Module 5 · Machine Learning for Time Series Forecasting

Bagging the Airline Passengers

Monthly international airline passengers, 1949 to 1960, in thousands. Each tree forecasts next month from the last three months and the calendar month. One deep tree overreacts to quirks in the history. Bagging trains many trees on bootstrap resamples of 1950 to 1958 and averages them. Then we score the forecasts on 1959 and 1960, which no tree ever saw.

Target
Base learner · max tree depth
Each tree gets its own bootstrap sample of training months.
Bigger leaves make each tree calmer on its own.
Try

Forecasts, one month ahead average of 20 trees

Actual passengers Individual trees Highlighted tree Bagged forecast Out of bag for that tree

In the shaded test years the faint lines fan out: that spread is variance. The blue line is their average. Where every tree misses in the same direction, that is bias, and averaging can't fix it.

Test RMSE vs number of trees 1959 to 1960, thousands

Bagged forecast OOB estimate Typical single tree Seasonal naive: same month last year

The first ten or so trees do most of the work, then the curve flattens. Notice the orange OOB line sits well below the real test error. Out of bag months fall between training months, so OOB measures filling gaps, not forecasting the future.

Which months one tree trained on

Each cell is one training month. The number is how many times the bootstrap drew it.

Tree 1 of 20
1Drawn once 2Twice 3Three or more 0Out of bag ·Warm-up, needed for lags TTest month, never trained on
Training months: – Unique months in bag: – Out of bag: – Theory: about 36.8% left out, since (1 − 1/n)ⁿ → e⁻¹
Single tree–avg test RMSE of one tree
Bagged–test RMSE, B = 20
Seasonal naive–benchmark to beat
Bagging gain–RMSE drop vs one tree
–

1 · Bootstrap the rows

After building lag features, every month becomes one row: its last three months and its calendar month in, its value out. Bagging draws those rows with replacement. Some months show up twice, about a third never show up, so every tree learns a slightly different history.

2 · Average the forecasts

If each tree's forecast has variance σ²T and trees are correlated by ρ, the average has variance ρσ²T + (1 − ρ)σ²T/B. More trees shrink the second term only. That is why the curve flattens instead of reaching zero.

3 · OOB is optimistic for time series

An out of bag month still has training months right before and after it, so OOB error is an interpolation score. For a forecast you want a later holdout, or time series cross validation with an expanding window.

4 · Trees can't extrapolate

A tree predicts averages of values it has seen. Switch the target to raw counts and every 1960 forecast is stuck below the 1958 peak, no matter how many trees you bag. Modeling the seasonal log change removes the trend, so the trees only learn growth rates, and the forecast rebuilds the level.