0
$\begingroup$

I try to display Decision Tree in Jupyter Notebook in Python.

This is my code:

X = data.drop(["Risk"], axis=1)
y = data["Risk"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
from sklearn.tree import DecisionTreeClassifier
klasyfikator = DecisionTreeClassifier(criterion = "gini", random_state=0, max_depth=4, min_samples_leaf=1)
klasyfikator.fit(X = X, y = y)

dot_data = StringIO()
export_graphviz(klasyfikator, out_file=dot_data,  
                filled=True, rounded=True,
                special_characters=True,feature_names = X.columns,class_names=['0','1'])
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())  
graph.write_png('diabetes.png')
Image(graph.create_png())

And by using above code I have Error:

InvocationException: GraphViz's executables not found

What can I do to display decision tree ? Where is a mistake ?

$\endgroup$

1 Answer 1

1
$\begingroup$

You need to add the graphviz/bin folder to PATH. See the tutorial here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.