使用 export_graphviz 时出现 FileNotFoundError: [WinError 2] 系统找不到指定的文件

我使用随机森林训练了我的模型,并希望可视化决策树。然后,我希望将 export_graphviz 转换为 png 文件。

from subprocess import call# Convert to pngcall(['dot', '-Tpng', 'tree_from_optimized_forest.dot', '-o', 'tree_from_optimized_forest.png', '-Gdpi=200'])Image('tree_from_optimized_forest.png')

输出结果是

---------------------------------------------------------------------------FileNotFoundError                         Traceback (most recent call last)<ipython-input-95-f836aa32a65b> in <module>      2       3 # Convert to png----> 4 call(['dot', '-Tpng', 'tree_from_optimized_forest.dot', '-o', 'tree_from_optimized_forest.png', '-Gdpi=200'])      5 Image('tree_from_optimized_forest.png')~\Anaconda3\lib\subprocess.py in call(timeout, *popenargs, **kwargs)    321     retcode = call(["ls", "-l"])    322     """--> 323     with Popen(*popenargs, **kwargs) as p:    324         try:    325             return p.wait(timeout=timeout)~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)    773                                 c2pread, c2pwrite,    774                                 errread, errwrite,--> 775                                 restore_signals, start_new_session)    776         except:    777             # Cleanup if the child failed starting.~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)   1176                                          env,   1177                                          os.fspath(cwd) if cwd is not None else None,-> 1178                                          startupinfo)   1179             finally:   1180                 # Child is launched. Close the parent's copy of those pipeFileNotFoundError: [WinError 2] The system cannot find the file specified

如何解决此错误?


回答:

我使用 pydot 库解决了这个问题

import pydot(graph,) = pydot.graph_from_dot_file('tree_real_data.dot')graph.write_png('somefile.png')

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注