Several seasons and long series
- Lesson 13
- 35 min
- Module 4: Statistical forecasters
Where we are
So far, our series had one season: the week. Hourly tickets have two: the day and the week. In this lesson, we forecast Grace's hourly tickets with MSTL and Theta, which handle several seasons, and we add known events as extra inputs.
Lesson 13 of 27 · Forecasting and Time Series: Predict What Comes NextSeveral seasons and long series
1. Forecasts serve decisions
2. Read a time series
3. Baselines and honest testing
4. Statistical forecasters
5. Machine learning forecasters
6. Hard series and many series
7. Uncertainty and the decision
8. Run a forecast in production
What you will be able to do
Forecast a series with two seasons, the day and the week, with MSTL and Theta. Check each forecast’s range before you plan with it, and add a known event, the Christmas delivery days, as an extra input.
NotebookDo this lesson in a notebook
The notebook has every code cell, task and check of this lesson. It shows the two seasons of the hourly tickets and splits them into parts with MSTL. It runs MSTL and Theta in the ticket backtest and checks their ranges and rosters. Last, it adds the Christmas delivery days as an input. Its setup cells install the packages and download the Larkfield data, so it needs no local setup. About 35 minutes.
Colab and Kaggle open your own copy. They need a free Google or Kaggle account. Stuck? See the solution notebook.
Before you startWhat to know and to have ready
What you need to know
- ETS and its one season, from Exponential smoothing (ETS, Holt-Winters).
- ARIMA, its extra inputs and its fit time, from ARIMA and SARIMA.
- An 80% range, from ARIMA and SARIMA: it should hold the real value about 8 times out of 10.
- Seasons and decomposition, from Trend, season and noise.
What you need on your computer
Nothing: the notebook runs in Colab or Kaggle. To run it on your own computer, use Python 3.12 with Jupyter or VS Code. The notebook’s first cell installs the packages.
Tested with Python 3.12, pandas 2.3.3 and statsforecast 2.1.1, in Jupyter on macOS.
How a café plans its staff
Section titled “How a café plans its staff”Think of the café again. The owner plans her staff with two rhythms in her head. Every day has a lunch rush at noon. Every week has a quiet Monday and a busy Saturday. With only the daily rhythm, Monday and Saturday get the same staff. With only the week, she forgets the lunch rush.
The problem: one season is not enough
Section titled “The problem: one season is not enough”Grace, the support lead, plans how many agents work in each hour, from 07:00 to 21:59. She needs a forecast of the tickets per hour for the next week.
Here are two weeks of hourly tickets, before Sunday 15 March 2026:
Text description of the chart
The chart shows 336 hours, from Monday 2 March to Sunday 15 March 2026. The line goes up and down once a day: 0 to 3 tickets at night, a peak in the late morning, at most 49. The peaks are higher on weekdays. Added up per day, the first week has 457 tickets on Monday and 222 on Sunday. The second week has 336 on Monday, 417 on Wednesday and 205 on Sunday.
The series has two seasons: a daily one of 24 hours, and a weekly one of 168 hours (7 × 24). In Exponential smoothing, ETS with one 24-hour season forecast the same total every day:
- Real tickets
- ETS, 24-hour season
Text description of the chart
The chart shows seven days, Monday to Sunday. The real tickets are dots: 473, 474, 393, 409, 294, 337, 243. The ETS forecast is a flat dashed line at 243 tickets every day. On Monday, the forecast is 230 tickets too low.
ETS with a 168-hour season follows the week: its WAPE in this week was 26.2%, against 39.3%. But it learns each of the 168 values from only 12 examples. And it does not show which part is the day and which the week.
The idea: split the series into parts
Section titled “The idea: split the series into parts”MSTL, which you met in Trend, season and noise, splits the series into parts, one for each pattern. Here it also forecasts: each part on its own.
Text description of the diagram
One box, the hourly tickets of the last 12 weeks, splits into four. They are the trend (forecast with ETS), the daily season of 24 hours and the weekly season of 168 hours (both in orange). The fourth, dashed, is the remainder: the noise, which is not forecast. Arrows from the first three join in a last box: forecast = trend forecast + daily season + weekly season.
A tiny example with real parts
Section titled “A tiny example with real parts”MSTL found these parts in the last week of the history before 15 March 2026. The four parts of each hour add up exactly to the tickets of that hour:
| Hour | Tickets | Trend | Daily season | Weekly season | Remainder |
|---|---|---|---|---|---|
| Monday 9 March, 11:00 | 37 | 12.3 | 18.3 | 9.8 | -3.5 |
| Sunday 15 March, 11:00 | 20 | 12.7 | 18 | -9.7 | -1 |
The two hours have almost the same daily season, 18.3 and 18: it is 11:00 on both days. (MSTL lets a season change slowly, so they are not exactly equal.) The weekly season makes the difference between a Monday and a Sunday. To forecast next Monday at 11:00, MSTL adds the same two seasons to the trend forecast.
- daily season (24 hours)
- weekly season (168 hours)
Text description of the chart
The chart shows the 168 hours of one week. The daily season, in orange, repeats the same shape seven times: from about -11.9 tickets at night to about +20.4 in the late morning. The weekly season, in blue, is smaller: from -9.7 to +9.8 tickets. On average over each day, it is above 0 from Monday to Thursday and below 0 from Friday to Sunday, lowest on Sunday.
Over the 12 weeks, the daily season explains 76.8% of the variance, and the weekly season 8.7%. The remainder is 11.3%, and the trend only 0.4%. The weekly season is small, but it is exactly what tells Grace’s Monday from her Sunday.
Theta: a trend line and smoothing
Section titled “Theta: a trend line and smoothing”Theta is a second simple method that often does well. It removes one season, combines a straight trend line with an exponential smoothing of the recent values, and puts the season back. AutoTheta from statsforecast chooses the details. We give it the week, 168 hours, which also holds the daily shape.
Larkfield: MSTL and Theta in the ticket backtest
Section titled “Larkfield: MSTL and Theta in the ticket backtest”The course backtest for tickets uses the same 13 origins as for orders, at 23:00, and forecasts 168 hours after each. Each method gets the last 12 weeks of history (2,016 hours): enough for both seasons, and fast to fit. The notebook keeps each method’s 80% range, as q10 and q90:
from statsforecast import StatsForecastfrom statsforecast.models import MSTL, AutoETS, AutoTheta
def with_range(model, keep=2016): def forecaster(train, h, future): sf = StatsForecast(models=[model], freq="h") out = sf.forecast(df=train[["unique_id", "ds", "y"]].tail(keep), h=h, level=[80]) name = str(model) return pd.DataFrame({"unique_id": out["unique_id"], "ds": out["ds"], "yhat": out[name].clip(lower=0), "q10": out[f"{name}-lo-80"].clip(lower=0), "q90": out[f"{name}-hi-80"].clip(lower=0)}) return forecaster
TICKET_ORIGINS = [o + pd.Timedelta(hours=23) for o in ORIGINS]fc_same = bt.backtest(tickets, bt.seasonal_naive(168), h=168, origins=TICKET_ORIGINS)fc_mstl = bt.backtest(tickets, with_range(MSTL(season_length=[24, 168], trend_forecaster=AutoETS(model="ZZN"))), h=168, origins=TICKET_ORIGINS)fc_theta = bt.backtest(tickets, with_range(AutoTheta(season_length=168)), h=168, origins=TICKET_ORIGINS)rows = [bt.score(f, tickets, name, season=168, cost=bt.roster_cost()) for name, f in [("same hour last week", fc_same), ("MSTL", fc_mstl), ("Theta", fc_theta)]]table = bt.show(rows)MSTL(season_length=[24, 168], ...) takes a list: one length per season. AutoETS(model="ZZN") forecasts the trend: Z means “choose”, N means no season, because MSTL already took the seasons out. bt.seasonal_naive(168) is “the same hour last week”. The output (the fit times change from run to run):
method horizon MASE WAPE % bias % pinball fit s cost $ Theta 168 0.883 27.1 0.7 0.15 10.22 3883 MSTL 168 0.919 28.3 1.7 0.067 6.0 4044same hour last week 168 1.036 31.9 3.3 0.03 4888Theta has the lowest error: MASE 0.883 and WAPE 27.1%, against 0.919 and 28.3% for MSTL. Both beat “the same hour last week” (31.9%). The pinball column scores the range; Module 7 explains it. The cost column is the weekly roster cost when Grace staffs exactly to the forecast, with one agent for every 6 tickets. An hour one agent short costs 72 dollars, and an extra agent hour 28. These costs are the course’s assumptions. Theta’s roster is the cheapest: 3,883 dollars a week.
So Theta wins on error and on cost. But is its range right?
Check the range before you plan with it
Section titled “Check the range before you plan with it”An 80% range should hold the real value in about 80% of the hours. The share of hours inside the range is its coverage. A coverage of 0.60 promises a safety that is not there. A coverage of 1.00 means a range too wide to plan with.
| Method | Share of hours inside the 80% range | Share inside the 90% range |
|---|---|---|
| same hour last week | 0.839 | 0.914 |
| MSTL | 0.851 | 0.911 |
| Theta | 0.996 | 1.000 |
Theta’s “80%” range holds the real tickets in 99.6% of the hours: far too wide. Here are the two ranges on Monday 16 March 2026, the first day after the last origin:
- Real tickets
- MSTL, 80% range
- Theta 80% range
Text description of the chart
The chart shows the 24 hours of Monday 16 March 2026. The real tickets are dots: 0 to 4 an hour at night, and up to 39 at 11:00. The MSTL forecast, a blue line, follows the same shape. Its 80% range is narrow: at 12:00, from 19.8 to 29.4 tickets, and 26 tickets came. Theta’s 80% range, two orange dashed lines, is much wider: at 12:00, from 14.5 to 41.3. Over all the hours of the backtest, Theta’s range is 42.3 tickets wide on average, and MSTL’s 14.1.
Why the range matters for the roster
Section titled “Why the range matters for the roster”A short hour (72 dollars) costs more than an extra agent hour (28 dollars). So Grace staffs to a point above the forecast. The tickets stay below that point 72% of the time: 72 ÷ (72 + 28) = 0.72. This point is the 0.72 quantile of the forecast: the 72nd percentile of the mathematics course. From forecast to order and roster explains this rule. At the 72% point of each range, the rosters cost:
Text description of the chart
A column chart with three columns, the weekly roster cost at the 72% point. The same hour last week costs 4,157 dollars. MSTL costs 3,718, the lowest. Theta costs 5,845, the highest. Staffed to the forecast itself, the costs were 4,888, 4,044 and 3,883.
With an honest range, staffing to the 72% point saves money. MSTL goes from 4,044 to 3,718 dollars a week, the cheapest roster of all. With Theta’s range, the 72% point is far above the real need in almost every hour. The method with the lowest error does not give the cheapest decision.
Known events as extra inputs
Section titled “Known events as extra inputs”Larkfield’s Christmas delivery days, from 12 to 23 December, bring more tickets: customers ask if their parcel will arrive in time. Grace knows these dates a year ahead.
An extra input is a column that the model gets for the history and for the days to forecast. Here it is 1 on a delivery day and 0 on other days. MSTL passes extra inputs to its trend forecaster. ETS cannot use them, but AutoARIMA can, so the notebook uses an AutoARIMA trend:
def delivery_days(ds): return ((ds.dt.month == 12) & (ds.dt.day >= 12) & (ds.dt.day <= 23)).astype(float)
o = pd.Timestamp("2025-12-21 23:00")train = tickets[tickets["ds"] <= o].tail(2016).assign(delivery=lambda d: delivery_days(d["ds"]))week = tickets[(tickets["ds"] > o) & (tickets["ds"] <= o + pd.Timedelta(hours=168))].assign(delivery=lambda d: delivery_days(d["ds"]))event = StatsForecast(models=[MSTL(season_length=[24, 168], trend_forecaster=AutoARIMA())], freq="h")f_event = event.forecast(df=train[["unique_id", "ds", "y", "delivery"]], h=168, X_df=week[["unique_id", "ds", "delivery"]])["MSTL"].clip(lower=0).to_numpy()X_df holds the input for the 168 hours to forecast. The notebook compares with the same forecast without the input:
WAPE without the input: 42.2 | with the delivery days: 38.7 real without withds2025-12-22 481 421 4492025-12-23 377 410 4562025-12-24 326 375 3272025-12-25 261 368 3212025-12-26 242 382 3342025-12-27 180 315 2732025-12-28 195 274 231- Real tickets
- MSTL without the input
- MSTL with the delivery days
Text description of the chart
The chart shows seven days, from 22 to 28 December 2025. The real tickets are dots: 481, 377, 326, 261, 242, 180, 195. MSTL without the input is a dashed orange line: 421, 410, 375, 368, 382, 315, 274. MSTL with the delivery-days input is a blue line: 449, 456, 327, 321, 334, 273, 231. With the input, the forecast drops after 23 December, closer to the real tickets.
The input lowers the week’s WAPE from 42.2% to 38.7%. Two honest limits:
- It helps only where the history has examples. The 12 weeks before 21 December hold 10 delivery days. At the other 12 origins, the input is always 0, so it changes nothing.
- It does not beat everything. Theta, with no input, had a WAPE of 32.1% in the same week. An input fixes one known cause; it does not make a weak model strong.
Long series: what the extra detail costs
Section titled “Long series: what the extra detail costs”Hourly data is long: two years are 17,472 hours, against 728 days, and long seasons make some methods slow. Times on a laptop CPU (the two AutoARIMA rows are one fit each, at the last origin):
| Method on the 12 weeks of hourly tickets | Time | Note |
|---|---|---|
| MSTL (24 and 168 hours), 13 origins | about 3 to 6 seconds | both seasons |
| Theta (168 hours), 13 origins | about 10 seconds | one season of 168 |
| AutoARIMA, 24-hour season, one origin | about 72 seconds | daily season only: WAPE 37.4% in that week (MSTL 26.1%, Theta 23.6%) |
| AutoARIMA, 168-hour season, one origin | more than 20 minutes | we stopped it after 20 minutes, with no forecast |
With a 168-hour season, each ARIMA model reaches back 168 hours, and AutoARIMA tries many such models. MSTL avoids this: it takes the seasons out first with smooth curves, and forecasts only a simple trend. For the same reason, every ticket method here uses only the last 12 weeks.
When to use MSTL and Theta, and what they cost
Section titled “When to use MSTL and Theta, and what they cost”Use MSTL when a series has more than one season, such as hourly tickets, calls or electricity use. It is fast, it shows its parts, and its range was close to right. With an AutoARIMA trend, it takes known events as inputs.
Use Theta as a strong, fast point forecast with one season. But check its range before you plan with it.
Do not use them when:
- The history is short: fewer than a few cycles of the longest season.
- The seasons change shape quickly, after a new opening time.
- Events drive the series more than the calendar. Module 5 gives such inputs to a model.
What they cost: seconds of fit time, plus the checks of the range, the inputs and the window of history in the backtest.
Common mistake
The best error, the most expensive roster
Symptom: Tomás reads the ticket table and says: “Theta has the lowest WAPE and the cheapest roster. Use Theta.” Grace staffs to the 72% point of Theta’s range, as she does with every forecast. Her roster costs 5,845 dollars a week, against 3,718 with MSTL. At the 90% point, Theta’s roster would cost 15,042 dollars.
Cause: Theta’s point forecast is good, but its 80% range holds the real tickets in 99.6% of the hours. A plan made from the range puts extra agents in almost every hour.
Fix: check the coverage of every range in the backtest before you plan with it. Use MSTL for the roster here. Or keep Theta’s point forecast and build a new range from its backtest errors: Module 7 shows how.
Consequence in AI work: a decision often uses more than the point forecast. Score the model on what the decision uses. A leaderboard of point errors can pick the model that costs the most.
Guided practice: two seasons in the notebook
Section titled “Guided practice: two seasons in the notebook”- Open the notebook from the box Do this lesson in a notebook at the top of this page.
- Run the setup cells and the helper cell. The data cell ends with the
Ready:line. - In section 1, predict which pattern is larger: the day or the week. Then run the cell.
- In section 2, run the MSTL cell and the chart. You see the share of each part.
- In section 3, predict which method has the lower WAPE. Then run the backtest. It takes about 20 seconds.
- In section 4, compute Theta’s coverage in the Your turn cell, and run the check cell. It prints
Check passed. - In section 5, run the roster cell. You see 3,718 dollars for MSTL.
- In section 6, predict the effect of the delivery days. Then run the cell.
Your turn: is Theta’s range right?
Section titled “Your turn: is Theta’s range right?”fc_theta holds every Theta forecast of the ticket backtest, with the real tickets y and the 80% range q10 to q90. Before you compute anything, predict: in what share of the hours is the real value inside the range? Compute the share of hours where q10 <= y <= q90, rounded to 3 decimals, and put it in theta_coverage.
Show the answer
inside = (fc_theta["y"] >= fc_theta["q10"]) & (fc_theta["y"] <= fc_theta["q90"])theta_coverage = round(float(inside.mean()), 3)mstl_coverage = round(float(((fc_mstl["y"] >= fc_mstl["q10"]) & (fc_mstl["y"] <= fc_mstl["q90"])).mean()), 3)print("Theta", theta_coverage, "| MSTL", mstl_coverage)Theta 0.996 | MSTL 0.851Theta’s 80% range holds 99.6% of the hours: far too wide. MSTL’s holds 85.1%: a little wide, close to right. These are the same values as in the course table, because bt.coverage() uses the same rule.
Knowledge check
Section titled “Knowledge check”Check your understanding
MSTL's parts for Monday 9 March 2026 at 11:00 are given in the table of this lesson. Why are the daily seasons of Monday 11:00 and Sunday 11:00 almost the same, and which part makes the two hours different?
Show the answer
The daily season has one value for each hour of the day, repeated every 24 hours. Both hours are 11:00, so they get almost the same daily season (18.3 and 18.0; MSTL lets it change slowly). The weekly season has one value for each of the 168 hours of the week, so it differs between a Monday and a Sunday. At 11:00, it is +9.8 on Monday and −9.7 on Sunday. The trend changes only slowly, and the remainder is noise.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Check your understanding
Theta has a WAPE of 27.1% on tickets and MSTL 28.3%. Grace staffs to the 72% point of the range. Which method do you recommend for her roster, and why?
Show the answer
MSTL. Grace’s decision uses the range, not only the forecast. MSTL’s 80% range holds the real tickets in 85.1% of the hours, close to right. Theta’s holds them in 99.6%: far too wide. At the 72% point, MSTL’s roster costs 3,718 dollars a week, the cheapest of all methods, and Theta’s 5,845. The lower WAPE of Theta does not make up for its wrong range.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Check your understanding
Tomás adds a 'Christmas delivery days' input to MSTL and runs the whole ticket backtest. The WAPE changes at only one of the 13 origins. Is the input useless?
Show the answer
No. The input is 1 only from 12 to 23 December. Only the origin of 21 December 2025 has delivery days in its 12 weeks of history and in its forecast week. At the other origins, the input is always 0, so it cannot change anything. At that origin, it lowered the WAPE from 42.2% to 38.7%. An input helps only in the weeks it describes, and only if the history has examples of it. To judge it, look at the weeks with the event, not at the average of all weeks.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Recap
- Hourly tickets have two seasons: 24 hours and 168 hours. ETS with one 24-hour season forecast 243 tickets on every day of a week that went from 473 to 243.
- MSTL splits the series into a trend, one part per season and a remainder, forecasts the trend and adds the seasons back. Here the daily season explains 76.8% of the variance, the weekly season 8.7%.
- Theta combines a trend line and exponential smoothing on the series without its season.
- In the ticket backtest, Theta has the lowest error (WAPE 27.1%) but a range that is far too wide (coverage 0.996). MSTL’s range is close to right (0.851), and it gives the cheapest roster at the 72% point: 3,718 dollars a week.
- A known event as an input (the Christmas delivery days) lowered the WAPE of that week from 42.2% to 38.7%. It helps only where the history has examples.
- Long seasons make seasonal ARIMA slow; MSTL avoids this. Every ticket method uses the last 12 weeks.
You can now forecast a series with several seasons and check its range before you plan with it. Every method so far learns from one series at a time, from its own past. Next, Module 5 turns forecasting into a regression problem: one model learns from all products at once, with prices, promotions and the calendar as inputs.