码迷,mamicode.com
首页 > 其他好文 > 详细

scikit包遇到的问题。

时间:2015-04-21 20:45:23      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:python   scikit   

因为需要调用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包遇到的问题。

标签:python   scikit   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!