当我想要可视化树时,出现了这个错误。
我已经展示了所需的导入库。是否与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))
属性错误:模块'sklearn.tree'没有属性'plot_tree'
matplotlib
版本大于等于 1.5,并尝试在将其放入绘图函数之前将拟合结果保存到一个对象中。 - Anna Yashinaplot_tree
是在 0.21 版本中新增的。也许需要检查您的 scikit-learn 版本。 - Josmoor98