Get feature and class names into decision tree using export graphviz
The class names are stored in decision_tree_classifier.classes_
, i.e. the classes_
attribute of your DecisionTreeClassifier
instance. And the feature names should be the columns of your input dataframe. For your case you will have
class_names = decision_tree_classifier.classes_
feature_names = df.columns[14:]
Personally for me class_names = True worked. It would show the symbolic representation of the outcome.
feature_names = df.columns[14:]
tree.export_graphviz(decision_tree_classifier, out_file="mytree.dot",
feature_names=feature_names ,
class_names=TRUE)
Here is some more details on the topic: https://scikit-learn.org/stable/modules/generated/sklearn.tree.export_graphviz.html