plot_tree renders a fitted scikit-learn decision tree as a visual diagram. Feature names and class names label the nodes, while node colors indicate the majority or predicted class. section 6.3.5
Useful display options include:
- filled=True colors nodes according to their majority class or predicted class and split purity. section 6.3.5
- rounded=True rounds node edges, improving visual presentation. section 6.3.5
- fontsize controls label readability; feature_names and class_names identify variables and outcomes. section 6.3.5
Plot a pruned classifier
Pass a fitted classifier to tree.plot_tree with feature_names such as QUARTER, TO_GO, OFFENSIVE_TEAM_VENUE, SCORE_DIFFERENTIAL, and PLAY_TYPE, then display the Matplotlib figure. A pruned tree contains fewer splits and features, making its decision paths easier to inspect. Thresholds can be non-integer, such as TO_GO <= 3.5, even when the feature is integer-valued; this does not affect predictive accuracy. section 6.3.5
>>> from sklearn import tree >>> plt.figure() >>> tree.plot_tree(clf, feature_names = ['QUARTER', >>> 'TO_GO', >>> 'OFFENSIVE_TEAM_VENUE', >>> 'SCORE_DIFFERENTIAL', >>> 'PLAY_TYPE'], >>> class_names = ['0', '1'], >>> filled = True, >>> rounded = True >>> fontsize = 12) >>> plt.tight_layout() >>> plt.show()
Use the runnable listing to see the scikit-learn import, label configuration, visual styling, and Matplotlib display call. section 6.3.5
