Actually I'm using sklearn for visualizing decision tree. I have already installed graphviz and pydotplus and also set the environment variable of graphviz but when i run this code, it gives an error.
I'm using "kyphosis" dataset.
Here is the actual code
from IPython.display import Image
from sklearn.externals.six import StringIO
from sklearn.tree import export_graphviz
import pydotplus
features = list(df.columns[1:])
features
Output:
['Age', 'Number', 'Start']
it works fine
but when i run this below code. Code:
dot_data = StringIO()
export_graphviz(dtree,
out_file=dot_data,feature_names=features,filled=True,rounded=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph[0].create_png())
It shows an error.
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
<ipython-input-44-28715c87781f> in <module>
3
4 graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
----> 5 Image(graph[0].create_png())
TypeError: 'Dot' object is not subscriptable