Back to regression with stacking
In Chapter 1, we treated the app ratings as a regression problem, predicting the rating on the interval from 1 to 5. So far in this chapter, we have dealt with it as a classification problem, rounding the rating to the nearest integer. To practice using the StackingRegressor
, we'll go back to the regression approach.
As usual, the input features have been standardized for you with a StandardScaler()
.
The MAE (mean absolute error) is the evaluation metric. In Chapter 1, the MAE was around 0.61
. Let's see if the stacking ensemble method can reduce that error.
This exercise is part of the course
Ensemble Methods in Python
Exercise instructions
- Instantiate a decision tree regressor with:
min_samples_leaf = 11
andmin_samples_split = 33
. - Instantiate the default linear regression.
- Instantiate a
Ridge
regression model withrandom_state = 500
. - Build and fit a
StackingRegressor
, passing theregressors
and themeta_regressor
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Instantiate the 1st-layer regressors
reg_dt = ____(____, ____, random_state=500)
reg_lr = ____
reg_ridge = ____
# Instantiate the 2nd-layer regressor
reg_meta = LinearRegression()
# Build the Stacking regressor
reg_stack = ____
reg_stack.____
# Evaluate the performance on the test set using the MAE metric
pred = reg_stack.predict(X_test)
print('MAE: {:.3f}'.format(mean_absolute_error(y_test, pred)))