title: How to display categorical values on export tree image of decision tree classifier?
body: <p>I am trying to export the decision tree as an image with the original labels of all categorical fields.</p>
  
  <p>The current data I have is like so:</p>
  
  <p><a href="https://i.stack.imgur.com/jhKIk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jhKIk.png" alt="enter image description here"></a></p>
  
  <p>I transformed the categorical features into numerical:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import pandas as pd
  
  # Importing the dataset
  dataset = pd.read_csv('data.csv')
  X = dataset.iloc[:, 0:4]
  y = dataset.iloc[:, 4]
  
  from sklearn.preprocessing import LabelEncoder
  lb = LabelEncoder()
  
  X['Outlook'] = lb.fit_transform(X['Outlook'])
  X['Temp'] = lb.fit_transform(X['Temp'])
  X['Humidity'] = lb.fit_transform(X['Humidity'])
  X['Windy'] = lb.fit_transform(X['Windy'])
  y = lb.fit_transform(y)
  </code></pre>
  
  <p>Afterwards, I applied the <code>DecisionTreeClassifier</code>:</p>
  
  <pre><code>from sklearn.tree import DecisionTreeClassifier
  dtc = DecisionTreeClassifier(criterion="entropy")
  dtc.fit(X, y)
  </code></pre>
  
  <p>At the end, I needed to check the tree generated from the model using the following:</p>
  
  <pre><code># Import tools needed for visualization
  from sklearn.tree import export_graphviz
  import pydot
  # Pull out one tree from the forest
  # Export the image to a dot file
  export_graphviz(dtc, out_file = 'tree.dot', feature_names = X.columns, rounded = True, precision = 1)
  # Use dot file to create a graph
  (graph, ) = pydot.graph_from_dot_file('tree.dot')
  # Write graph to a png file
  graph.write_png('tree.png')
  </code></pre>
  
  <p>The <code>tree.png</code>:</p>
  
  <p><a href="https://i.stack.imgur.com/DYwBU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DYwBU.png" alt="enter image description here"></a></p>
  
  <p>But what I really need, is to see the main labels of each feature inside the nodes or at each branch, instead of <code>true</code> or <code>false</code> or a numeric representation.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>y=lb.inverse_transform(y)
  </code></pre>
  
  <p>And the same for X features, but the tree is being generated the same as above.</p>