Get startedGet started for free

Model stacking I

Now it's time for stacking. To implement the stacking approach, you will follow the 6 steps we've discussed in the previous video:

  1. Split train data into two parts
  2. Train multiple models on Part 1
  3. Make predictions on Part 2
  4. Make predictions on the test data
  5. Train a new model on Part 2 using predictions as features
  6. Make predictions on the test data using the 2nd level model

train and test DataFrames are already available in your workspace. features is a list of columns to be used for training on the Part 1 data and it is also available in your workspace. Target variable name is "fare_amount".

This exercise is part of the course

Winning a Kaggle Competition in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

from sklearn.model_selection import train_test_split
from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor

# Split train data into two parts
part_1, part_2 = ____(train, test_size=____, random_state=123)

# Train a Gradient Boosting model on Part 1
gb = GradientBoostingRegressor().____(____[features], ____.fare_amount)

# Train a Random Forest model on Part 1
rf = RandomForestRegressor().____(____[features], ____.fare_amount)
Edit and Run Code