Building models for prediction · Apple quarterly revenue

How much to hold out?

To test a forecast, we hide the most recent quarters, fit a model to everything before them, and see how well it predicts the quarters it never saw. Choose how many quarters to hold out and which model to fit, and watch the fitted line (solid) and the projection (dashed) change.

Test RMSPE = $19.08B Log model, holding out the last 4 quarters, 2025 Q1 to 2025 Q4
4 quarters (1 year)

Step 1

Fit on the past, project into the holdout

Blue dots are the training quarters. The solid line is the model fit to them. The shaded orange band is the holdout: the dashed line carries the same trend forward into quarters the model never saw, and the orange lines are its misses.

Training quarterHeld-out quarter (test)Fitted lineProjection
Training54quarters
Held out4quarters
Miss on training data13.96Typical miss on quarters it saw ($B)
Test RMSPE19.08Typical miss on held-out quarters ($B)

Step 2

The 4 held-out forecasts

RMSPE turns these misses into one number: square each miss, average the squares, take the square root.

QuarterActual ($B)Forecast ($B)MissMiss squared
Mean of squares
Square root = RMSPE

Step 3

Every holdout size at once

Each holdout size gives a different test. Here are all of them from 1 to 20 quarters. Click the chart to jump to one.

Test RMSPEMiss on training dataOther model's test RMSPEYour holdout

For quarterly data, holding out the last 4 quarters (one year) is a common choice: enough quarters to see every season once, while keeping almost all the history for training. That's what the lecture uses.

In R

Choose a holdout, fit both models, forecast

h <- 4 # quarters to hold out n <- nrow(apple) # 58 quarters training <- apple[1:(n - h), ] # everything before the holdout test <- apple[(n - h + 1):n, ] # the last h quarters log_model <- lm(log(Revenue) ~ Period, data = training) lin_model <- lm(Revenue ~ Period, data = training) log_pred <- exp(predict(log_model, test)) # exp() undoes log() lin_pred <- predict(lin_model, test) # already in $B sqrt(mean((test$Revenue - log_pred)^2)) # RMSPE: 19.08 when h = 4 sqrt(mean((test$Revenue - lin_pred)^2)) # RMSPE: 19.28 when h = 4

Revenue in billions of dollars, by calendar quarter, 2011 Q3 to 2025 Q4 (58 quarters). The log model is log(Revenue) ~ Period and the linear model is Revenue ~ Period, each fit by least squares to the training quarters. "Miss on training data" is the root mean squared miss in dollars on the training quarters. Companion lab: Train, Test, Repeat.