環境
windows 10
python 3.8
jupyter
#from sklearn.linear_model import LogisticRegression #from sklearn.svm import LinearSVC import mglearn import matplotlib.pyplot as plt from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt #from sklearn.datasets import make_blobs import numpy as np #from sklearn.linear_model import LogisticRegression #from sklearn.svm import LinearSVC from sklearn.tree import DecisionTreeClassifier from sklearn.tree import export_graphviz import graphviz cancer = load_breast_cancer() X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,stratify = cancer.target,random_state = 42) logreg = LogisticRegression().fit(X_train,y_train) tree = DecisionTreeClassifier(random_state = 0) tree.fit(X_train,y_train) print('Accuracy on training set: {:.3f}'.format(tree.score(X_train,y_train))) print('Accuracy on test set: {:.3f}'.format(tree.score(X_test,y_test))) tree = DecisionTreeClassifier(max_depth = 4 , random_state = 0) tree.fit(X_train,y_train) print('Accuracy on training set: {:.3f}'.format(tree.score(X_train,y_train))) print('Accuracy on test set: {:.3f}'.format(tree.score(X_test,y_test))) export_graphviz(tree, out_file = "tree.dot", class_names = ["malignant" , "benign"] , feature_names = cancer.feature_names , impurity = False , filled = True) with open('tree.dot') as f: dot_graph = f.read() graphviz.Source(dot_graph)
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) 774 errread, errwrite, --> 775 restore_signals, start_new_session) 776 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) 1177 os.fspath(cwd) if cwd is not None else None, -> 1178 startupinfo) 1179 finally: FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。 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\site-packages\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\site-packages\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\site-packages\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\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', '-Tsvg'], make sure the Graphviz executables are on your systems' PATH
teratail で検索したのですが解決しなかったです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/09 14:55