Decision Tree and Python Coding
Decision Tree and Python Coding
Instructions
Read the article here and make the codes run in Jupyter. Review on how to make methods in Python.
Put your name as part of the screenshots for the codes.
y_not_zero = y>0 #get the index for each non zero value in y.
clf_df=DecisionTreeClassifier(random_state=42)
clf_df=clf_df.fit(X_train,y_train)
plt.figure(figsize=(15,7.5))
plot_tree(clf_df,filled=True,rounded=True,class_name=["","",],feature_names=X_encoded.columns);
## now create one decision tree per value for for alpha and store it in the array
for ccp_alpha in ccp_alphas:
~~graph the accuracy of the trees using the Training Dataset and the Testing Dataset as a function of
the alpha.
fig,ax = plt.subplots()
ax.set_xlabel("alphas")
ax.set_ylabel("accuracy")
ax.legend()
plt.show()