Question: Construct a decision tree to classify whether an NBA team won or lost a game based on the team's points in the game, elo score
Construct a decision tree to classify whether an NBA team won or lost a game based on the team's points in the game, elo score entering
the game, and win equivalence.
Read nbaallelologcsv into a data frame.
Subset the data containing pts eloi and winequivalent.
Subset the data containing the labels, which are in the feature gameresult.
Standardize the data.
Split the data into train and test sets.
Use DecisionTreeClassifier to initialize a classification tree using the train data.
Use the classification tree to predict the results for the test data.
Construct and print the confusion matrix. Ex: If only pts and eloi are used, the output is:
Here is my current code:
import pandas as pd
from sklearn.modelselection import traintestsplit
from sklearn.preprocessing import StandardScaler
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import confusion.matrix
df pdread.csvnbaaellologcsv
x dfpts 'eloi 'winequiv'
y dfgameresults'
xtrain, xtest, ytrain, ytest traintestsplitx y testsize randomstate
scaler StandardScaler
scaler.fitxtrain
xtrain scaler.transfromxtrain
xtest scaler.transfromxtest
cart DecisionTreeClassifier
cart.fitxtrain, ytrain
ypred cart.predictxtest
conf confusionmatrixytest, ypred
print conf
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
