Voting and Stacking
Ensemble methods that combine the predictions of different models to predict home sale prices more reliably.
If, for the same house, linear regression predicts $410,000, a random forest predicts $430,000 and gradient boosting predicts $425,000, which value should you trust? Instead of picking one model, can you use the judgments of several models together?
Methods that combine the results of several predictive models to produce a final prediction are called voting and stacking. Voting averages the models’ predictions, or takes a weighted average, while stacking trains a separate model that takes the base models’ predictions as its input.
Random forests and gradient boosting also use many learners, but what sets voting and stacking apart is that they can combine different kinds of models that have already been built. Still, building an ensemble does not by itself guarantee better performance than the individual models.
They are useful for problems that predict continuous values, such as home prices, sales, demand and customer behavior. In this lesson we use a home sale price example to cover how voting and stacking work, how predictions are combined, preventing data leakage, comparing performance, how they differ from other analyses, and how to report the results.
What are voting and stacking?
They are widely used ensemble learning methods that combine the predictions of several models.
In regression problems, voting produces the final prediction by taking the average, or a weighted average, of the numbers predicted by several models. Stacking, by contrast, trains a meta-model that uses the predictions made by each base model as new explanatory variables. To distinguish it from majority voting in classification, regression voting is usually described as averaging.
Why do we need voting and stacking?
They are used to combine the strengths and weaknesses of different models.
Linear regression expresses linear relationships between variables fairly clearly but can miss complex nonlinearity. A random forest reduces variability by averaging many trees, and gradient boosting corrects the errors of earlier models one after another. When different errors are mixed together, an ensemble may reduce the error, but if the models are wrong in the same direction, the benefit is limited.
How do voting and stacking work?
Voting takes an average, while stacking learns a rule for combining the predictions.
① Regression voting: average the predictions
If the models predict 410, 430 and 425 ($ thousands), the simple average is about 421.7 ($ thousands). You can also use a weighted average that gives more weight to better models, but the weights must be set during training without looking at the evaluation data.
② Stacking: learn how to combine
In stacking, the predictions of the three base models are used as inputs to a meta-model. The meta-model can learn in which situations to trust which model’s predictions more.
③ Don’t reselect models during the final evaluation
Decide on the base models, the combining rule and the hyperparameters within the training data, and then check performance just once at the end on independent evaluation data. Repeatedly looking at the evaluation score and making adjustments can make the results overly optimistic.
A real-world example: predicting the sale prices of home listings
We compare three base models and two ensembles on the same housing data.
We prepared 1,000 hypothetical home listings. The sale price is predicted from floor area, number of rooms, year built, neighborhood, distance to a transit station, and so on. 800 listings are used for training and cross-validation, and 200 are set aside for the final evaluation.
| Variable | Example | Role |
|---|---|---|
| Sale price | $425,000 | Target variable |
| Floor area | 1,850 ft² | Input variable |
| Rooms | 3 | Input variable |
| Year built | 2008 | Input variable |
| Neighborhood | A / B / C | Categorical input variable |
| Distance to transit station | 1.2 miles | Input variable |
The values in the results table are hypothetical numbers designed to explain the method. They should not be interpreted as performance obtained by actually training and evaluating models.
What should you check before the analysis?
First check the characteristics of the price data and the evaluation design.
| Item | What to check |
|---|---|
| Distribution of sale prices | Influence of high-priced homes and unusual sales |
| Missing variables | Whether key information such as floor area, age or neighborhood is missing |
| Timing | If predicting future prices, split in time order |
| Duplicate listings | That the same house is not in both the training and evaluation data |
| Preprocessing leakage | Fit imputation, standardization and encoding on the training data only |
| Evaluation metrics | Check errors with MAE, RMSE and in actual dollar amounts |
In what order are the models trained?
Build the base models first, then set up voting and stacking.
① Split off the training data and the final evaluation data
Model development is carried out only on the 800 listings, excluding the 200 held out for the final evaluation. If the actual sale dates need to be taken into account, a time-based split may be more appropriate than a random split.
② Train the three base models
Compare linear regression, a random forest and gradient boosting on the same training data, and choose their settings through cross-validation.
③ Set up the voting model
Take a simple average of the base models’ predictions, or combine them with weights chosen from cross-validation results on the training data.
④ Train the stacking meta-model
Collect the predictions (OOF) for each training row from base models trained on the folds that exclude that row. Training the meta-model on these predictions ensures it does not simply use the overly good predictions of models that were trained on those same rows.
⑤ Compare performance on the same evaluation data
Apply the five models that have completed the selection process to the 200 listings in the final evaluation data and compare their prediction errors.
How are voting weights chosen?
Start with a simple average, and choose any weighted average using validation data.
| Approach | How it combines | Features |
|---|---|---|
| Simple-average voting | Averages the three predictions 1:1:1 | Easy to set up and a good baseline for comparison |
| Weighted-average voting | E.g., averages with weights 0.2·0.3·0.5 | Weights must be chosen during validation |
| Stacking | Trains a meta-model on the predictions | Allows even nonlinear combinations, but adds complexity |
A model with a large weight is not necessarily the better model. The correlation of errors between models also affects the combined result. With real data, it is best to check the simple average first and then compare more complex methods.
How do you compare predictive performance?
Use the same final evaluation data and the same error metrics.
| Model | MAE ($ thousands) | RMSE ($ thousands) |
|---|---|---|
| Linear regression | 42 | 55 |
| Random forest | 31 | 42 |
| Gradient boosting | 29 | 39 |
| Voting | 27 | 36 |
| Stacking | 26 | 35 |
In the hypothetical results, stacking has the lowest MAE of the five models, at $26,000. But it differs from voting’s $27,000 by only $1,000. Further review is needed to tell whether this difference is due to the particular evaluation sample, and whether it matters enough in practice to justify the added model complexity.
How do you interpret MAE and RMSE?
For both metrics smaller is better, but they differ in how much weight they give to large errors.
MAE is the average of the absolute differences between the predicted prices and the actual sale prices. An MAE of $26,000 means the average absolute error in the evaluation data was about that much. RMSE gives more weight to large errors, so it helps you see whether the price was badly off for some houses.
Things to watch out for with voting and stacking
A complex combination does not automatically guarantee better predictions.
Are the base models’ errors too similar?
If the three models are wrong in similar ways for the same houses, averaging them may improve things only a little. Check the correlations between their predictions and residuals.
Is there data leakage in the stacking?
If the meta-model is trained on the base models’ direct predictions on their own training data, overfitting is likely. Use OOF predictions, and fit all preprocessing within the training folds of the cross-validation.
Has performance improved enough to justify the complexity?
If the improvement is small, you might choose a simpler model or voting, taking into account training and operating costs, explainability and inference latency.
Does it generalize across neighborhoods and time periods?
If listings from the same nearby development or sales from adjacent time periods end up in both datasets, performance can be rated higher than it would be for genuinely new listings.
How does it differ from other analyses?
Even when several learners are used, the ways they are combined differ.
| Method | How it trains and combines | Features |
|---|---|---|
| Voting | Averages the final predictions of separate models | Simple combination |
| Stacking | Trains a meta-model on the base models’ predictions | OOF predictions are essential |
| Bagging · random forest | Combines many models built with resampling or randomization | Focuses on reducing variance |
| Gradient boosting | Trains sequentially, correcting the loss of earlier learners | Improves step by step |
| Single linear regression | Fits a single linear relationship | Coefficients relatively easy to interpret |
How do you report the results?
Present the data split, the combining method and the error metrics together.
In the report, state the sample size, the input variables, how the data were split, how missing values and categorical variables were handled, the settings of each model, the voting weights, the fold setup and meta-model for stacking, the evaluation metrics, and the units of the home prices.
Of 1,000 hypothetical home sales, 800 were used for model training and cross-validation and 200 for the final evaluation. Linear regression, a random forest and gradient boosting were used as base models, and we compared voting, which took a simple average of their predictions, with stacking, which trained a meta-model on cross-validated OOF predictions. On the final evaluation data, the MAE was $42 thousand for linear regression, $31 thousand for the random forest, $29 thousand for gradient boosting, $27 thousand for voting and $26 thousand for stacking. The numbers shown are hypothetical examples set up for illustration.
Where can voting and stacking be used?
They can be used when different types of predictive models capture different patterns.
| Field | What is predicted | Example base models |
|---|---|---|
| Real estate | Home sale prices | Linear regression · tree-based models |
| Retail | Weekly sales volume | Regression · boosting models |
| Energy | Electricity demand | Time series · machine learning regression |
| Manufacturing | Product quality scores | Regularized regression · random forest |
| Finance | Predicting loss amounts | Regression · boosting models |
Stacking is not the answer in every field. What matters is confirming the improvement through independent evaluation and judging whether the complexity is manageable in operation.
Voting and stacking pool the predictions of different models to try for better results.
What matters is not how elaborate the combination is, but whether the prediction error for new houses actually went down.
In the home sale price example, linear regression, a random forest and gradient boosting predicted different prices for the same listing. Voting averaged the three values to produce a final price, and stacking additionally learned a combining rule from the base models’ predictions. In the hypothetical results stacking had the lowest MAE, but we cannot assume that the performance differences between the individual models and the ensembles would be reproduced with real data.
For stacking in particular, a design that prevents data leakage while training the meta-model is essential. Rather than feeding the meta-model direct predictions on the training rows, use cross-validated OOF predictions. The final evaluation data should not be used repeatedly to choose models or tune weights. If you consider maintenance costs and explainability as well as predictive accuracy, then when the improvement is small, simple voting or a single model that works well may be more appropriate.
Regression voting averages the price predictions of several models, while stacking trains a meta-model that uses the base models’ predictions as input. The stacking meta-model should be trained on OOF predictions obtained through cross-validation, and the final evaluation data must be kept separate. The value of an ensemble is judged not by the number of models, but by the reduction in prediction error confirmed on independent evaluation data and by whether it is practical to operate.