if not has_fit_parameter(self.base_estimator_, "sample_weight"):
raise ValueError("%s doesn't support sample_weight."
% self.base_estimator_.__class__.__name__)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "//anaconda/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py", line 411, in fit
return super(AdaBoostClassifier, self).fit(X, y, sample_weight)
File "//anaconda/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py", line 128, in fit
self._validate_estimator()
File "//anaconda/lib/python2.7/site-packages/sklearn/ensemble/weight_boosting.py", line 429, in _validate_estimator
% self.base_estimator_.__class__.__name__)
ValueError: LinearDiscriminantAnalysis doesn't support sample_weight.
这是一个你不会在scikit learn中四处走动的要求。文件明确指出,这是一项硬性要求:
"...Support for sample weighting is required, as well as proper classes_ and n_classes_ attributes."
但是,如果你只想使用一个整体,你可以一直使用装袋,而不是增加:
from sklearn.ensemble import BaggingClassifier
clf = BaggingClassifier(base_estimator=LDA())
clf.fit(X_train, y_train)
尽管scikitlearn的
AdaBoostClassifier
允许您选择一个基估计器(参见documentation),但它要求估计器支持sample_weight
。看看source:不幸的是,}都不属于这一类。下面是一个玩具的例子:
^{pr2}$LinearDiscriminantAnalysis
和{您将看到如下所示的回溯:
这是一个你不会在scikit learn中四处走动的要求。文件明确指出,这是一项硬性要求:
但是,如果你只想使用一个整体,你可以一直使用装袋,而不是增加:
相关问题 更多 >
编程相关推荐