【发布时间】:2017-04-19 07:31:57
【问题描述】:
抱歉,我会懒惰地复制粘贴我的代码...我要解决的问题是为 3 类问题绘制 OOB 错误图(针对三个不同的分类器)。类似于http://scikit-learn.org/stable/auto_examples/ensemble/plot_ensemble_oob.html。
- 问题。
即使我创建了有序字典,代码返回,“标签”未定义。在特定行上有注释。任何人都可以发现代码的问题???
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 回答了这个问题。代码已相应更新。
- 问题
【问题讨论】:
标签: python pandas numpy random-forest