scikit包遇到的问题。

来源:互联网 发布:阳西县官方网络问政 编辑:程序博客网 时间:2024/05/19 17:06

因为需要调用scikit包中Adaboost算法,我们需要设定一个基础分类器,因为开始不知道随便设定一些分类器,出现错误信息:

TypeError: fit() got an unexpected keyword argument 'sample_weight' 然后网上搜到有人问到这个问题如下:

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? 

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 inspectfrom sklearn.utils.testing import all_estimatorsfor name, clf in all_estimators(type_filter='classifier'):    if 'sample_weight' in inspect.getargspec(clf().fit)[0]:       print name

This results in following output: AdaBoostClassifier, BernoulliNB, DecisionTreeClassifier, ExtraTreeClassifier, ExtraTreesClassifier, MultinomialNB, NuSVC, Perceptron, RandomForestClassifier, RidgeClassifierCV, SGDClassifier, SVC.

运行结果如图:


If the classifier doesn't implement predict_proba, you will have to set AdaBoostClassifier parameter algorithm = 'SAMME'.

原始链接:http://stackoverflow.com/questions/18306416/adaboostclassifier-with-different-base-learners
0 0
原创粉丝点击