質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

2回答

1763閲覧

決定木分析のコードについて

KUSS

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2022/01/05 14:53

前提・実現したいこと

決定木分析のやり方を、あるサイトをみながら(https://analysis-navi.com/?p=2007)勉強しています。

発生している問題・エラーメッセージ

下記のようにコード入力しました。
import numpy as np
import pandas as pd
df_past = pd.read_csv("user_data.csv")
X_name = ["sex", "student", "stay time"]
y_name = ["registration"]
X = df_past[X_name]
y = df_past[y_name]
from sklearn.datasets import *
from sklearn import tree
from dtreeviz.trees import *
import graphviz
dtree = tree.DecisionTreeClassifier(max_depth=2)
dtree.fit(X,y)
上記のコードによって、
DecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',
max_depth=2, max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, presort='deprecated',
random_state=None, splitter='best')
と無事出力されました。さらに、下記ようにコードを入力したのですが、図がうまく出力されません。
viz = dtreeviz(dtree,X,y,
target_name = 'registration',
feature_names = X_name,
class_names = ["Not Register","Register"])

viz

下記がエラーメッセージとなります。エラーの意味があまりに分からずで何が原因か教えていただけますと幸いです。

エラーメッセージ FileNotFoundError Traceback (most recent call last) /opt/anaconda3/lib/python3.7/site-packages/graphviz/backend/execute.py in run_check(cmd, input_lines, encoding, capture_output, quiet, **kwargs) 84 else: ---> 85 proc = subprocess.run(cmd, **kwargs) 86 except OSError as e: /opt/anaconda3/lib/python3.7/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs) 487 --> 488 with Popen(*popenargs, **kwargs) as process: 489 try: /opt/anaconda3/lib/python3.7/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: /opt/anaconda3/lib/python3.7/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, restore_signals, start_new_session) 1550 err_msg += ': ' + repr(err_filename) -> 1551 raise child_exception_type(errno_num, err_msg, err_filename) 1552 raise child_exception_type(err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'dot': 'dot' The above exception was the direct cause of the following exception: ExecutableNotFound Traceback (most recent call last) /opt/anaconda3/lib/python3.7/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: /opt/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py in _repr_svg_(self) 35 36 def _repr_svg_(self): ---> 37 return self.svg() 38 39 def svg(self): /opt/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py in svg(self) 39 def svg(self): 40 """Render tree as svg and return svg text.""" ---> 41 svgfilename = self.save_svg() 42 with open(svgfilename, encoding='UTF-8') as f: 43 svg = f.read() /opt/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py in save_svg(self) 52 tmp = tempfile.gettempdir() 53 svgfilename = os.path.join(tmp, f"DTreeViz_{os.getpid()}.svg") ---> 54 self.save(svgfilename) 55 return svgfilename 56 /opt/anaconda3/lib/python3.7/site-packages/dtreeviz/trees.py in save(self, filename) 80 graphviz.backend.run(cmd, capture_output=True, check=True, quiet=False) 81 else: ---> 82 graphviz.backend.execute.run_check(cmd, capture_output=True, check=True, quiet=False) 83 84 if filename.endswith(".svg"): /opt/anaconda3/lib/python3.7/site-packages/graphviz/backend/execute.py in run_check(cmd, input_lines, encoding, capture_output, quiet, **kwargs) 86 except OSError as e: 87 if e.errno == errno.ENOENT: ---> 88 raise ExecutableNotFound(cmd) from e 89 raise 90 ExecutableNotFound: failed to execute 'dot', make sure the Graphviz executables are on your systems' PATH Out[33]: <dtreeviz.trees.DTreeViz at 0x7fb4d683d4d0> ### 該当のソースコード ```ここに言語名を入力 ソースコード

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

failed to execute 'dot', make sure the Graphviz executables are on your systems' PATH

graphvizをMacで使用したい。。

投稿2022/01/05 15:28

jbpb0

総合スコア7651

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

English

1ExecutableNotFound: failed to execute 'dot', make sure the Graphviz executables are on your systems

をGoogle翻訳すると、

Japanese

1ExecutableNotFound:「ドット」の実行に失敗しました。Graphviz実行可能ファイルがシステム上にあることを確認してください 2

です。

Graphviz をインストールするを読んで、Graphviz実行可能ファイルをインストールしてください。

投稿2022/01/05 15:06

ppaul

総合スコア24666

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問