Advertisement
naren_paste

Plot_DT_Tree

Nov 23rd, 2023
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | Source Code | 0 0
  1. from sklearn.datasets import load_iris
  2. from sklearn.tree import DecisionTreeClassifier, plot_tree
  3. import matplotlib.pyplot as plt
  4.  
  5. # Load the Iris dataset as an example
  6. iris = load_iris()
  7. X, y = iris.data, iris.target
  8.  
  9. # Create a decision tree classifier
  10. clf = DecisionTreeClassifier(random_state=42)
  11. clf.fit(X, y)
  12.  
  13. # Plot the decision tree
  14. plt.figure(figsize=(12, 8))
  15. plot_tree(clf, feature_names=iris.feature_names, class_names=iris.target_names, filled=True, rounded=True)
  16. plt.show()
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement