###前提・実現したいこと
決定木分析をしようとしたところ、掲題の「ImportError: cannot import name 'graph_from_dot_data' from 'pydotplus'(C:\ProgramData\Anaconda3\lib\site-packages\pydotplus_init_.py)」とエラー表示が発生してしまいます。
検索してみたところ、同様の質問も見受けられなかったため質問させていただきました。
Pythonによるあたらしいデータ分析の教科書を用いてPythonを勉強している初学者です。
初心者でも分かるようにご回答いただければ幸いです。
###発生している問題・エラーメッセージ
ImportError: cannot import name 'graph_from_dot_data' from 'pydotplus' (C:\ProgramData\Anaconda3\lib\site-packages\pydotplus_init_.py)
###該当のソースコード
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
iris = load_iris()
X, y = iris.data, iris. target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=123)
tree = DecisionTreeClassifier(max_depth=3)
tree.fit(X_train, y_train)
! pip install graphviz
! pip install pydotplus
from pydotplus import graph_from_dot_data
from sklearn.tree import export_graphviz
dot_data = export_graphviz (tree, filled=True,
rounded=True,
class_names=["Setona",
"Vercicolor",
"virginica"],
feature_names=["Sepal Length",
"Sepal Width",
"Petal Length",
"Petal Width"],
out_file=None)
graph = graph_from_dot_data (dot_data)
graph.write_png("test1.png")
###補足情報(FW/ツールのバージョンなど)
Anaconda3でJupyternotebook6.0.0を使用しています。
回答1件
あなたの回答
tips
プレビュー