首页 > 其他 > 详细

scikit包遇到的问题。

时间:2015-04-21 20:44:38      阅读:653      评论:0      收藏:0      [点我收藏+]

因为需要调用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 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

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

scikit包遇到的问题。

原文:http://blog.csdn.net/huruzun/article/details/45175141

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!