Issue
I trained my model using Random Forest and I want to Visualize the Decision Tree. Then, I want to convert the export_graphviz to a png file.
from subprocess import call
# Convert to png
call(['dot', '-Tpng', 'tree_from_optimized_forest.dot', '-o', 'tree_from_optimized_forest.png', '-Gdpi=200'])
Image('tree_from_optimized_forest.png')
The output is
---------------------------------------------------------------------------
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 pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
How to solve the error?
Solution
I solve it using pydot library
import pydot
(graph,) = pydot.graph_from_dot_file('tree_real_data.dot')
graph.write_png('somefile.png')
Answered By - ebuzz168
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.