Graphviz 无法打印随机森林回归树
我看了几个例子,并遵循它们,但无法打印树形图Graphviz 无法打印随机森林回归树,graphviz,random-forest,pydot,Graphviz,Random Forest,Pydot,我看了几个例子,并遵循它们,但无法打印树形图 R_forest = RandomForestRegressor(bootstrap=False, max_depth=30, max_features ='sqrt', min_samples_leaf= 4, min_samples_split=2, n_estimators = 600) model=R_forest.fit(X_train,y_train) from sklearn.datasets import * f
R_forest = RandomForestRegressor(bootstrap=False,
max_depth=30,
max_features ='sqrt',
min_samples_leaf= 4,
min_samples_split=2,
n_estimators = 600)
model=R_forest.fit(X_train,y_train)
from sklearn.datasets import *
from sklearn import tree
from sklearn.tree import export_graphviz
import graphviz
import pydot
tree = R_forest.estimators_[5]
# Export the image to a dot file
export_graphviz(tree, out_file = 'tree.dot', feature_names = X_train.columns,
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')
我得到这个错误:
FileNotFoundError:[WinError 2]“dot.exe”未在路径中找到
我遵循了这个解决方案,但仍然得到相同的错误
我的系统截图
如果您能够生成“tree.dot”文件,那么您可以从命令行(在带有“tree.dot”的目录中)运行以下命令,以转换为png格式:
dot-Tpng tree.dot-o tree.png
如果这不起作用,您也可以尝试使用dot.exe的完整路径:
path\to\dot.exe-Tpng tree.dot-o tree.png
使用
graph.write\u png('tree.png')
在我的Windows计算机上不起作用,但命令行操作起作用
来自的解决方案 哪一行代码给出了错误?你能生成'tree.dot'文件吗?是的,我能生成'tree.dot'文件。谢谢你的回答,我会确认你的回答是正确的。