<jupyter_start><jupyter_text>Libraries<jupyter_code>from matplotlib import pyplot as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
import pandas as pd<jupyter_output><empty_output><jupyter_text>Load Data<jupyter_code>df = pd.read_csv("../data/all_Seasons_MVP.csv")
df.head(3)
# Tomar cuidado com quem mudou de time
# Target
df.loc[df['MVP'].isnull(),'Target'] = 0
df.loc[~df['MVP'].isnull(),'Target'] = 1
SeasonComplete = df.loc[df['Target']==1]['Season']
df = df.loc[df['Season'].isin(SeasonComplete)]<jupyter_output><empty_output><jupyter_text>Features<jupyter_code>target = 'Target'
feat1 = ['Age', 'FG%', '3P%', '2P%', 'eFG%', 'FT%']
feat2 = ['GS_PG','MP_PG','FG_PG','FGA_PG','3P_PG','3PA_PG','2P_PG','2PA_PG','FT_PG','FTA_PG','ORB_PG','DRB_PG','TRB_PG','PTS_PG','PF_PG','TOV_PG','BLK_PG','STL_PG','AST_PG']
features = feat1+feat2
originVar = ['GS','MP','FG','FGA','3P','3PA','2P','2PA','FT','FTA','ORB','DRB','TRB','PTS','PF','TOV','BLK','STL','AST']
for var in range(len(originVar)):
    df.loc[:,feat2[var]] = df.loc[:,originVar[var]]/df.loc[:,'G']
# Tratar as Positions/Team como variável
# 'Pos'
# 'Tm'<jupyter_output><empty_output><jupyter_text>Basic Filters<jupyter_code>df = df.loc[df['PTS_PG']>22]<jupyter_output><empty_output><jupyter_text>Data Imputation<jupyter_code>df = df.fillna(df.mean())<jupyter_output><empty_output><jupyter_text>Sample/Prepare<jupyter_code># Prepare the data data
X = df[features]
y = df[target]<jupyter_output><empty_output><jupyter_text>Fit Classifier<jupyter_code># Fit the classifier with default hyper-parameters
clf = DecisionTreeClassifier(random_state=2021,max_depth=3,min_samples_leaf=2)
model = clf.fit(X, y)
text_representation = tree.export_text(clf)
print(text_representation)
fig = plt.figure(figsize=(25,20))
_ = tree.plot_tree(clf, 
                   feature_names=features,  
                   filled=True)
import graphviz
# DOT data
dot_data = tree.export_graphviz(clf, out_file=None, 
                                feature_names=features,  
                                filled=True)

# Draw graph
graph = graphviz.Source(dot_data, format="png") 
graph<jupyter_output><empty_output><jupyter_text>Predict<jupyter_code>y_model = model.predict(X)
y_model_proba = model.predict_proba(X)
#Acurácia
from sklearn.metrics import accuracy_score
accuracy_score(y, y_model)
import scikitplot as skplt
import matplotlib.pyplot as plt

y_true = y# ground truth labels
y_probas = y_model_proba# predicted probabilities generated by sklearn classifier
skplt.metrics.plot_confusion_matrix(y, y_model, normalize=True)
skplt.metrics.plot_roc_curve(y,y_model_proba)
plt.show()
skplt.metrics.plot_precision_recall_curve(y, y_model_proba)
plt.show()<jupyter_output>C:\Users\thiag\Anaconda3\lib\site-packages\sklearn\utils\deprecation.py:86: FutureWarning: Function plot_precision_recall_curve is deprecated; This will be removed in v0.5.0. Please use scikitplot.metrics.plot_precision_recall instead.
  warnings.warn(msg, category=FutureWarning)
{'fraction_non_alphanumeric': 0.15463576158940398, 'fraction_numerical': 0.012251655629139073, 'mean_word_length': 6.992063492063492, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '444589', 'license': 'MIT', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1148, 'n_words': 167, 'path': 'Notebooks/Model.ipynb', 'repo_name': 'FabioCaffarello/NBA', 'size': '3020'}