Accessing the values of base classifiers from stacked ensemble model

Viewed 28

How can I access the values of the base classifiers from a stacked ensemble mode? I used StackingClassifier from sklearn.

When I implement this:

model.final_estimator_.decision_function(X_train)

I got this error:

X has 10 features, but LinearRegression is expecting 4 features as input.

I have a stacked ensemble model with:

  • Decision tree, linear regression, XGB and MLP as base classifer
  • Linear regression as meta classifier

Im just curious how could I access what is passed from the base classifier to the metaclassifier

1 Answers

The fitted base estimators are stored in the attribute estimators_ and named_estimators_, so you can inspect them directly that way. The ensemble's transform method returns an array with columns being the base estimators' predictions, so that's a more convenient way to "access what is passed from the base classifier to the metaclassifier". (And of course the ensemble's predict method(s) will make the base estimators' predictions as in transform and then use that as input to the final_estimator_.predict.)

Related