Skip to content

Instantly share code, notes, and snippets.

@vijayvd
Created August 19, 2013 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijayvd/6269621 to your computer and use it in GitHub Desktop.
Save vijayvd/6269621 to your computer and use it in GitHub Desktop.
Using KNeighborsClassifier as a base learner for AdaBoostClassifier
Running following code:
clf = AdaBoostClassifier(n_estimators=100, base_estimator=KNeighborsClassifier()); clf.fit(x,y)
I get the following traceback:
TypeError Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
176 else:
177 filename = fname
--> 178 __builtin__.execfile(filename, *where)
/home/vdesai/Dropbox/currentDocs/Kaggle/scikitComp/code/ensemble/train_adaboost.py in <module>()
49
50 if __name__=="__main__":
---> 51 main()
/home/vdesai/Dropbox/currentDocs/Kaggle/scikitComp/code/ensemble/train_adaboost.py in main()
24 #clf = AdaBoostClassifier(n_estimators=100, base_estimator=SVC(probability=True));
25 clf = AdaBoostClassifier(n_estimators=100, base_estimator=KNeighborsClassifier());
---> 26 clf.fit(x,y)
27 tup = ('adaboost', x, clf)
28 data_io.save_model(tup, 'adaboost.pickle')
/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/weight_boosting.pyc in fit(self, X, y, sample_weight)
387 "algorithm='SAMME' instead.")
388
--> 389 return super(AdaBoostClassifier, self).fit(X, y, sample_weight)
390
391 def _boost(self, iboost, X, y, sample_weight):
/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/weight_boosting.pyc in fit(self, X, y, sample_weight)
123 iboost,
124 X, y,
--> 125 sample_weight)
126
127 # Early termination
/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/weight_boosting.pyc in _boost(self, iboost, X, y, sample_weight)
425 """
426 if self.algorithm == 'SAMME.R':
--> 427 return self._boost_real(iboost, X, y, sample_weight)
428
429 else: # elif self.algorithm == "SAMME":
/usr/local/lib/python2.7/dist-packages/sklearn/ensemble/weight_boosting.pyc in _boost_real(self, iboost, X, y, sample_weight)
439 pass
440
--> 441 estimator.fit(X, y, sample_weight=sample_weight)
442
443 y_predict_proba = estimator.predict_proba(X)
TypeError: fit() got an unexpected keyword argument 'sample_weight'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment