[scikit-learn] tree visualization with class names in leaves

greg g greg315 at hotmail.fr
Mon Oct 24 10:18:11 EDT 2016

 I just begin with scikit-learn and would like to visualize a classification tree with class names displayed in the leaves as shown in the SCIKITLEARN.TREE documentation http://scikit-learn.org/stable/modules/tree.html where we find class=’virginica’ etc…
I made a tree providing a 2D array X (n1 samples , n2 features) and 1D array Y (n1 corresponding classes ) such that Y(i) is the class of the sample X(i, …)
After that I have correct predictions using predict()
Then I use the function 
export_graphviz(clf, out_file=dot_data,feature_names=FEATURES)
with FEATURES being the array of my n2 features names in the same order as in X 
I obtain the tree .png but can’t find a way to have the correct class names in the leaves…
In export_graphviz() should I use the class_names optional parameter and how ?
Thanks for any help
Gregory, Toulouse FRANCE

More information about the scikit-learn mailing list