I do not understand the meaning of colors in nodes/leaves when building decision trees by sklearn.tree DecisionTreeClassifier.

Here's my code:

from sklearn import tree
from sklearn import datasets
from sklearn.tree import DecisionTreeClassifier
import matplotlib.pyplot as plt
iris = datasets.load_iris()           
X = iris.data[:, [2, 3]]
y = iris.target  
tree_model = DecisionTreeClassifier(criterion='gini',  
plt.rcParams["figure.figsize"] = (12,10)

enter image description here

Is there any logic in the choice of colors by scikit-learn? It doesn't seem so.


1 Answer 1


The colours represent the majority class (and therefore the predicted class) in each node. Thus, the plot_tree() function is using orange to represent the first class, green to represent the second class, and purple to represent the third class.

Also note that transparency is used to communicate the impurity of each node.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.