Using the csv file nbaallelo.csv and the logit function, construct a logistic regression model to classify whether
Question:
Using the csv file nbaallelo.csv and the logit 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.
- 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 logit function to construct a logistic regression model with wins as the target and elo_i as the predictor.
- Print the coefficients of the model.
Ex: If the feature pts is used as the predictor, rather than elo_i, the output is:
# 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"
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
# construct a logistic model with wins and the target and elo_i as the predictor, using the training set
lm = # code to construct logistic model using the logit function
# print coefficients for the model
print(# code to return coefficients)
Essentials of Business Analytics
ISBN: 978-1285187273
1st edition
Authors: Jeffrey Camm, James Cochran, Michael Fry, Jeffrey Ohlmann, David Anderson, Dennis Sweeney, Thomas Williams