Skip to content
Advertisement

How to change colors for decision tree plot using sklearn plot_tree?

How to change colors in decision tree plot using sklearn.tree.plot_tree without using graphviz as in this question: Changing colors for decision tree plot created using export graphviz?

JavaScript

enter image description here

Advertisement

Answer

Many matplotlib functions follow the color cycler to assign default colors, but that doesn’t seem to apply here.

The following approach loops through the generated annotation texts (artists) and the clf tree structure to assign colors depending on the majority class and the impurity (gini). Note that we can’t use alpha, as a transparent background would show parts of arrows that are usually hidden.

JavaScript

changing the colors of sklearn plot_tree

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement