Answered step by step
Verified Expert Solution
Question
1 Approved Answer
7 . 6 LAB: Performing logistic regression using LogisticRegression ( ) The nbaallelo _ log file contains data on 1 2 6 3 1 4
LAB: Performing logistic regression using LogisticRegression
The nbaallelolog file contains data on NBA games from to The dataset includes the features pts eloi
winequiv, and gameresult. Using the csv file nbaallelologcsv and scikitlearn's LogisticRegression function,
construct a logistic regression model to classify whether a team will win or lose a game based on the team's eloi score.
Hot encode the gameresult variable as a numeric variable with for and for
Use the LogisticRegression function to construct a logistic regression model with gameresult as the target and eloi as
the predictor.
Predict the probability of a win from an eloi score of
Predict whether a team with an eloi score of will win.
Note: Use ravel from numpy to flatten the second argument of LogisticRegression. fit into a D array.
Ex: If a eloi score of is used instead of the output is:
A team with the given eloi score has predicted probability:
losing
winning
and the overall prediction is
# Import the necessary Libraries
import pandas as pd
from sklearn.linearmodel import LogisticRegression
import numpy as
# Load nbaallelologcsv into a dataframe
NBA pdreadcsvnbaallelologcsv
# Hot encode the gameresult variable as a numeric variable with for and for
# Your code here
# Store relevant columns as variables
NBAeloivalues.reshape
'gameresult'values.reshape astypeint
# Initialize and fit the logistic model using the LogisticRegression function
# Your code here
# Predict the probability that an eloi score of is a win loss
outcomeProb # Your code here
# Predict whether an eloi score of is a win or loss
outcomePred # Your code here
printA team with the given eloi score has predicted probability:
end
printf outcomeProb winning"
printand the overall prediction is
outcomePred
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started