问题描述
我试图将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. Can some one point out the classifiers that can be used with AdaBoostClassifier?
推荐答案
好的,我们有一种系统的方法来找出AdaBoostClassifier支持的所有基础学习者.兼容的基础学习者的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,伯努利(Bernoulli)NB,DecisionTreeClassifier,ExtraTreeClassifier,ExtraTreesClassifier,多项式NBNuSVC,感知器RandomForestClassifier,RidgeClassifierCV,SGDClassifier,SVC.
This results in following output: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'.
感谢Andreas展示了如何列出所有估算器.
Thanks to Andreas for showing how to list all estimators.
这篇关于具有不同基础学习者的AdaBoostClassifier的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!