graphviz - Pydotplus,Graphviz 错误:程序以状态终止:1. 标准错误如下:'C:\Users\En' 未被识别为内部或外部命令
问题描述
from pydotplus import graph_from_dot_data
from sklearn.tree import export_graphviz
from IPython.display import Image
dot_data = export_graphviz(tree,filled=True,rounded=True,class_names=['Setosa','Versicolor','Virginica'],feature_names=['petal length','petal width'],out_file=None)
graph = graph_from_dot_data(dot_data)
Image(graph.create_png())
程序以状态终止:
1. stderr follows: 'C:\Users\En' is not recognized as an internal or external command,
operable program or batch file.
似乎它将我的用户名分成两半。我该如何克服这个问题?
解决方案
我有一个非常相似的示例,我正在尝试,它基于 ML 操作手册,该手册与预测违约风险的台湾信用卡数据集一起使用。我的设置如下:
from six import StringIO
from sklearn.tree import export_graphviz
from IPython.display import Image
import pydotplus
然后以这种方式创建决策树图:
dot_data = StringIO()
export_graphviz(decision_tree=class_tree,
out_file=dot_data,
filled=True,
rounded=True,
feature_names = X_train.columns,
class_names = ['pay','default'],
special_characters=True)
graph = pydotplus.graph_from_dot_data(dot_data.getvalue())
Image(graph.create_png())
我认为这一切都来自out_file=dot_data
参数,但无法确定文件路径的创建和存储位置,因为print(dot_data.getvalue())
没有显示任何路径名。
在我的研究中,我遇到了 sklearn.plot_tree() ,它似乎可以完成 graphviz 所做的所有事情。所以我采用了上面的 exporet_graphviz 参数,并且匹配的参数在我添加的 .plot_tree 方法中。
我最终得到了以下内容,它创建了与文本中相同的图像:
from sklearn import tree
plt.figure(figsize=(20, 10))
tree.plot_tree(class_tree,
filled=True, rounded=True,
feature_names = X_train.columns,
class_names = ['pay','default'],
fontsize=12)
plt.show()
推荐阅读
- curl - 运行make文件时ld找不到库curl
- python - 如何更改整个列的时区?
- javascript - javascript 正则表达式匹配,包括非捕获组
- signal-processing - 如何使用 GNURadio 控制 OFDM 中的带宽
- gitbook - gitbook 编辑器缺少文件内容仅显示文件
- javascript - 如何使用自定义按钮发送到 JQGrid 的 editurl?
- javascript - 如何将 CanJS 与 VelocityJS 一起使用?
- css - CSS 过渡不起作用
- php - 刷新页面时 https 更改为 http
- regex - HTML5输入模式(防止先到0)