我试图绘制我的随机林,但它给我以下错误:TypeError:unshable type:“slice”除了显示空的绘图之外。模型本身运行良好,给了我可接受的精确度和召回分数。在
from sklearn.ensemble import RandomForestClassifier
forest = RandomForestClassifier(n_estimators=500, random_state=0)
forest.fit(train_x, train_y)
import matplotlib as plt
import matplotlib.pyplot as plt
import mglearn
fig, axes = plt.subplots(2, 3, figsize=(20, 10))
for i, (ax, tree) in enumerate(zip(axes.ravel(), forest.estimators_)):
ax.set_title("Tree {}".format(i))
mglearn.plots.plot_tree_partition(train_x, train_y, tree, ax=ax)
mglearn.plots.plot_2d_separator(forest, train_x, fill=True, ax=axes[-1, -1],
alpha=.4)
axes[-1, -1].set_title("Random Forest")
mglearn.discrete_scatter(train_x[:, 0], train_x[:, 1], train_y)
请参见下面的详细错误:
^{pr2}$
错误来自pandas,因为函数不支持它
尝试用
plot_2d_separator
中的train_x
替换您的train_x.values
希望这有帮助,
干杯
相关问题 更多 >
编程相关推荐