3

Below is an example sklearn pipeline. There are two sklearn StackingClassifiers:

  1. stackingclassifier1 with base classifier as RandomForestClassifier & stackingclassifier2 as Meta Learner.
  2. stackingclassifier2 with base classifier as KNearestNeighborsClassifier & SVC as Meta Learner.

So pipeline is: enter image description here I want to use featureset1 on RndomForestClassifier & featureset2 on KNearestNeighborsClassifier & featureset3 on SVM. However on pipeline only option I am getting is to pass one featureset for all pipeline steps - Pipeline.fit(X_train, y_train).

How could I pass different featureset to different estimators enter image description here

Also this is a workaround implementation. In my design there is no stack. Just one learner passing probability to next. Then get final probabilities at last step. If there is a better implementation technique using pipeline please add that as well. Thanks

Alexander L. Hayes
  • 3,892
  • 4
  • 13
  • 34
  • You can probably use a `ColumnTransformer` to handle the different feature sets. But the rest of this setup doesn't make much sense: stackingclassifiers with only one base estimator are unlikely to be useful, and the first stack will be treated as a transformer, and so will only pass the RF predictions forward to the next step (the LR will be ignored entirely). – Ben Reiniger Nov 21 '22 at 17:05
  • @BenReiniger Your point is absolutely correct. I realized that the example I have posted is flawed. I have fixed that now & have provided detailed information on what I am looking for in the description. Have a look. I will try out ColumnTransformer. Thanks a lot! – Jyoti Hassanandani Nov 22 '22 at 09:04
  • https://stackoverflow.com/q/63974211/10495893 – Ben Reiniger Nov 22 '22 at 15:39
  • @BenReiniger This is really great trick will be interesting to implement this. Thanks a lot! – Jyoti Hassanandani Dec 08 '22 at 08:30
  • @BenReiniger I am facing an issue with this resolution when using predict_proba inplace of predict with custom classifier. Please see details at this link: https://stackoverflow.com/questions/75148145/sklearn-pipeline-one-feature-automatically-missed-out. Probably you will know the resolution. Thanks! – Jyoti Hassanandani Jan 18 '23 at 12:17

0 Answers0