Question: Using the csv file nbaallelo _ log . csv and the LogisticRegression function, construct a logistic regression model to classify whether a team will win
Using the csv file nbaallelologcsv and the 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 and evaluate the model.
Read in the file nbaaellologcsv
The target feature will be converted from string to a binary feature by the provided code.
Split the data into percent training set and percent testing set. Set randomstate
Use the LogisticRegression function to construct a logistic regression model with wins as the target and eloi as the predictor.
Use the test set to predict the wins from the eloi score.
Construct and print the confusion matrix.
Calculate and print the sensitivity
Calculate and print the specificity.
Note: Use ravel from numpy to flatten the second argument of LogisticRegression.fit into a D array. # import the necessary libraries
# load nbaallelologcsv into a dataframe
df # code to load csv file
# Converts the feature "gameresult" to a binary feature and adds as new column "wins"
wins dfgameresult W
boolval npmultiplywins
wins pdDataFrameboolval, columns gameresult"
winsnew wins.renamecolumns gameresult": "wins"
dffinal pdconcatdf winsnew axis
# split the data dffinal into training and test sets with a test size of and randomstate
train, test # code to split dffinal into training and test sets
# build the logistic model using the LogisticRegression function with wins as the target variable and eloi as the predictor.
# use the test set to predict the wins from the eloi score
predictions # code to predict wins
# generate confusion matrix
conf # code to generate confusion matrix
printconfusion matrix is
conf
# calculate the sensitivity
sens # code to calculate the sensitivity
printfSensitivity is sens:f
# calculate the specificity
spec # code to calculate the specificity
print fSpecificity is spec:f
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
