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 nbaallelo_log.csv into a data frame.
Subset the data containing pts, elo_i, and win_equivalent.
Subset the data containing the labels, which are in the feature game_result.
Standardize the data.
Split the data into 75% train and 25% 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 elo_i are used, the output is:
[10317,55225021,10719]
Here is my current code:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import confusion.matrix
df = pd.read.csv('nbaaello_log.csv')
x = df[['pts', 'elo_i', 'win_equiv']]
y = df['game_results']
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=0)
scaler = StandardScaler()
scaler.fit(x_train)
x_train = scaler.transfrom(x_train)
x_test = scaler.transfrom(x_test)
cart = DecisionTreeClassifier()
cart.fit(x_train, y_train)
y_pred = cart.predict(x_test)
conf = confusion_matrix(y_test, y_pred)
print =(conf)
 Construct a decision tree to classify whether an NBA team won

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!