Exponential smoothing (ETS, Holt-Winters)
- Lesson 11
- 40 min
- Module 4: Statistical forecasters
Where we are
The backtest table has its first rows: the naive forecasts. They give every past day the same weight, or only the last one. In this lesson, we meet exponential smoothing, where recent days count more, and we add a trend and a season to it.
Lesson 11 of 27 · Forecasting and Time Series: Predict What Comes NextExponential smoothing (ETS, Holt-Winters)
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
Make a forecast where recent days count more than old days, and add a weekly season to it. This is exponential smoothing (ETS). It beats every naive forecast in the backtest table, and it fits 50 products in under a minute.
NotebookDo this lesson in a notebook
The notebook has every code cell, task and check of this lesson. It computes the fading weights and fits ETS to the parasol. Then it runs ETS in the course backtest and compares it with the moving average, product by product. Last, it shows what ETS does with two seasons. Its setup cells install the packages and download the Larkfield data, so it needs no local setup. About 40 minutes, with about 1 minute of waiting.
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
- The four naive forecasts and the moving average’s window, from Naive forecasts.
- The course backtest (13 origins, 14 days), from Test like the future: backtesting.
- WAPE, MASE, bias and the cost column of the backtest table, from Measure the error that matters.
- Trend and season, 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 you guess your travel time
Section titled “How you guess your travel time”Think about your trip to work. How long will it take tomorrow? You do not take the mean of every trip of the last year. You also do not copy only today’s trip. You think: “This week it took about 35 minutes. Last month it was nearer 30, but the road works started since then.”
So yesterday’s trip counts most. Last week’s trips count a little less. Trips from months ago count almost nothing, but they are not forgotten. Your memory fades. That is the idea of this lesson.
The problem: two baselines, two different mistakes
Section titled “The problem: two baselines, two different mistakes”In the last module, two baselines did best, each in its own way:
- The 28-day moving average had the lowest WAPE, 43.5%. But it gives the same weight to every one of its 28 days, and no weight at all to day 29. It also gives the same number for every day ahead, so it forgets the weekly season.
- The seasonal naive forecast (the same weekday last week) follows the weekly season. But it copies one single week, with all of its accidents. Its WAPE was 51.3%.
Kenji, the stock planner, wants both at once: “Use many days, so that one strange day does not fool you. Count the recent days more. And remember that Saturdays sell more than Wednesdays.”
The idea: weights that fade into the past
Section titled “The idea: weights that fade into the past”Simple exponential smoothing keeps one number, the level: the forecaster’s best guess of a normal day now. Every day, it moves the level a part of the way toward the new value. The part is the smoothing value α (say “alpha”), between 0 and 1:
- new level = old level + α × (today’s value − old level)
The forecast for every day ahead is the last level. “Exponential” means that the weight of a past day shrinks by the same factor, 1 − α, every day back. “Smoothing” means that the noise is averaged away.
A tiny example
Section titled “A tiny example”A product sold 10, 12, 9, 15 and 11 units in five days. Take α = 0.3 and start the level at the first value, 10. Work out each step:
| Day | Sold | Level before | Miss (sold − level) | Level after = before + 0.3 × miss |
|---|---|---|---|---|
| 1 | 10 | 10.00 (the start) | ||
| 2 | 12 | 10.00 | +2.00 | 10.60 |
| 3 | 9 | 10.60 | −1.60 | 10.12 |
| 4 | 15 | 10.12 | +4.88 | 11.58 |
| 5 | 11 | 11.58 | −0.58 | 11.41 |
The forecast for day 6, and for every day after it, is 11.41. statsforecast’s SimpleExponentialSmoothing(alpha=0.3) gives the same 11.41 on these five days.
Day 4 sold 15, but the level only moved to 11.58. One busy day moves the forecast only 30% of the way.
The weights, day by day
Section titled “The weights, day by day”Write the level out, and each past day gets a weight: α for yesterday, α × (1 − α) for the day before, then α × (1 − α)², and so on. With α = 0.3, the weights are 0.3, 0.21, 0.147, 0.103 and 0.072. The last 7 days get 0.918 of the weight together.
- α = 0.6
- α = 0.3
- α = 0.1
- moving average (28 days)
Text description of the chart
The chart shows the weight of each past day, from yesterday (day 1) to 28 days back. With α = 0.6, yesterday gets 0.6, the day before 0.24, and the weights are almost 0 after 6 days. The last 7 days get 0.998 of the weight. With α = 0.3, the weights start at 0.3 and fall to almost 0 after about 14 days. The last 7 days get 0.918. With α = 0.1, the weights start at 0.1 and fall slowly, to 0.006 on day 28. The last 7 days get 0.522. The 28-day moving average is a flat dashed line at 0.036 for all 28 days.
A large α (0.6) follows changes fast, but it also follows the noise. A small α (0.1) averages many days, but it reacts late when the level really changes. The forecaster finds the α that fits the series best, as you see below.
Add a trend and a season
Section titled “Add a trend and a season”The level alone gives a flat forecast. Two more parts fix this, each with its own smoothing value:
- Holt’s method adds a trend: how much the level grows or falls per day. The forecast becomes a sloped line.
- Holt-Winters also adds a season: how much each weekday is above or below the level. The forecast goes up on Saturdays and down on Wednesdays.
The whole family is called ETS: Error, Trend and Season. Each part can be absent (N, for none), added (A) or multiplied (M). “Multiplied” means that the part grows with the level: a season of +20% instead of +5 units. An ETS model is named with three letters, such as ETS(A,N,A).
Let statsforecast choose the model
Section titled “Let statsforecast choose the model”You do not need to choose the letters yourself. AutoETS from statsforecast fits the possible models and keeps the one with the best AICc. AICc is a fit score: it rewards a model that fits the history closely, and it punishes each extra part. So a trend is kept only if it helps more than it costs.
In the notebook, Priya fits AutoETS to the parasol’s sales up to Sunday 22 June 2025, the week before the heat wave:
from statsforecast import StatsForecastfrom statsforecast.models import AutoETS
parasol = load_sales(["P025"])origin = pd.Timestamp("2025-06-22")train = parasol[parasol["ds"] <= origin][["unique_id", "ds", "y"]]sf = StatsForecast(models=[AutoETS(season_length=7)], freq="D")fc = sf.forecast(df=train, h=14)sf.fit(train)print("model chosen:", sf.fitted_[0, 0].model_["method"])real = parasol[(parasol["ds"] > origin) & (parasol["ds"] <= origin + pd.Timedelta(days=14))]print("14-day total: ETS", round(fc["AutoETS"].sum(), 1), "| real", int(real["y"].sum()))season_length=7 tells it that the season repeats every 7 days. The output:
model chosen: ETS(A,N,A)14-day total: ETS 176.3 | real 197Text description of the diagram
The diagram has three columns. Error, A: added, so misses go up and down by about the same number of units. Trend, N: none. Season, in orange, A: added, so each weekday adds or takes away some units. A note says that each letter is N (none), A (added) or M (multiplied), and that AutoETS keeps the best model.
For the parasol, AutoETS also chose its smoothing values: α = 0.41 for the level, and 0.08 for the season. So the level moves 41% of the way to each new day, and the weekly pattern changes only slowly.
- Sold
- ETS
- seasonal naive
Text description of the chart
The chart shows the parasol’s daily sales from 12 May to 22 June 2025 as a grey line, mostly between 1 and 25 a day. After the origin, the real sales are grey dots: 50 in the first week, 147 in the heat-wave week. The ETS forecast is a smooth blue line that repeats the same week twice. It is between 10.7 and 15.5 units a day, 176.3 units in total. The seasonal naive forecast is a dashed orange line that repeats the last week twice. It is between 3 and 20 a day, 134 units in total. Both stay far below the heat-wave week.
ETS forecasts 176.3 parasols, closer to the real 197 than every naive forecast. But it is still too low, for the same reason: the heat wave was not in the parasol’s past.
Larkfield: ETS in the course backtest
Section titled “Larkfield: ETS in the course backtest”The notebook runs AutoETS at the 13 origins of the course backtest, for the 50 products: 650 fits. The forecaster is a small function that returns the column yhat, as backtest.py expects:
def ets(train, h, future): sf = StatsForecast(models=[AutoETS(season_length=7)], freq="D") out = sf.forecast(df=train[["unique_id", "ds", "y"]], h=h) return out.rename(columns={"AutoETS": "yhat"}).assign(yhat=lambda d: d["yhat"].clip(lower=0))
sales = load_sales(BACKTEST_PRODUCTS)fc_ets = bt.backtest(sales, ets, h=14, origins=ORIGINS)fc_snaive = bt.backtest(sales, bt.seasonal_naive(7), h=14, origins=ORIGINS)fc_ma = bt.backtest(sales, bt.moving_average(28), h=14, origins=ORIGINS)rows = [bt.score(f, sales, name, season=7, cost=bt.stock_cost(PRICES)) for name, f in [("seasonal naive", fc_snaive), ("moving average (28 days)", fc_ma), ("ETS (AutoETS)", fc_ets)]]table = bt.show(rows)clip(lower=0) turns a negative forecast into 0: a shop cannot sell −2 parasols. The output (the fit times change from run to run):
method horizon MASE WAPE % bias % pinball fit s cost $ ETS (AutoETS) 14 0.832 41.3 0.1 53.69 16578moving average (28 days) 14 0.875 43.5 -0.1 0.04 19444 seasonal naive 14 1.034 51.3 -0.5 0.04 16739ETS is the new best row of the table. Its MASE is 0.832 and its WAPE 41.3%, against 0.875 and 43.5% for the moving average. Its bias is +0.1%, so it is not too high or too low on average. Its order cost, 16,578 dollars, is a little below the seasonal naive’s 16,739 and far below the moving average’s 19,444. It is the first method of the course that is good on error and on cost.
The fit took about 54 seconds for 650 fits in this run, and 46 seconds in the course’s own measurement. That is much more than the naive methods, and still very little.
The parasol at every origin
Section titled “The parasol at every origin”The explorer shows the parasol at the 13 origins of the backtest. Choose ETS and the moving average, and move the origin.
Explore
ETS and the baselines on the parasol
Predict first: On the parasol, will ETS beat the 28-day moving average over all 13 origins?
- Sold in the 14 days
- 101
- Forecast for the 14 days
- 92
- WAPE at this origin
- 45.5%
- WAPE, all 13 origins
- 65.1%
At the origin 8 Jun 2025, ETS forecasts 92 units for the next 14 days. 101 were sold. Its WAPE here is 45.5%: it is too low. Over all 13 origins, ETS has a WAPE of 65.1%: number 2 of 5 methods. It beats the baseline, seasonal naive (66.1%).
- Units sold
- Forecast of the chosen method
- Baseline: seasonal naive
Show every method, ranked
| Rank | Method | Family | WAPE at this origin | WAPE, all 13 origins |
|---|---|---|---|---|
| 1 | moving average (28 days) | baseline | 101.3% | 64.9% |
| 2 | ETS | statistical | 45.5% | 65.1% |
| 3 | seasonal naive | baseline | 74.3% | 66.1% |
| 4 | naive | baseline | 50.5% | 90.9% |
| 5 | drift | baseline | 50.3% | 92.5% |
Text description of the explorer
The explorer shows the parasol’s daily sales. The four weeks before the chosen origin are a grey line, and the 14 days after it are grey dots. The chosen method’s forecast is a blue line, and the seasonal naive forecast a dashed orange line. The controls choose the origin and one of five methods: naive, seasonal naive, the 28-day moving average, drift and ETS. The readout shows the units sold, the forecast and the WAPE. At the origin of 8 June 2025, 101 parasols were sold and ETS forecast 92. The WAPE over all 13 origins is 64.9% for the moving average (28 days) and 65.1% for ETS. It is 66.1% for seasonal naive, 90.9% for naive and 92.5% for drift.
On the parasol, ETS (65.1%) and the moving average (64.9%) are almost the same. The parasol’s sales change with the weather, and a model of its own past cannot know the weather. Over 50 products, ETS wins clearly. On one hard product, it does not.
Product by product
Section titled “Product by product”The table adds up all 50 products. Per product, the result is:
- Against the seasonal naive forecast, ETS wins on 50 of the 50 products. ETS keeps the weekly season, but it averages many weeks instead of copying one.
- Against the 28-day moving average, ETS wins on 33 of 50. The moving average wins on 17.
We looked for a simple rule for those 17 products, and did not find one. They are not slower sellers: the median product sells 5.8 units a day, against 5.9 where ETS wins. Their weekly pattern is only a little weaker: on a median product, a weekday differs from the weekly mean by 7.2%, against 8.3%. A likely reason: when the weekly pattern is weak and the noise is large, the season that ETS estimates is partly noise. Then a flat mean does as well. The backtest, not a rule, tells you which products these are.
When to use ETS, and what it costs
Section titled “When to use ETS, and what it costs”Use ETS as the first model after the baselines. It is fast, it needs only the series itself, and its parts (level, trend, season) can be explained to Kenji in a sentence each. It is a strong default for daily or weekly business series with one season.
Know its limits:
- One season only. ETS takes one
season_length. Hourly tickets have a daily and a weekly season. The failure case below shows what happens. Several seasons and long series fixes it. - Only the series’ own past. ETS cannot use a planned promotion, a holiday or the weather. Module 5 adds them as inputs.
- Short histories. A weekly season needs several weeks of history before the season part means anything. A new product with two weeks of sales gets a poor season. Module 6 handles new products.
- Its range assumes normal errors. ETS also gives a range around its forecast. An 80% range should hold the real value 8 times out of 10. On the 50 products, it held the real value 83.5% of the time: close, but Module 7 checks this properly.
What it costs: about 46 seconds for 650 fits on a laptop. The forecasting job in Module 8 fixes the model to ETS(A,N,A), so AutoETS does not search. Then it fits 600 series in about 5 seconds instead of 40.
Common mistake
One season only: ETS on hourly tickets
Symptom: Grace, the support lead, asks for next week’s tickets per hour. Priya fits AutoETS with a daily season (24 hours) to the last 12 weeks of hourly tickets, and forecasts the last week of the history. Added up per day, the forecast and the real tickets are:
| Day | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
|---|---|---|---|---|---|---|---|
| Real tickets | 473 | 474 | 393 | 409 | 294 | 337 | 243 |
| ETS forecast | 243 | 243 | 243 | 243 | 243 | 243 | 243 |
The forecast is the same 243 tickets every day. The real tickets fall from 473 on Monday to 243 on Sunday.
Cause: a daily season repeats the same 24 hours seven times. The model cannot know that Monday is busy and Sunday is quiet. Here it repeats the level of the last day of the history, a quiet Sunday, for the whole week. With season_length=168 (one week of hours) instead, ETS follows the week (381 tickets on Monday, 226 on Sunday). But then it learns each hour of the week from only 12 examples in 12 weeks.
Fix: use a method that takes several seasons, such as MSTL, in Several seasons and long series.
Consequence in AI work: a model’s options limit what it can learn, whatever the data says. Before you compare models, check that each one can represent the patterns you already see in the series. Otherwise you compare a model with a handicap.
Guided practice: ETS in the notebook
Section titled “Guided practice: ETS 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 how much weight the last 7 days get with α = 0.3. Then run the cell. You see
0.918. - In section 2, run the parasol cell. You see
model chosen: ETS(A,N,A)andreal 197. - In section 3, predict if ETS beats the moving average. Then run the backtest cell. It takes about a minute.
- In section 4, write the product-by-product count in the Your turn cell, and run it.
- Run the check cell. It prints
Check passed. - In section 5, run the hourly tickets cell. You see the same 243 tickets on every day.
Your turn: ETS against the moving average, product by product
Section titled “Your turn: ETS against the moving average, product by product”fc_ets and fc_ma hold every forecast of ETS and of the 28-day moving average, with the real value y. Before you compute anything, predict: on how many of the 50 products does ETS have the smaller error? For each product, add up the absolute errors of each method over all origins and days. Count the products where the ETS sum is smaller, and put the count in ets_wins.
Show the answer
e_ets = (fc_ets["y"] - fc_ets["yhat"]).abs().groupby(fc_ets["unique_id"]).sum()e_ma = (fc_ma["y"] - fc_ma["yhat"]).abs().groupby(fc_ma["unique_id"]).sum()ets_wins = int((e_ets < e_ma).sum())print(ets_wins, "of", len(e_ets))33 of 50ETS wins on 33 products, and the moving average on 17. The sum of the absolute errors is each product’s WAPE without the division. Both methods divide by the same sales, so the division does not change the winner.
Knowledge check
Section titled “Knowledge check”Check your understanding
With α = 0.3, the level is 10.60 and the product sells 9 units today. What is the new level, and what is the forecast for the next three days?
Show the answer
The miss is 9 − 10.60 = −1.60. The new level is 10.60 + 0.3 × (−1.60) = 10.60 − 0.48 = 10.12. Simple exponential smoothing forecasts the last level for every day: 10.12, 10.12 and 10.12. A trend (Holt) or a season (Holt-Winters) would make the days differ.
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
AutoETS chose ETS(A,N,A) for the parasol. What does each letter mean, and why can the model still not forecast the heat wave?
Show the answer
- A (error): the misses are added; they go up and down by about the same number of units.
- N (trend): no trend; the level does not grow or fall steadily.
- A (season): an added weekly season; each weekday adds or takes away some units.
ETS learns only from the parasol’s own past sales. The heat wave came from the weather, which is not in the model. So it forecast 176.3 parasols for the two weeks, and 197 were sold.
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
Use the backtest table and the product-by-product counts. On which of Larkfield's 50 products did ETS beat the seasonal naive forecast, on which did it not, and why?
Show the answer
ETS beat the seasonal naive forecast on all 50 products: MASE 0.832 against 1.034, WAPE 41.3% against 51.3%. The seasonal naive forecast copies one single week, with its noise and accidents. ETS also follows the weekly season, but it averages it over many weeks with weights that fade. Against the 28-day moving average, ETS won on 33 products and lost on 17. We found no simple rule for these 17 products: they are not slower sellers. A likely reason is a weak weekly pattern and much noise. Then the season that ETS estimates is partly noise, and a flat 28-day mean does as well.
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
- Exponential smoothing keeps a level and moves it a part α of the way to each new value. The weights of past days fade: with α = 0.3, the last 7 days get 0.918 of the weight.
- Holt adds a trend, Holt-Winters adds a season. The family is ETS (error, trend, season), each part none (N), added (A) or multiplied (M).
- AutoETS chooses the model by its AICc fit score. For the parasol, it chose ETS(A,N,A) with α = 0.41.
- In the course backtest, ETS has MASE 0.832, WAPE 41.3% and a cost of 16,578 dollars. It is the best row so far, and it took about 46 seconds for 650 fits.
- ETS beats the seasonal naive forecast on 50 of 50 products, and the 28-day moving average on 33 of 50.
- ETS takes one season only. On hourly tickets, it forecast the same 243 tickets every day.
You can now fit ETS and read its letters. ETS describes a series by its level, trend and season. Next, you meet a different way to describe a series: from its past values and its past errors. Its range also shows clearly how uncertainty grows with the horizon.
Next: ARIMA and SARIMA