1
$\begingroup$

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',  
                                max_depth=4, 
                                random_state=1)
tree_model.fit(X,y)
plt.rcParams["figure.figsize"] = (12,10)
tree.plot_tree(tree_model,filled=True)
plt.show()

enter image description here

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

$\endgroup$
1

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

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.