sklearn下绕过graph.rende查看图片

问题背景

原始代码

file = pd.read_csv("train.csv")
feature_names = ["is_login","view_duration","last_up","ofcl_count","other_count"]
x = file[feature_names]
y = file[["click"]]
print(y.sum())
x_train0, x_test0, y_train0, y_test0 =  model_selection.train_test_split( x, y, test_size=0.3)
#model = svm.SVC()
#model = GradientBoostingClassifier(random_state=10)
model = DecisionTreeClassifier(random_state=0,max_depth=5)
model.fit(x_train0,y_train0)
joblib.dump(model, "dt.m")
#model.score(x_test0,y_test0)
test_result = model.predict(x_test0)
dot_data = export_graphviz(model, out_file="xx",
                         feature_names=feature_names,
                         class_names=["NO","YES"],
                         filled=True, rounded=True,
                         special_characters=True)
graph = graphviz.Source(dot_data)  
graph.render("xx")

使用报错

Traceback (most recent call last):
  File "dt_train.py", line 31, in <module>
    graph.render("picx")
  File "/usr/lib/python3.6/site-packages/graphviz/files.py", line 209, in render
    quiet=quiet)
  File "/usr/lib/python3.6/site-packages/graphviz/backend.py", line 221, in render
    run(cmd, capture_output=True, cwd=cwd, check=True, quiet=quiet)
  File "/usr/lib/python3.6/site-packages/graphviz/backend.py", line 167, in run
    raise ExecutableNotFound(cmd)
graphviz.backend.ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'picx'], make sure the Graphviz executables are on your systems' PATH

由于我使用的是docker运行,若使用anacoda重新安装graphviz下载过慢,找到一个解决办法是直接使用

dot -Tpng xx -o loan_tree.png

问题解决。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值