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 nbaallelo_log.csv 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 elo_i score and evaluate the model.
Read in the file nbaaello_log.csv.
The target feature will be converted from string to a binary feature by the provided code.
Split the data into 70 percent training set and 30 percent testing set. Set random_state =0.
Use the LogisticRegression function to construct a logistic regression model with wins as the target and elo_i as the predictor.
Use the test set to predict the wins from the elo_i 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 1-D array. # import the necessary libraries
# load nbaallelo_log.csv into a dataframe
df = # code to load csv file
# Converts the feature "game_result" to a binary feature and adds as new column "wins"
wins = df.game_result =="W"
bool_val = np.multiply(wins,1)
wins = pd.DataFrame(bool_val, columns =["game_result"])
wins_new = wins.rename(columns ={"game_result": "wins"})
df_final = pd.concat([df, wins_new], axis=1)
# split the data df_final into training and test sets with a test size of 0.3 and random_state =0
train, test = # code to split df_final into training and test sets
# build the logistic model using the LogisticRegression function with wins as the target variable and elo_i as the predictor.
# use the test set to predict the wins from the elo_i score
predictions = # code to predict wins
# generate confusion matrix
conf = # code to generate confusion matrix
print("confusion matrix is
", conf)
# calculate the sensitivity
sens = # code to calculate the sensitivity
print(f'Sensitivity is {sens:.6f}')
# calculate the specificity
spec = # code to calculate the specificity
print (f'Specificity is {spec:.6f}')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!