Home / Python / Predictive Modeling & Machine Learning / 204.3.8 Practice : Validating the Tree

204.3.8 Practice : Validating the Tree

In last post we built a decision tree and after plotting we explored the major characteristics of the tree.

In this post we will practice how to validate the tree.

Tree Validation

  • Find the accuracy of the classification for the tree model
#Tree Validation
predict1 = clf.predict(X)
from sklearn.metrics import confusion_matrix ###for using confusion matrix###
cm = confusion_matrix(y, predict1)
print (cm)
[[6370   38]
 [ 648 4749]]
total = sum(sum(cm))
#####from confusion matrix calculate accuracy
accuracy = (cm[0,0]+cm[1,1])/total
  • We can also use the .score() function to predict the accuracy in python from sklearn library.
  • However, confusion matrix allows us to see the wrong classifications too that gives an intutive understanding.

About admin

Check Also

204.7.6 Practice : Random Forest

Let’s implement the concept of Random Forest into practice using Python. Practice : Random Forest …

Leave a Reply

Your email address will not be published. Required fields are marked *