I'm currently trying to work with scikit-learn classification tree.

I followed the example on iris dataset : http://scikit-learn.org/stable/modules/tree.html and everything is working fine.

I do not understand the final graph though. My problem is that values like [50, 0, 0] are not clear to me. Which values corresponds to which class ? I mean, if I shuffle the lines of the dataset, class 0,1,2 will not be in the same order so my tree values will change.

So does anybody knows how I could change the code in order to have the proper initials labels before the values (and if possible how to plot the proportions for each leaf ?)


PS : If you feel that this question is too scikit-learn based. Please edit it so it is sent to stack overflow instead.


1 Answer 1


The ordering of the classes in the value parameter should be deterministic and independent of the samples ordering in the training set.

Either the unique string name or integer identifier for each class is stored in the classes_ attribute of the DecisionTreeClassifier instance after a call to the fit method.

  • $\begingroup$ Ok, thanks. Still, do you know how i could access the tree structure so I can modify values to have proportions instead ? An other problem I have is that for a tree with of max_depth=5, values are plot only for the leafs at the bottom of the tree. $\endgroup$
    – Scratch
    Jan 8, 2014 at 9:47
  • $\begingroup$ Then just have a look at the source code of the export_graphviz function and customize it to have it work the way you want. $\endgroup$
    – ogrisel
    Jan 8, 2014 at 12:39

Your Answer

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

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