LoslegenKostenlos loslegen

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".

Diese Übung ist Teil des Kurses

Winning a Kaggle Competition in Python

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

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)
Code bearbeiten und ausführen