我正在学习scikit-learn。我一直在尝试为特定任务优化分类器,其中性能由日志丢失来判断。我正在尝试检查VotingClassifier()是否可以使用我的两个性能最佳的分类器来提高我的性能。
这是我的代码:
estimators = [RandomForestClassifier(random_state=0,n_estimators=500,bootstrap=False,criterion='entropy',
max_depth=None,max_features='auto'),
LogisticRegression(solver='lbfgs',C=opt_c)]
vc = VotingClassifier(estimators=estimators,voting='soft',weights=[1,1])
vc.fit(X_train_std,y_train.as_matrix())
vcp = vc.predict_proba(X_valid_std)
print('Score: {}\tLog Loss: {}'.format(vc.score(X_valid_std,y_valid),log_loss(y_valid,vcp)))
但是,当我尝试运行此代码时,出现以下错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-123-8cd305ba77b8> in <module>()
----> 1 vc.fit(X_train_std,y_train.as_matrix())
/afs/-omited-/miniconda2/envs/iaml/lib/python2.7/site-packages/sklearn/ensemble/voting_classifier.pyc in fit(self, X, y, sample_weight)
170 raise ValueError('Underlying estimator \'%s\' does not'
171 ' support sample weights.' % name)
--> 172 names, clfs = zip(*self.estimators)
173 self._validate_names(names)
174
/afs/-ommited-/miniconda2/envs/iaml/lib/python2.7/site-packages/sklearn/ensemble/base.pyc in __iter__(self)
145 def __iter__(self):
146 """Returns iterator over estimators in the ensemble."""
--> 147 return iter(self.estimators_)
148
149
AttributeError: 'RandomForestClassifier' object has no attribute 'estimators_'
有人可以说明为什么会这样吗?
答案 0 :(得分:1)
我弄清楚了我的错误,估算器属性采用了元组列表。