CSq*_*are 5 python dot decision-tree pydot scikit-learn
这是我在stackoverflow上发布的第一个问题所以我为布局中的任何不幸事件道歉等等(建议欢迎).非常感谢您的帮助!
我正在尝试使用多个输出可视化DecisionTreeRegressor的输出(如http://scikit-learn.org/stable/auto_examples/tree/plot_tree_regression_multioutput.html#example-tree-plot-tree-regression-multioutput-py中所述)使用pydot以png或pdf格式.
我试过的代码看起来像这样:
...
dtreg = tree.DecisionTreeRegressor(max_depth=3)
dtreg.fit(x,y)
tree.export_graphviz(dtreg, out_file='tree.dot') #print dotfile
dot_data = StringIO()
tree.export_graphviz(dtreg, out_file=dot_data)
print dot_data.getvalue()
pydot.graph_from_dot_data(dot_data.getvalue()).write_pdf("pydot_try.pdf")
Run Code Online (Sandbox Code Playgroud)
编写pdf会出现以下错误:
pydot.InvocationException:程序以状态终止:1.stderr跟随:警告:/ tmp/tmpAy7d59:7:字符串超过行尾错误:/ tmp/tmpAy7d59:8:第8行附近的语法错误:>>> [< << 0.20938667]警告:/ tmp/tmpAy7d59:18:字符串跑过行尾警告:/ tmp/tmpAy7d59:20:字符串跑过行尾
等等更多"字符串跑过终点"错误.
我之前从未使用过.dot,但我怀疑多输出格式可能存在问题.例如,树的一部分看起来像这样:
digraph Tree {
0 [label="X[0] <= 56.0000\nmse = 0.0149315126135\nsamples = 41", shape="box"] ;
1 [label="X[0] <= 40.0000\nmse = 0.0137536911947\nsamples = 25", shape="box"] ;
0 -> 1 ;
2 [label="X[0] <= 24.0000\nmse = 0.0152142545276\nsamples = 21", shape="box"] ;
1 -> 2 ;
3 [label="mse = 0.0140\nsamples = 15\nvalue = [[ 0.83384667]
[ 0.20938667]
[ 0.08511333]
[ 0.04234667]
[ 0.08158 ]
[ 0.17948667]
[ 0.03616 ]
[ 0.00995333]
[ 0.99529333]
[ 0.13715333]
[ 0.10294667]
[ 0.06632667]]", shape="box"] ;
2 -> 3 ;
4 [label="mse = 0.0170\nsamples = 6\nvalue = [[ 0.69588333]
[ 0.20275 ]
[ 0.0953 ]
[ 0.0436 ]
[ 0.1216 ]
[ 0.17248333]
[ 0.04393333]
[ 0.01178333]
[ 0.99913333]
[ 0.12348333]
[ 0.10838333]
[ 0.06973333]]", shape="box"] ;
2 -> 4 ;
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何解决这个问题,因为这只是我从DecisionTreeRegressor得到的输出.
我也试过转换点文件:
dot -Tpng tree.dot -o tree.png
Run Code Online (Sandbox Code Playgroud)
但是这会产生相同的错误(字符串超过行尾)我也尝试使用xdot可视化tree.dot并且给出了相同的错误.
| 归档时间: |
|
| 查看次数: |
1779 次 |
| 最近记录: |