Breaks and changes
- Lesson 21
- 30 min
- Module 6: Hard series and many series
Where we are
We forecast new products from what others did. Old products change too: a price rise moves the level for good, and the old history may then mislead a model. In this lesson, we find the break and test whether a shorter training window helps.
Lesson 21 of 27 · Forecasting and Time Series: Predict What Comes NextBreaks and changes
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
Find a lasting change in a series, and decide what the forecast should learn from the time before it. A price rise moves a product’s level for good. A model that weighs all days the same keeps forecasting the old level. You test whether a shorter training window fixes this, and you find that ETS does not need it.
NotebookDo this lesson in a notebook
The notebook has every code cell, task and check of this lesson. It compares a mean with a smoothed level after a change. It measures the garden hose before and after its price rise, tries a simple alarm rule, and fits ETS on two training windows. Its setup cells install the packages and download the Larkfield data, so it needs no local setup. About 30 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 smoothing weight alpha, from Exponential smoothing.
- WAPE and bias, from Measure the error that matters.
- The yearly season of garden products, from Trend, season and noise.
What you need on your computer
Nothing: the notebook runs in Colab or Kaggle.
Tested with Python 3.12, pandas 2.3.3 and statsforecast 2.1.1, in Jupyter on macOS.
The bus that changed its timetable
Section titled “The bus that changed its timetable”You take the same bus every morning. For a year, it came at 8:10. In June, the company changed the timetable: now it comes at 8:25. If you plan with the average of all your mornings, you arrive at 8:11 every day and wait 14 minutes. The old mornings are true, but they describe a world that is gone.
Two fixes are natural. You can forget the old mornings and use only the mornings since June. Or you can give new mornings more weight, so that the old ones fade by themselves. This lesson tests both on a real change at Larkfield.
The problem: a level that moves for good
Section titled “The problem: a level that moves for good”On Monday 2 June 2025, the supplier raised the price of the garden hose P077, from 24.99 to 31.99 dollars. Larkfield records the change in price_changes.csv:
product_id date new_price reason P077 2025-06-02 31.99 supplier price rise2025: 8 weeks before 126.9 | 8 weeks after 79.82024: 8 weeks before 106.4 | 8 weeks after 117.8The hose sold 126.9 units a week in the 8 weeks before the rise, and 79.8 in the 8 weeks after. That is 37% less. Is this the end of spring? The same weeks one year before say no: in 2024, June sold more than spring (117.8 against 106.4).
- Weeks from 1 April 2024
- Weeks from 31 March 2025 (price rise on 2 June)
Text description of the chart
The chart shows the garden hose’s units sold per week from April to September, for two years. The 2024 line, dashed, stays between about 70 and 160 units a week. The 2025 line is mostly above it in April and May, with weeks of 93 to 163. In the week of 2 June 2025, the price rise, it falls to 90, then 61. From June to September 2025, it stays between about 60 and 96 units a week, below the 2024 line in every week.
A change like this is a break, or a level shift: the series moves to a new level and stays there. It is not an outlier (one strange day) and not a season (a change that comes back every year). Other causes of breaks: a new sales channel, a competitor, a product that moves to a new page of the website.
A break harms a forecast that learns from all the history in the same way. Its old days pull the forecast toward the old level.
Find the change
Section titled “Find the change”At Larkfield, this break is easy to find: the price change is in a table. Read the planned changes first, before any statistics. Kenji knows about prices, suppliers and new channels long before the data shows them.
Breaks without a record are harder. Priya tries a simple rule. It raises an alarm when a week sells less than 75% of the mean of the 8 weeks before it, two weeks in a row.
ratio = weeks / weeks.rolling(8).mean().shift(1)low = ratio < 0.75fires = ratio.index[low & low.shift(1, fill_value=False)]alarm in the weeks that end on: ['2024-10-27', '2024-11-03', '2024-11-10', '2025-01-19', '2025-06-15', '2025-06-22', '2026-01-04']The rule finds the price rise (the weeks that end on 15 and 22 June 2025). But five of its seven alarms are the end of the garden season in autumn and the quiet weeks after Christmas. A level rule cannot tell a season from a break. Two better checks:
- Compare with the same weeks last year, as above: −37% against +11% one year before.
- Use a change-point method that models the season first. Finding unusual points and change points in many series is the subject of the anomaly detection course.
The idea: a shorter window, or a model that forgets
Section titled “The idea: a shorter window, or a model that forgets”Once you know the date of a break, there are two ways to stop the old days from misleading the forecast.
- A shorter training window: train only on the days since the break. Simple and clear. But it throws away information that is still true, like the weekly pattern.
- A model that forgets by itself: give new days more weight than old ones. ETS does this: its smoothing weight alpha is the share of the newest day in the level. With an alpha of 0.3, each new day pulls the level 30% of the way toward it.
A tiny example
Section titled “A tiny example”A product sold 20 units a day for 10 days. Then its price rose, and it sold 12 a day for 5 days.
| Forecast for tomorrow | How | Value |
|---|---|---|
| Mean of all 15 days | (10 × 20 + 5 × 12) ÷ 15 | 17.3 |
| Mean since the change | (5 × 12) ÷ 5 | 12.0 |
| Smoothed level, alpha 0.3 | after 5 new days, the old level keeps 0.7⁵ = 0.168 of the weight: 12 + 0.168 × (20 − 12) | 13.3 |
mean of all days: 17.3 | mean since the change: 12.0 | smoothed level: 13.3 | weight left on the old level: 0.168The mean of all days needs the shorter window badly. The smoothed level forgets the old days by itself. After 5 days, they keep 16.8% of the weight. After 10 days, they keep only 2.8%.
Larkfield: two windows for the garden hose
Section titled “Larkfield: two windows for the garden hose”Priya fits ETS twice at three cut-offs (forecast origins) after the rise: on all the history, and only on the days since 2 June. She uses statsforecast’s AutoETS, which chooses its own model. Each forecast covers 14 days.
Text description of the diagram
The diagram is a timeline from 1 April 2024 to the end of July 2025. A dashed line marks the price rise on 2 June 2025. The first bar, all history, runs 469 days from 1 April 2024 to the cut-off on 13 July 2025; from it, ETS chose a model with a weekly pattern and an alpha of 0.16, with a WAPE of 23.4% on the next 14 days. The second bar, since the price rise, runs 42 days from 2 June to 13 July 2025; from it, ETS chose no weekly pattern, almost a flat average, with a WAPE of 24.6%. Both bars end with a 14-day test, from 14 to 27 July 2025. A note says that with alpha 0.16, the newest day gets 16% of the weight, and after the 42 days since the rise, the level before the rise keeps about 0.1% of the weight.
The notebook’s table:
origin window days model alpha WAPE % bias %2025-07-13 all history 469 ETS(A,N,A) 0.1563 23.4 -2.92025-07-13 since the rise 42 ETS(A,N,N) 0.0001 24.6 1.22025-08-10 all history 497 ETS(A,N,A) 0.1534 15.9 -8.22025-08-10 since the rise 70 ETS(A,N,N) 0.0001 17.2 9.12025-09-07 all history 525 ETS(A,N,A) 0.1501 26.4 -9.42025-09-07 since the rise 98 ETS(M,N,M) 0.0001 27.7 -14.2The model column is ETS’s short name. The last letter says if it has a weekly pattern: A or M means yes, N means no.
- All history
- Since the price rise
Text description of the chart
A column chart with three pairs of columns, one pair per cut-off. 13 July 2025: all history 23.4%, since the rise 24.6%. 10 August: all history 15.9%, since the rise 17.2%. 7 September: all history 26.4%, since the rise 27.7%.
The shorter window did not help. It was worse at all three cut-offs. Two reasons:
- ETS had already forgotten. On all the history, its alpha was about 0.15. After the 42 days from the rise to the first cut-off, the old level keeps (1 − 0.1563)⁴² ≈ 0.0008 of the weight. That is less than 0.1%.
- The short window lost the weekly pattern. With 42 or 70 days,
AutoETSchose no weekly pattern, and a flat level (alpha 0.0001). The days since the rise were too few to show it a pattern it could trust.
This chart shows the first cut-off, day by day:
- Hoses sold per day
- ETS on all history (153 in 14 days)
- ETS since the rise (160 in 14 days)
Text description of the chart
The chart shows 14 days, from 14 to 27 July 2025. The real sales are dots between 4 and 18 hoses a day: 158 in total. ETS on all the history forecasts between 8.8 and 14.6 a day, highest on Saturday, 153 in total. ETS on the days since the rise forecasts 11.4 every day, 160 in total. Both forecasts are close to the new level; neither is near the old level of about 18 a day.
When a shorter window does help
Section titled “When a shorter window does help”A shorter window helps a method that weighs all days the same. Priya tried it with the plainest such method, the mean of the window:
| Cut-off | Sold in 14 days | Mean of all history | Mean since the rise |
|---|---|---|---|
| 13 Jul 2025 | 158 | 13.4 a day, WAPE 29.4% | 11.4 a day, WAPE 24.6% |
| 10 Aug 2025 | 142 | 13.3 a day, WAPE 31.7% | 11.1 a day, WAPE 17.2% |
| 7 Sep 2025 | 181 | 13.1 a day, WAPE 21.5% | 11.1 a day, WAPE 25.7% |
For the mean, the short window wins at two of three cut-offs, by up to 14.5 points. At the third, the season pushed the sales up again. So shorten the window for methods with a long memory. Examples are a mean, a long moving average, or a regression that fits one level to all the data. For ETS and other methods with a smoothing weight, first check how much the old days still count.
When to act on a break, and what it costs
Section titled “When to act on a break, and what it costs”Act when the change is lasting and large compared with the noise: a price change, a new channel, a lost customer. Do not act on one strange week; that may be an outlier or the season.
The costs:
- A shorter window throws away true information: here, the weekly pattern. The fewer the days, the noisier the model.
- A window per product needs a date per product, and someone to keep the dates. A table of planned changes, like
price_changes.csv, is the cheapest source. - A break also changes the backtest. Score the forecast only on days after the break, or the old level flatters or harms it.
A different fix keeps the whole history: give the model the price as an input, as the regression of Forecasting as regression did. Then it can learn what a price rise does. This works when prices change often enough to learn from, and Larkfield’s history has only three price changes, each on a different product.
Common mistake
A cure the model did not need
Symptom: after the price rise, Tomás sets every forecast at Larkfield to train only on the data since the last price change. For the garden hose, ETS gets worse at all three cut-offs: 24.6% instead of 23.4% at the first.
Cause: ETS already gave the old days almost no weight (alpha 0.16: the old level kept less than 0.1% after 42 days). The short window only took away the days that taught ETS the weekly pattern.
Fix: check what the method remembers before you cut its history. Test the short window in a backtest on the days after the break, against the full history. Keep it only where it wins: here, for the mean of the window, not for ETS.
Consequence in AI work: a fix that sounds obvious can make a forecast worse, and nobody notices without a test. Every change to the training data is a change to the model; backtest it like one.
Guided practice: a break in the notebook
Section titled “Guided practice: a break 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. The data cell ends with the
Ready:line. - In section 1, predict which forecast is closer to 12. Then run the cell. You see
smoothed level: 13.3. - In section 2, run the cell. You see the price change and the weekly means
126.9and79.8. - In section 3, predict if the rule fires only in June 2025. Run the cell. You see seven weeks.
- In section 4, predict which window gives the lower WAPE. Run the cell. You see six rows.
- In section 5, write your answer in the Your turn cell, then run the check cell.
Your turn: how much does the old level still count?
Section titled “Your turn: how much does the old level still count?”Before you run it, predict: after 42 days with an alpha of about 0.16, does the old level keep more or less than 1% of the weight? In the notebook, section 5, take the alpha of the all-history ETS at the first cut-off. Compute (1 − alpha) to the power 42, and put it in old_weight, rounded to 4 decimals.
Show the answer
alpha = ets.loc[0, "alpha"]old_weight = round(float((1 - alpha) ** 42), 4)print(alpha, old_weight)0.1563 0.0008Less than 0.1%. After six weeks, ETS has practically forgotten the level before the price rise. The forecast at the new level comes from the model itself, not from a shorter window.
Knowledge check
Section titled “Knowledge check”Check your understanding
How do you know that the garden hose's drop in June 2025 is a break and not the season? Use the numbers.
Show the answer
The price change is recorded: 24.99 to 31.99 dollars on 2 June 2025. The hose sold 126.9 units a week in the 8 weeks before and 79.8 in the 8 weeks after, 37% less. In the same weeks one year before, without a price change, June sold more than spring: 117.8 against 106.4. So the season alone would have raised sales. The drop stayed below the previous year’s level all summer, so it is a lasting change of level: a break.
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
Why did a training window since the price rise make ETS worse, and for which kind of method would it help?
Show the answer
ETS on all the history had an alpha of about 0.15. After the 42 days from the rise to the first cut-off, the old level kept about 0.0008 of the weight. So ETS was already at the new level. The short window gave AutoETS only 42 to 98 days. It chose no weekly pattern at two cut-offs and a flat level at all three. It was worse by 1.2 to 1.3 points. A short window helps a method that weighs all days the same. The mean of the window improved from 29.4% to 24.6% and from 31.7% to 17.2%, at two of three cut-offs.
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
Predict: Larkfield starts selling through a large marketplace next month, and Grace expects many more tickets. What would you do with the ticket forecast before and after the start?
Show the answer
Before the start, write the date and the expected change in a table of planned changes, as Larkfield does for prices. After the start, compare the weekly tickets with the same weeks last year, not with the weeks just before. Then the season is not mistaken for the break. Then check what the ticket model remembers. A model with a smoothing weight may adapt within a few weeks by itself. A model with a long memory needs a window that starts at the break. Backtest both versions only on the weeks after the start before choosing. If more channels are planned, a channel input may be better than cutting the history.
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
- A break (level shift) moves a series to a new level for good. The garden hose fell from 126.9 to 79.8 units a week after its price rise. In the same weeks of 2024, sales rose.
- Find it from the planned changes first, then by comparing with last year. A simple level rule also fired on 5 season changes; change-point methods are in the anomaly detection course.
- A shorter window helps methods that weigh all days the same: the mean improved at two of three cut-offs.
- It did not help ETS: worse at all three cut-offs (24.6% against 23.4% at the first). ETS had already forgotten the old level (alpha 0.16), and the short window lost the weekly pattern.
- Test every change to the training data in a backtest on the days after the break.
This module made hard series workable: hierarchies, slow sellers, new products and breaks. But every order so far came from one number per day. Next, you order from the forecast’s range, because Kenji’s order depends on how wrong the forecast can be.
Next: A forecast is a range