【发布时间】:2020-01-09 01:54:52
【问题描述】:
当我想可视化树时,我得到了这个错误。
我已经展示了导入的所需库。 jupiter-notebook 是否有预期的原因?
from sklearn import tree
import matplotlib.pyplot
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_breast_cancer
cancer=load_breast_cancer()
x=cancer.data
y=cancer.target
clf=DecisionTreeClassifier(max_depth=1000)
x_train,x_test,y_train,y_test=train_test_split(x,y)
clf=clf.fit(x_train,y_train)
tree.plot_tree(clf.fit(x_train,y_train))
AttributeError: 模块 'sklearn.tree' 没有属性 'plot_tree'
【问题讨论】:
-
确保您的
matplotlib版本 >= 1.5 并在将其放入绘图功能之前尝试将其保存到对象 -
matplotlib 版本为 3.0.3
-
plot_tree是 0.21 版中的新功能。也许检查你的 scikit-learn 版本 -
非常感谢,这是我的 sklearn 版本
标签: python tree jupyter-notebook sklearn-pandas