Question: The nbaallelo _ log . csv file contains data on 1 2 6 3 1 4 NBA games from 1 9 4 7 to 2
The nbaallelologcsv file contains data on NBA games from to The dataset includes the features pts eloi winequiv, and gameresult. Using a sample of the csv file nbaallelologcsv and scikitlearn's 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. Using scikitlearn's metrics module, calculate the various classification metrics for the model.
Build a logistic model with default parameters, fit to the input and output features X and y
Use the model to predict the classification of instances in X
Calculate the confusion matrix for the model.
Calculate the accuracy for the model.
Calculate the precision for the model.
Calculate the recall for the model.
Calculate kappa for the model.
import numpy as np
import pandas as pd
from sklearn import metrics
from sklearn.preprocessing import StandardScaler
from sklearn.linearmodel import LogisticRegression
# Input the random state
rand intinput
# Load sample set by a userdefined random state into a dataframe.
NBA pdreadcsvnbaallelologcsvsamplen randomstaterand
# Create binary feature for gameresult with for L and for W
NBAwin NBAgameresult'replacetoreplace LW value int int
# Store relevant columns as variables
X NBAeloi
y NBAwin
# Build logistic model with default parameters, fit to X and y
# Your code here
# Use the model to predict the classification of instances in X
logPredY # Your code here
# Calculate the confusion matrix for the model
confMatrix # Your code here
printConfusion matrix:
confMatrix
# Calculate the accuracy for the model
accuracy # Your code here
printAccuracy: roundaccuracy
# Calculate the precision for the model
precision # Your code here
printPrecision: roundprecision
# Calculate the recall for the model
recall # Your code here
printRecall: roundrecall
# Calculate kappa for the model
kappa # Your code here
printKappa: roundkappa
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
