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
發佈了166 篇原創文章 · 獲贊 54 · 訪問量 37萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章