У меня есть pip install Graphviz в conda. и получите путь из конды файла. Graphviz правильно установлен в системе, но по-прежнему получает эту ошибку. Я работаю в ноутбуке jupyter. Я работаю над алгоритмом дерева решений и получаю сообщение об ошибке при использовании graphviz.i уже установили pydot.
Prediction and Evaluation
Let's evaluate our decision tree.
predictions = dtree.predict(X_test)
from sklearn.metrics import classification_report,confusion_matrix
print(classification_report(y_test,predictions))
precision recall f1-score support
absent 0.81 0.94 0.87 18
present 0.75 0.43 0.55 7
accuracy 0.80 25
macro avg 0.78 0.69 0.71 25
weighted avg 0.79 0.80 0.78 25
print(confusion_matrix(y_test,predictions))
[[17 1]
[ 4 3]]
import os
os.environ["PATH"] += os.pathsep + 'graphviz in c:/users/anu nema/appdata/local/programs/python/python38-32/lib/site-packages/graphviz'
from sklearn.tree import export_graphviz
dot_data=export_graphviz(dtree, out_file="dtree.dot", class_names=["absent", "present"],feature_names=features, impurity=True, filled=True)
import graphviz
with open("dtree.dot") as f:
dot_data = f.read()
graphviz.Source(dot_data)
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\anaconda3\lib\graphviz\backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
163 try:
--> 164 proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
165 except OSError as e:
~\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)
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
~\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)
1206 os.fspath(cwd) if cwd is not None else None,
-> 1207 startupinfo)
1208 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
ExecutableNotFound Traceback (most recent call last)
~\anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
343 method = get_real_method(obj, self.print_method)
344 if method is not None:
--> 345 return method()
346 return None
347 else:
~\anaconda3\lib\graphviz\files.py in _repr_svg_(self)
111
112 def _repr_svg_(self):
--> 113 return self.pipe(format='svg').decode(self._encoding)
114
115 def pipe(self, format=None, renderer=None, formatter=None, quiet=False):
~\anaconda3\lib\graphviz\files.py in pipe(self, format, renderer, formatter, quiet)
136 out = backend.pipe(self._engine, format, data,
137 renderer=renderer, formatter=formatter,
--> 138 quiet=quiet)
139
140 return out
~\anaconda3\lib\graphviz\backend.py in pipe(engine, format, data, renderer, formatter, quiet)
242 """
243 cmd, _ = command(engine, format, None, renderer, formatter)
--> 244 out, _ = run(cmd, input=data, capture_output=True, check=True, quiet=quiet)
245 return out
246
~\anaconda3\lib\graphviz\backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
165 except OSError as e:
166 if e.errno == errno.ENOENT:
--> 167 raise ExecutableNotFound(cmd)
168 else:
169 raise
ExecutableNotFound: failed to execute ['dot', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH
<graphviz.files.Source at 0xa852610>
g=graphviz.Source(dot_data)
g.view()
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\anaconda3\lib\site-packages\graphviz\backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
163 try:
--> 164 proc = subprocess.Popen(cmd, startupinfo=get_startupinfo(), **kwargs)
165 except OSError as e:
~\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)
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
~\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)
1206 os.fspath(cwd) if cwd is not None else None,
-> 1207 startupinfo)
1208 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
ExecutableNotFound Traceback (most recent call last)
<ipython-input-29-f295ffe886cc> in <module>
1 g=graphviz.Source(dot_data)
----> 2 g.view()
~\anaconda3\lib\site-packages\graphviz\files.py in view(self, filename, directory, cleanup, quiet, quiet_view)
240 return self.render(filename=filename, directory=directory,
241 view=True, cleanup=cleanup,
--> 242 quiet=quiet, quiet_view=quiet_view)
243
244 def _view(self, filepath, format, quiet):
~\anaconda3\lib\site-packages\graphviz\files.py in render(self, filename, directory, view, cleanup, format, renderer, formatter, quiet, quiet_view)
207 rendered = backend.render(self._engine, format, filepath,
208 renderer=renderer, formatter=formatter,
--> 209 quiet=quiet)
210
211 if cleanup:
~\anaconda3\lib\site-packages\graphviz\backend.py in render(***failed resolving arguments***)
219 cwd = None
220
--> 221 run(cmd, capture_output=True, cwd=cwd, check=True, quiet=quiet)
222 return rendered
223
~\anaconda3\lib\site-packages\graphviz\backend.py in run(cmd, input, capture_output, check, encoding, quiet, **kwargs)
165 except OSError as e:
166 if e.errno == errno.ENOENT:
--> 167 raise ExecutableNotFound(cmd)
168 else:
169 raise
ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'Source.gv'], make sure the Graphviz executables are on your systems' PATH