Question: Please answer in Python Code taking into consideration the below output example and default template. Thank you Default Template # import the necessary libraries #
Please answer in Python Code taking into consideration the below output example and default template. Thank you
Default Template
# 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}')
10.6 LAB: Evaluating logistic regression using LogisticRegression() 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 ravel0 from numpy to flatten the second argument of LogisticRegression.fit) into a 1-D array. Ex: If the feature pts is used as the predictor, rather than elo_i, the output is: confusion matrix is [[12220 6730] [ 653012415]] Sensitivity is 0.644855 Specificity is 0.655318
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
