2

i can see the prediction using AdaBoostClassifier of ensemble method of sklearn using code like this.

from sklearn.ensemble import AdaBoostClassifier
clf = AdaBoostClassifier(n_estimators=100)
clf.fit(X_train, y_train)
y_pred= clf.predict(X_test)
print y_pred

Now i want to see the prediction of all base estimators(i.e. estimation of all the individual 100 base estimators.) Is it possible in sklearn. How would i do that ?please help me. Thnaks in advance.

Jaeger
  • 159
  • 4
  • 14

1 Answers1

4
for estimator in clf.estimators_:
    print estimator.predict(X_test)

You can also get weight and classification error for each estimator, see documentation.

Nikita Astrakhantsev
  • 4,701
  • 1
  • 15
  • 26
  • It works fine for default base classifier.But, when i'm using SVM classifier it shows prediction of single estimator. `clf = AdaBoostClassifier(SVC(kernel='linear',probability=True),n_estimators=10, learning_rate=1.0, algorithm='SAMME.R')` I can't figure out why it is printing for a single estimator. How would i print for all the estimators ? Thanks. – Jaeger May 14 '15 at 10:32
  • I guess, the reason is that (cited from docs) 'n_estimators : integer, optional (default=50) The maximum number of estimators at which boosting is terminated. In case of perfect fit, the learning procedure is stopped early.' So, the procedure stops after the 1st iteration. Btw, default SVM isn't good in AdaBoost, see http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.3874&rep=rep1&type=pdf – Nikita Astrakhantsev May 14 '15 at 10:42
  • can you help in in this question. [how does sklearn's Adaboost predict_proba works internally](http://stackoverflow.com/questions/30239305/how-does-sklearns-adaboost-predict-proba-works-internally) – Jaeger May 14 '15 at 14:07