【问题标题】:OOB score graph for multiclass random forrest. (OneVsRest)多类随机森林的 OOB 得分图。 (一个与休息)
【发布时间】:2017-04-19 07:31:57
【问题描述】:

抱歉,我会懒惰地复制粘贴我的代码...我要解决的问题是为 3 类问题绘制 OOB 错误图(针对三个不同的分类器)。类似于http://scikit-learn.org/stable/auto_examples/ensemble/plot_ensemble_oob.html

  1. 问题。

即使我创建了有序字典,代码返回,“标签”未定义。在特定行上有注释。任何人都可以发现代码的问题???

min_estimators = 5
max_estimators = 250

estimator_list = estimator_01.estimators_ # List of estimators
labels_list = ['Binary OneVsRest estimator predicting agressiveness', 'Binary OneVsRest estimator predicting passiveness', 'Binary OneVsRest estimator predicting submissiveness'] #List of labels
estimators_dict = OrderedDict((label, []) for label, _ in zip(labels_list, estimator_list))


for i in range(min_estimators, max_estimators + 1):
    for label, est in zip(labels_list, estimator_list):   

        estimator_01.set_params(estimator__n_estimators=i, estimator__oob_score=True, estimator__warm_start=True)
        estimator_01.fit(x_train, y_train)

        oob_error = 1 - est.oob_score_
        estimators_dict[label].append((i, oob_error)) 

for label, clf_err in estimators_dict.items():
    xs, ys = zip(*clf_err)
    plt.plot(xs, ys, label=label)

plt.xlim(min_estimators, max_estimators)
plt.xlabel("n_estimators")
plt.ylabel("OOB error rate")
plt.title('Random Forrest classifier predicting pre-flop actions. OOB rate.')
plt.show()

MAXYMOO 回答了这个问题。代码已相应更新。

  1. 问题

由于某种原因,它会产生三个单变量行,这实际上是不可能的。任何想法为什么会这样?我附上图表。

【问题讨论】:

    标签: python pandas numpy random-forest


    【解决方案1】:

    你忘记在你的 for 循环中包含 label,你需要有这个:

     for label, est in zip(label_list, estimator_list):
    

    【讨论】:

      猜你喜欢
      • 2019-03-14
      • 2017-03-15
      • 2017-09-24
      • 2018-06-06
      • 2018-07-10
      • 2017-05-13
      • 2019-09-05
      • 2013-09-22
      • 2018-02-18
      相关资源
      最近更新 更多