i am having a problem producing a visual image of a decision tree. i am using python 2.7 and i have installed graphviz and pydot but when i run my code this is the error am getting "Could not run dot, ie graphviz, to produce visualization" what could be the problem?
NB am using windows not linux
Below is my code
from __future__ import print_function
import pandas as pd
import os
import subprocess
from sklearn.tree import DecisionTreeClassifier, export_graphviz
os.chdir('C:\\Users\\lussi\\Desktop\\tests')
df= pd.read_csv('yield2.csv')
print("* df.head()", df.head(), sep="\n", end="\n\n")
features = list(df.columns[:6])
y = df["yield"]
X = df[features]
dt = DecisionTreeClassifier(min_samples_split=20, random_state=99)
dt.fit(X, y)
def visualize_tree(tree, f_names):
with open("dt.dot", 'w') as f:
export_graphviz(tree, out_file=f,
feature_names=f_names)
command = ["dot", "-Tpng", "dt.dot", "-o", "dt.png"]
try:
subprocess.check_call(command)
except:
exit("Could not run dot, ie graphviz, to "
"produce visualization")
visualize_tree(dt, features)