问题描述
我正在尝试将 AdaBoostClassifier 与 DecisionTree 以外的基础学习器一起使用.我尝试过 SVM 和 KNeighborsClassifier,但出现错误.AdaBoostClassifier 可以使用哪些分类器?
I am trying to use AdaBoostClassifier with a base learner other than DecisionTree. I have tried SVM and KNeighborsClassifier but I get errors. What are the classifiers that can be used with AdaBoostClassifier?
推荐答案
好的,我们有一个系统的方法来找出 AdaBoostClassifier 支持的所有基学习器.兼容base learner的fit方法需要支持sample_weight,运行如下代码即可获得:
Ok, we have a systematic method to find out all the base learners supported by AdaBoostClassifier. Compatible base learner's fit method needs to support sample_weight, which can be obtained by running following code:
import inspect
from sklearn.utils.testing import all_estimators
for name, clf in all_estimators(type_filter='classifier'):
if 'sample_weight' in inspect.getargspec(clf().fit)[0]:
print name
结果如下:
AdaBoostClassifier,
BernoulliNB,
DecisionTreeClassifier,
ExtraTreeClassifier,
ExtraTreesClassifier,
MultinomialNB,
NuSVC,
Perceptron,
RandomForestClassifier,
RidgeClassifierCV,
SGDClassifier,
SVC.
如果分类器没有实现predict_proba
,则必须设置 AdaBoostClassifier 参数 algorithm = 'SAMME'.
If the classifier doesn't implement predict_proba
, you will have to set AdaBoostClassifier parameter algorithm = 'SAMME'.
这篇关于具有不同基学习器的 AdaBoostClassifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!