Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the csv file nbaallelo.csv and the Logistic Regression function, construct a logistic regression model to classify whether a team will win or lose

   

Using the csv file nbaallelo.csv and the Logistic Regression 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.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 Logistic Regression 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. Ex: If the feature pts is used as the predictor, rather than elo_i, the output is: Ex: If the feature pts is used as the predictor, rather than elo_i, the output is: confusion matrix is [[12220 6730] [ 6530 12415]] Sensitivity is 0.6448548812664907 Specificity is 0.6553180258643442 main.py (default template) # import the necessary libraries # load nbaallelo.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" ["game_result"]) bool_val = wins = wins_new = df_final == np.multiply(wins, 1) pd.DataFrame(bool_val, columns = pd.concat([df, wins_new], axis=1) wins.rename(columns = {"game_result": "wins"}) # split the data df_final into training and test sets with a test size of 0.3 and random_state train, test = #23 code to split df_final into training and test sets = 0 # build the logistic model using the Logistic Regression 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("Sensitivity is ", sens) # calculate the specificity spec = # code to calculate the specificity print ("Specificity is ", spec)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis And Decision Making

Authors: Christian Albright, Wayne Winston, Christopher Zappe

4th Edition

538476125, 978-0538476126

More Books

Students also viewed these Operating System questions