简体   繁体   English

在 Python 中的 Jupyter Notebook 中显示决策树的巨大问题:ExecutableNotFound?

[英]Huge problem to display decision tree in Jupyter Notebook in Python: ExecutableNotFound?

I have a problem to create and display decision tree in Jupyter Notebook using Python.我在使用 Python 在 Jupyter Notebook 中创建和显示决策树时遇到问题。 My code is as below:我的代码如下:

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)


data = export_graphviz(klasyfikator,out_file=None,feature_names=X.columns,class_names=["0", "1"],   
                         filled=True, rounded=True,  
                         special_characters=True)
graph = graphviz.Source(data)
graph

Generally this decision tree concerns credit risk research 0 - will not pay 1 - will pay.通常,此决策树涉及信用风险研究 0 - 不会支付 1 - 会支付。

When I use code above, I have error like this:当我使用上面的代码时,我有这样的错误:

ExecutableNotFound: failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH ExecutableNotFound:无法执行 ['dot', '-Tsvg'],请确保 Graphviz 可执行文件在您系统的 PATH 中

I have already tried many solutions from StackOverflow, for example:我已经尝试过 StackOverflow 的许多解决方案,例如:

  1. pip install graphviz pip安装graphviz
  2. Conta install graphiz连接安装graphiz
  3. I Downloaded Graphviz from http://www.graphviz.org/download/我从http://www.graphviz.org/download/下载了 Graphviz
  4. I added to the PATH environment variable:我添加到 PATH 环境变量中:

C:\\Program Files (x86)\\Graphviz2.38\\bin C:\\Program Files (x86)\\Graphviz2.38\\bin

And there is still error described above.并且仍然存在上述错误。 What can I do?我能做什么? what should I do ?我该怎么办 ? Please help me guys because I'm losing hope of being able to draw this tree.请帮助我,因为我失去了能够画这棵树的希望。 Thank you!谢谢!

Moreover, when I added by using this code:此外,当我使用此代码添加时:

import os 
os.environ["PATH"] += os.pathsep + 'C:\Program Files (x86)\Graphviz2.38\bin' 

I have in PATH something like this: C:\\\\Program Files (x86)\\\\Graphviz2.38\\x08in it is not the same, what can I do ?我在 PATH 中有这样的东西: C:\\\\Program Files (x86)\\\\Graphviz2.38\\x08in它不一样,我该怎么办?

With latest version of sklearn, you can directly plot the decision tree without graphviz .使用最新版本的 sklearn,您可以直接绘制决策树而无需graphviz

Use:用:

from sklearn.tree import plot_tree

plot_tree(klasyfikator) 

Read more here . 在这里阅读更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM