尝试用python绘制决策树

尝试用python绘制决策树,python,scikit-learn,Python,Scikit Learn,请原谅我的天真。我试图使用Jupyter笔记本在Python中生成一个决策树图。我不断地遇到麻烦,一个问题我一解决,另一个问题就出现了。有人能推荐一个链接到一个代码示例来绘制一个实际工作的决策树吗?我已经下载了Python 3.8(32位)、Python 3.9(64位)、Anaconda3。问题的一个例子是我运行了以下代码: # https://chrisalbon.com/machine_learning/trees_and_forests/visualize_a_decision_tree

请原谅我的天真。我试图使用Jupyter笔记本在Python中生成一个决策树图。我不断地遇到麻烦,一个问题我一解决,另一个问题就出现了。有人能推荐一个链接到一个代码示例来绘制一个实际工作的决策树吗?我已经下载了Python 3.8(32位)、Python 3.9(64位)、Anaconda3。问题的一个例子是我运行了以下代码:

# https://chrisalbon.com/machine_learning/trees_and_forests/visualize_a_decision_tree/
# Load libraries
from sklearn.tree import DecisionTreeClassifier
from sklearn import datasets
from IPython.display import Image  
from sklearn import tree
# import pydotplus # 
# I pasted this into Anaconda prompt conda install pydotplus
# the error persisted after I said pip install pydotplus
import pydotplus
# Load data
iris = datasets.load_iris()
X = iris.data
y = iris.target
# Train Decision Tree
# Create decision tree classifer object
clf = DecisionTreeClassifier(random_state=0)

# Train model
model = clf.fit(X, y)
# continuing https://chrisalbon.com/machine_learning/trees_and_forests/visualize_a_decision_tree/
# Visualize Decision Tree
# Create DOT data
dot_data = tree.export_graphviz(clf, out_file=None, 
                            feature_names=iris.feature_names,  
                            class_names=iris.target_names)

# Draw graph
graph = pydotplus.graph_from_dot_data(dot_data)  

# Show graph
Image(graph.create_png())
在这一点上,我陷入了绝望: 调用异常回溯(最近一次调用上次) 在里面 10 11#显示图表 --->12图像(graph.create_png())

~\anaconda3\lib\site packages\pydotplus\graphviz.py in(f,prog)
1795年自__(
1796“创建”+frmt,
->1797 lambda f=frmt,prog=self.prog:self.create(format=f,prog=prog)
1798             )
1799 f=自我.uuuu指令uuuuu['create_uuu'+frmt]
创建中的~\anaconda3\lib\site packages\pydotplus\graphviz.py(self、prog、format)
1957 self.progs=find_graphviz()
1958如果self.progs为无:
->1959年的例外情况(
1960“未找到GraphViz的可执行文件”)
1961
调用异常:找不到GraphViz的可执行文件

我发现一些网站说了一些关于changine the PATH的内容,但我不理解。我不是一名计算机科学家,我受过医学训练,但得了脑瘤,所以我学习了R并进行了临床试验研究。非常感谢您的帮助

在我的案例中,它在本地机器和Google Colab中提供了一个输出。我的建议是制作一个单元格并编写
!pip在jupyter笔记本中安装pydotplus
。Google Colab的链接


谢谢Vibhav Surve,我试着添加了!pip将pydotplus安装到jupyter的一个新单元中,唉,它对我没有任何影响,我仍然有相同的错误消息,前几行是:InvocationException Traceback(最近一次调用)in 10 11#Show graph-->12 Image(graph.create_png())
~\anaconda3\lib\site-packages\pydotplus\graphviz.py in <lambda>(f, prog)
   1795             self.__setattr__(
   1796                 'create_' + frmt,
-> 1797                 lambda f=frmt, prog=self.prog: self.create(format=f, prog=prog)
   1798             )
   1799             f = self.__dict__['create_' + frmt]

~\anaconda3\lib\site-packages\pydotplus\graphviz.py in create(self, prog, format)
   1957             self.progs = find_graphviz()
   1958             if self.progs is None:
-> 1959                 raise InvocationException(
   1960                     'GraphViz\'s executables not found')
   1961 

InvocationException: GraphViz's executables not found