我道歉,我会懒洋洋地复制粘贴我的代码...我试图解决的问题是为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回答了它。代码已被更新。
答案 0 :(得分:1)
您忘记在for循环中加入label
,您需要这样:
for label, est in zip(label_list, estimator_list):