解决使用export_graphviz可视化树报错的问题
作者:lzher0 时间:2022-06-10 18:35:59
在使用可视化树的过程中,报错了。说是‘dot.exe'not found in path
原代码:
# import tools needed for visualization
from sklearn.tree import export_graphviz
import pydot
#Pull out one tree from the forest
tree = rf.estimators_[5]
# Export the image to a dot file
export_graphviz(tree, out_file = 'tree.dot', feature_names = features_list, rounded = True, precision = 1)
#Use dot file to create a graph
(graph, ) = pydot.graph_from_dot_file('tree.dot')
# Write graph to a png file
graph.write_png('tree.png');
报错信息:
解决方法:
先使用安装pydot:
pip install pydot
然后再下载Graphviz(http://www.graphviz.org 选择msi版本)一路安装,记住默认的安装路径
c:\Program Files (x86)\Graphviz2.38\。
将Graphviz2.38添加到环境变量中
import os
os.environ['PATH'] = os.environ['PATH'] + (';c:\\Program Files (x86)\\Graphviz2.38\\bin\\')
之后便可以正常使用了。
修改后代码:
# import tools needed for visualization
from sklearn.tree import export_graphviz
import pydot
import os
os.environ['PATH'] = os.environ['PATH'] + (';c:\\Program Files (x86)\\Graphviz2.38\\bin\\')
#Pull out one tree from the forest
tree = rf.estimators_[5]
# Export the image to a dot file
export_graphviz(tree, out_file = 'tree.dot', feature_names = features_list, rounded = True, precision = 1)
#Use dot file to create a graph
(graph, ) = pydot.graph_from_dot_file('tree.dot')
# Write graph to a png file
graph.write_png('tree.png');
来源:https://blog.csdn.net/weixin_42007359/article/details/80425670
标签:export,graphviz,可视化树
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中使用matplotlib模块errorbar函数绘制误差棒图实例代码
2022-11-09 17:01:42
![](https://img.aspxhome.com/file/2023/5/79435_0s.png)
opencv python Canny边缘提取实现过程解析
2023-08-20 19:43:18
![](https://img.aspxhome.com/file/2023/4/81834_0s.png)
oracle跨库查询的方法
2023-07-18 03:15:35
Access数据库用另一种方式管理密码
2008-10-13 12:25:00
利用ASP.NET MVC和Bootstrap快速搭建响应式个人博客站(一)
2023-07-06 23:47:39
![](https://img.aspxhome.com/file/2023/6/56056_0s.jpg)
JavaScript组件打包模式
2010-04-08 16:26:00
python中迭代器(iterator)用法实例分析
2023-12-16 05:32:51
python学生信息管理系统实现代码
2021-07-01 03:41:18
![](https://img.aspxhome.com/file/2023/7/81817_0s.jpg)
Python判断某个用户对某个文件的权限
2023-12-15 01:25:27
如何利用python的tkinter实现一个简单的计算器
2021-09-12 09:19:52
![](https://img.aspxhome.com/file/2023/6/82636_0s.png)
Sql server数据库优化
2010-04-06 19:17:00
Sublime Text4 配置 Python3 环境、代码提示、编译报错的解决方案
2021-09-24 12:00:03
![](https://img.aspxhome.com/file/2023/4/72074_0s.png)
不同分辨率下的自适用宽度
2008-11-24 12:58:00
![](https://img.aspxhome.com/file/UploadPic/200811/24/2008112413340367s.jpg)
asp如何阻止别人非法链接你网站的图片?
2010-07-11 21:01:00
Python3 加密(hashlib和hmac)模块的实现
2022-07-02 08:13:52
java正则表达式之Pattern与Matcher类详解
2023-06-21 10:14:03
![](https://img.aspxhome.com/file/2023/2/58592_0s.png)
php获取qq用户昵称和在线状态(实例分析)
2023-11-14 11:19:22
python开发之IDEL(Python GUI)的使用方法图文详解
2023-09-15 23:22:42
![](https://img.aspxhome.com/file/2023/8/62568_0s.png)
改变链接,让别人永远找不到你的程序
2008-09-13 18:57:00
Firefox与IE下UL预设标记的异同
2007-05-11 17:03:00