# Combining scaling, dimensionality reduction, prediction using sklearn pipeline

I would like to use a sklearn pipeline doing this :

( - ) scale the data ( StandardScaler )

( - ) reduce dimensionality ( PCA )

( - ) make a prediction with GradientBoostingRegressor() and GridSearchCV() ( to get the model with best parameters from grid )

( - ) make a prediction with RandomForestRegressor() and GridSearchCV() ( to get the model with best parameters from grid )

( - ) take the mean of both predictions

but I cannot figure out how to proceed.

Do I have to ( scale & predict ) 2 times or can I scale and then predict 2 times ?

Thks.

The problem seems to be that sklearn pipelines are strictly linear in nature, so you can't fit the two models within the pipeline. You could try ensembling the GBM and RF into a new model object to use; for that, use FeatureUnion: