I am doing a text classification task. Now I want to use ensemble.AdaBoostClassifier
with LinearSVC
as base_estimator
. However, when I try to run the code
clf = AdaBoostClassifier(svm.LinearSVC(),n_estimators=50, learning_rate=1.0, algorithm='SAMME.R')
clf.fit(X, y)
An error occurred. TypeError: AdaBoostClassifier with algorithm='SAMME.R' requires that the weak learner supports the calculation of class probabilities with a predict_proba method
The first question is Cannot the svm.LinearSVC()
calculate the class probabilities ? How to make it calculate the probabilities?
Then I Change the parameter algorithm
and run the code again.
clf = AdaBoostClassifier(svm.LinearSVC(),n_estimators=50, learning_rate=1.0, algorithm='SAMME')
clf.fit(X, y)
This time TypeError: fit() got an unexpected keyword argument 'sample_weight'
happens. As is said in AdaBoostClassifier, Sample weights. If None, the sample weights are initialized to 1 / n_samples.
Even if I assign an integer to n_samples
, error also occurred.
The second question is What does n_samples
mean? How to solve this problem?
Hope anyone could help me.
According to @jme 's comment, however, after trying
clf = AdaBoostClassifier(svm.SVC(kernel='linear',probability=True),n_estimators=10, learning_rate=1.0, algorithm='SAMME.R')
clf.fit(X, y)
The program cannot get a result and the memory used on the server keeps unchanged.
The third question is how I can make AdaBoostClassifier
work with SVC
as base_estimator?