预测明天的需求
阅读约需 69分钟 分钟,7节中含3个示例。
本章构建对明天需求的第一个预测,以及此后每个预测都必须超越的简单基线。你将载入一位客户的逐小时需求数据,分别用季节性朴素基线和一个统计模型预测其次日需求,并在相同的 7 天上为两者评分。结果有意做得粗略:没有区间,没有调参,也只有一位客户可供判断。后续各章会分别把其中一个部分做扎实。你需要掌握 Python、pandas、样本均值以及什么是误差,除此之外不需要别的;核心术语在首次出现时用一行话加以定义。
明天的电力必须在今天、在当天开始之前,按小时购买。购电的人需要一份预测,说明客户在每个小时会用多少电;预测每错一个小时,该小时的购电计划就围绕一个错误的数字制定。因此,在信任任何方法之前,先要回答两个问题。仅凭购电之前记录的读数做出的预测,是否接近客户的实际用电量?它是否优于任何人都能做出的最简单的预测,即照抄昨天用电量的预测?
这部分尚未翻译,因此以英文显示。
The case and its data
This book follows one case throughout: an electricity supplier that buys power a day ahead for its clients, which we call the supplier.
The supplier commits to its purchases before the day starts, and it needs a range as well as a single number, because buying too little costs more than buying too much. This book builds the forecast that such a purchase starts from. A forecast here is the expected demand of one client in each hour, made from readings recorded before the forecast was made.
Three terms fix what a forecast is. The moment a forecast is made is its cutoff. A forecast uses only the readings before its cutoff, and it reaches forward a fixed number of hours, its horizon. A window is one cutoff with its horizon and the forecast it produces. Here the horizon is 24 hours, so each window covers one day: the 24 hours that start at its cutoff.
The timing matters as much as the method. Every window in this book has its cutoff at 00:00 on the day it predicts, so the last reading it can use is the one for 23:00 on the day before. The case buys before the day starts, so a midnight cutoff is a simplification. The book keeps it so that each window needs only the day before. A supplier that buys earlier would cut earlier and forecast further ahead. A forecast that reads one hour past its cutoff would use information the supplier does not have when it buys, and its score would flatter it.
The data is public. It is the ElectricityLoadDiagrams20112014 dataset from the UCI Machine Learning Repository, by Trindade (2015), with the DOI 10.24432/C58C86. It is licensed under CC BY 4.0. The book ships a cut of it, electricity_hourly.csv.gz, with the licence beside it in the same folder. The data card gives the source, the cut and its limits.
The raw file holds 370 clients, with a reading every 15 minutes. The cut averages the four readings of each hour, which gives the energy used in that hour in kWh, and it keeps two whole years, 2013 and 2014. One client, MT_223, has no non-zero reading in that window, so the cut drops it. The 369 clients that remain are sorted by id, and 30 are kept at evenly spaced positions. A reader who cuts the raw file must drop MT_223 and take the same 30 evenly spaced positions, or the counts in this book will not match.
The clients have anonymous ids such as MT_014. The dataset does not say what they are, so the book calls them clients. It does not describe them as companies or households.
Two groups of clients recur through the book. The thirty clients are every client in the cut. The 8 clients of SUBSET8 are every fourth client of the thirty, starting with the second. Later chapters use that subset where a full run would take too long, and it includes one client that starts late. The lead client, MT_014, is the first client of SUBSET8. This chapter and its single-client examples use it.
The test period is the last week of 2014, from Dec 25 to Dec 31, 2014. The forecasts in this chapter are scored on it, and it is called the held-out week. Each forecast uses only readings from before its cutoff, so no forecast learns from the day it predicts. The week is not quiet. Dec 25, 2014 is Christmas Day, a national holiday in Portugal, where the data's clock is set. This chapter scores the week as it is, and the scores show what the holiday does. Chapter 5 tests a holiday flag on holiday windows and does not keep it, so the book does not repair the holiday here. Chapter 10 shows its cost.
A forecast says what demand is likely to be. It does not say why. The data records how much each client used. It cannot say what demand would have been under a different price or contract. That is a causal question, and it needs a different design.
Working rule: Check the cut against the data card before any forecast is made. The file should hold 30 clients, and the example counts how many of them have a full two years of hourly rows. Those counts should match the card. Confirm that MT_223 is missing and explained. A cut that does not match the card is different data, and every number computed from it describes that data, not this one.
这部分尚未翻译,因此以英文显示。
Load one client's hourly demand
A time series is a sequence of readings in time order. In the book's file, each row is one client in one hour, and each client's hours are in time order. To load one client, keep that client's rows. The helper load in examples/lib/electricity.py does that and returns four columns. unique_id names the client. ds is the hour. y is the energy used in that hour, in kWh. quirk tells you whether the row needs special handling.
The ds column is the start of the hour, in local clock time with no time zone. The data card gives this label, and the book's examples treat the index as one naive hourly index. Each row's quirk is one of four labels:
normalis an ordinary hour.before_first_readingis an hour before a client's first non-zero reading. Only a late-starting client has these rows.clock_change_gapis 01:00 on a March clock-change day. The dataset's note says it reads zero for every client. The data card measures it: of 57 such hours with non-zero neighbours, 55 read below 5% of them.clock_change_repeatis 01:00 on an October clock-change day. It holds about two hours of energy under one label.
The book keeps every value as the meter recorded it. Nothing is filled, smoothed, removed or rescaled. A zero in a gap hour and a doubled October hour are therefore still in the file, flagged but not corrected. Chapter 3 decides what each flagged row means for a model. This chapter only needs to know the labels exist, and to check that none of them falls inside the windows it scores.
The lead client has readings in every hour of the window, so none of its rows are before_first_reading. Over the two years it has 17516 ordinary rows. It has 2 gap rows and 2 repeat rows, one of each in each year.
1"""Loads the lead client's hourly demand, counts its quirk labels, and checks the eight-week history before each2held-out cutoff. The point rests on the last printed line: no history holds a clock-change row."""3from lib.backtest import held_out_cutoffs, history_before4from lib.electricity import load5from lib.settings import LEAD, show678def fmt(ts):9 return ts.strftime("%Y-%m-%d %H:%M")101112FULL_ROWS = 2 * 365 * 24 # two years of hours; 2013 and 2014 are not leap years1314everyone = load()15show("clients in the file", everyone["unique_id"].nunique())16show(f"clients with {FULL_ROWS} rows", int((everyone.groupby("unique_id").size() == FULL_ROWS).sum()))1718df = load([LEAD])19show("rows", len(df))20show("first reading", fmt(df["ds"].min()))21show("last reading", fmt(df["ds"].max()))22for quirk in ["normal", "before_first_reading", "clock_change_gap", "clock_change_repeat"]:23 show(f"{quirk} rows", int((df["quirk"] == quirk).sum()))2425# history_before keeps the HISTORY_HOURS hours (eight weeks) before each cutoff, and raises if a count is off.26windows = [history_before(df, cutoff) for cutoff in held_out_cutoffs()]27show("history rows per window", min(len(w) for w in windows))28show("longest history rows", max(len(w) for w in windows))29show("first history reading", fmt(windows[0]["ds"].min()))30# Counts only the two clock-change labels.31show("clock-change rows in held-out histories",32 sum(int(w["quirk"].isin(["clock_change_gap", "clock_change_repeat"]).sum()) for w in windows))
python load-lead-client.pyclients in the file: 30
clients with 17520 rows: 30
rows: 17520
first reading: 2013-01-01 00:00
last reading: 2014-12-31 23:00
normal rows: 17516
before_first_reading rows: 0
clock_change_gap rows: 2
clock_change_repeat rows: 2
history rows per window: 1344
longest history rows: 1344
first history reading: 2014-10-30 00:00
clock-change rows in held-out histories: 0
The file holds 30 clients. The lead client has 17520 rows, from 2013-01-01 00:00 to 2014-12-31 23:00.
Two years of hours is 17520 rows for each client, and 30 of 30 clients have exactly that many, so no hour is missing from the file for those clients. A window with fewer hours than its history should hold has a gap, and the gap would be the first thing to explain. Check the client count and the row count against the card.
A forecast needs history. The book's history is 8 weeks, which is 1344 hours, and each cutoff in the held-out week gets exactly that much before it. The shortest history has 1344 rows, and the longest has 1344.
For the first cutoff of the held-out week, the history begins at 2014-10-30 00:00. That is after the clock change of Oct 26, 2014, which the data card dates. So none of the 7 histories holds a clock-change hour, and the example counts 0 clock-change rows across all seven.
The rest of this chapter can leave the clock-change rows alone for that reason. Chapter 3 meets them, and Chapter 4 meets the late starter.
Working rule: Choose the client and the window first, then count the quirks in that window's history before any model sees it. If a history holds a clock-change label or a before_first_reading row, do not hand it to a model unchanged, because the model will read the label's value as demand. Chapter 3 and Chapter 4 give the rules for those rows. A window that holds neither can use its rows as they are, as this chapter does.
用季节性朴素法预测次日
第一个预测是最简单的一个,此后的每个预测都必须胜过它。它使用案例及其数据中给出的案例截止时点和预测范围,以及加载单个客户所描述的历史数据。
季节性朴素法认为,每个未来值都等于同一季节中最后一次观测到的值。Hyndman 和 Athanasopoulos 对任意季节长度 m 都给出了这一定义:未来某个值的预测值,就是一个季节之前观测到的值(Hyndman and Athanasopoulos, Forecasting: Principles and Practice, ch. 5)。对于按小时记录且具有日周期的数据,季节长度为 24 小时,因此明天某个小时的预测值就是今天同一小时的读数。按本书的记法,第 t 小时的预测值为 y(t - 24)。
这条规则中没有任何拟合。预测值是对数据的复制,因此不需要估计步骤。无论截止时点是哪一个,它都不会读取截止时点之后的数据。对于从截止时点起到其后 23 小时的每个小时,t - 24 都落在截止时点之前 24 小时到截止时点前一小时之间,所以这种复制只用到历史数据。
留出的这一周有 7 个窗口,对应 2014 年 12 月 25 日至 12 月 31 日的每一天,每个窗口都在 00:00 做出预测。供应商关心的问题是 MT_014 明天的需求。对于 12 月 25 日,预测值复制 12 月 24 日每个小时的读数,同一规则也由前一天为这一周的其他每一天给出预测。
以 12 月 25 日 00:00 的窗口为例。它对 12 月 25 日 00:00 的预测值是 12 月 24 日 00:00 的读数,对 12 月 25 日 23:00 的预测值是 12 月 24 日 23:00 的读数。在其历史的 1344 个小时中,这一方法只用到最后 24 个,因为 statsforecast 的 _seasonal_naive 只重复最后一个季节的值(statsforecast 2.1.1,statsforecast/utils.py)。示例仍然传入全部历史,因为同一个调用也服务于会用到更多历史的模型,而一个调用、一种历史长度,只需学习一种形式,而不是两种。
为什么用一天而不用一周?168 小时的季节会复制前一周同一工作日的同一小时,对于具有周节律的序列,这是另一个有效的基线。本章采用日季节,是因为问题针对的是次日,也因为案例需要的正是日前预测。
1"""Forecasts the lead client's next day with seasonal naive for each day of the held-out week, then scores it.2The point rests on the MAE and RMSE lines, which score a copy of yesterday, and on the missing forecasts line."""3import pandas as pd4from statsforecast import StatsForecast5from statsforecast.models import SeasonalNaive67from lib.backtest import forecast_windows, held_out_cutoffs, scoring_counts, score_windows, window_mae8from lib.electricity import load9from lib.settings import HORIZON, LEAD, show101112def day_mean(day):13 return df[df["ds"].dt.normalize() == pd.Timestamp(day)]["y"].mean()141516# statsforecast reads a frame with three columns: the series id, the time and the value.17df = load([LEAD])[["unique_id", "ds", "y"]]18# season_length 24 is the daily cycle of hourly data; freq "h" is pandas' code for hourly steps; one job runs in one process.19sf = StatsForecast(models=[SeasonalNaive(season_length=24)], freq="h", n_jobs=1)20forecasts = forecast_windows(sf, df, held_out_cutoffs())21scores = score_windows(df, forecasts, "SeasonalNaive")22counts = scoring_counts(df, forecasts, "SeasonalNaive")2324show("horizon hours", HORIZON)25show("windows", counts["windows"])26show("scored hours", counts["scored_hours"])27show("missing forecasts", counts["missing_forecasts"])28# The readings at the forecast hours, which are the hours the scores cover.29show("mean demand", df[df["ds"].isin(forecasts["ds"])]["y"].mean())30show("mean demand 2014-12-24", day_mean("2014-12-24"))31show("mean demand 2014-12-25", day_mean("2014-12-25"))32show("MAE", scores["mae"])33show("RMSE", scores["rmse"])34for day, mae_day in window_mae(df, forecasts, "SeasonalNaive").items():35 show(f"MAE {day:%Y-%m-%d}", mae_day)3637# The check is run on a history with one hour removed, to show it refuses a short history.38cutoff = held_out_cutoffs()[0]39gap = df[df["ds"] != cutoff - pd.Timedelta(hours=1)] # drops the hour just before the first cutoff40try:41 forecast_windows(sf, gap, [cutoff]) # history_before raises ValueError unless every client has exactly HISTORY_HOURS rows before the cutoff.42 refused = "no"43except ValueError:44 refused = "yes"45show("history with one hour removed refused", refused)
python seasonal-naive-next-day.pyhorizon hours: 24
windows: 7
scored hours: 168
missing forecasts: 0
mean demand: 46.62
mean demand 2014-12-24: 47.58
mean demand 2014-12-25: 38.40
MAE: 8.36
RMSE: 10.87
MAE 2014-12-25: 9.41
MAE 2014-12-26: 12.16
MAE 2014-12-27: 5.10
MAE 2014-12-28: 11.16
MAE 2014-12-29: 8.68
MAE 2014-12-30: 5.26
MAE 2014-12-31: 6.75
history with one hour removed refused: yes
每个预测都与随后的读数对照评分,168 个评分小时中的每一个都有预测值。这些小时的平均值为 46.62 kWh,本章中的每个误差都应对照这一水平来解读。
季节性朴素法是一个基线,当日周期在序列中占主导时,它可以相当强。它的弱点在于只复制单独一天。异常的一天会成为次日的预测值,而该方法无法把它平均掉。
**工作准则:**对于具有日周期的小时序列,每次比较中都要保留季节性朴素法。它无需拟合,因此在每个窗口上运行都不增加成本。在同样的窗口上不能胜过它的模型,就没有证明自己值得付出额外的工作。在解读评分之前,先检查预测中是否有缺失值,因为最后一个季节中的缺失读数会变成缺失的预测值。第 3 章给出了在任何模型运行之前填补这些小时的规则。
这部分尚未翻译,因此以英文显示。
Forecast the next day with one model
The baseline above answers what a forecast gets with no model at all. The question here is whether a fitted model does better on the same 7 windows, and the model is AutoETS. statsforecast 2.1.1 describes AutoETS as selecting the best ETS (error, trend and seasonality) form with an information criterion (statsforecast/models.py, class AutoETS). The criterion AutoETS uses is AICc, the Akaike information criterion corrected for small samples. It is set in ets_f, in statsforecast/ets.py, and AutoETS offers no other.
The model string sets which forms the model may take, with one letter each for error, trend and season. Z lets AICc choose, and A fixes the form to additive. This chapter uses ZZA: AICc chooses the error and the trend, and the season is additive, so every candidate has a daily cycle. The default, ZZZ, also lets AICc choose the season. On this client and these 7 cutoffs it chose no season in every window, a flat form, ETS(A,N,N), so its forecast is one value repeated for the day. This chapter asks whether a model with the daily cycle beats a copy of yesterday, so it does not use that form. Other seasonal forms score differently on this week, and Chapter 4 looks at the forms and the choice.
A fit does three things, and each one matters for what the score means. At a cutoff, AutoETS reads the 1344 hours before it and compares the candidate forms, keeping the one with the lowest AICc. AICc rewards a close fit to the history and charges for each parameter the form uses, so a form with more parameters must fit much better to win. The model then projects that form 24 hours ahead. The held-out week therefore means 7 separate selections, not one. In this week 7 windows chose ETS(A,N,A): additive error, no trend and an additive daily season. The 7 fits still differ in their parameters. The book does not quote them, because each is a detail of one fit, and a reader should not take it as a finding.
The comparison is fair only when nothing else changes. It uses the same 7 cutoffs and the same 1344 hours of history before each one, and it refits the model at every cutoff using only the history before that cutoff. Only the model differs from the baseline.
1"""Forecasts the lead client's next day with AutoETS for each day of the held-out week, then scores it.2The point rests on the MAE and RMSE lines, read against the seasonal naive example, and on the form counts."""3import numpy as np4from statsforecast import StatsForecast5from statsforecast.models import AutoETS67from lib.backtest import chosen_forms, forecast_windows, held_out_cutoffs, scoring_counts, score_windows, window_mae8from lib.electricity import load9from lib.settings import HORIZON, LEAD, SEED, show1011# Seeded by convention. AutoETS's point forecast draws no random numbers, so this line changes nothing here.12np.random.seed(SEED)13# statsforecast reads a frame with three columns: the series id, the time and the value.14df = load([LEAD])[["unique_id", "ds", "y"]]15# model="ZZA": AICc chooses the error and trend forms; the seasonal form is fixed to additive, so every form has a day cycle.16sf = StatsForecast(models=[AutoETS(season_length=24, model="ZZA")], freq="h", n_jobs=1)17forecasts = forecast_windows(sf, df, held_out_cutoffs())18scores = score_windows(df, forecasts, "AutoETS")19counts = scoring_counts(df, forecasts, "AutoETS")20# chosen_forms refits at each cutoff to read the form each fit picked; the forecasts above do not report it.21forms = chosen_forms(sf, df, held_out_cutoffs())2223show("horizon hours", HORIZON)24show("windows", counts["windows"])25show("scored hours", counts["scored_hours"])26show("missing forecasts", counts["missing_forecasts"])27for form, n in forms.items():28 show(f"windows that chose {form}", n)29show("MAE", scores["mae"])30show("RMSE", scores["rmse"])31for day, mae_day in window_mae(df, forecasts, "AutoETS").items():32 show(f"MAE {day:%Y-%m-%d}", mae_day)
python autoets-next-day.pyhorizon hours: 24
windows: 7
scored hours: 168
missing forecasts: 0
windows that chose ETS(A,N,A): 7
MAE: 8.86
RMSE: 10.91
MAE 2014-12-25: 13.51
MAE 2014-12-26: 11.21
MAE 2014-12-27: 4.17
MAE 2014-12-28: 10.03
MAE 2014-12-29: 9.53
MAE 2014-12-30: 6.33
MAE 2014-12-31: 7.25
The counts match the baseline's, so the two scores cover the same 168 hours, and all 7 windows chose the same form. The model makes 7 fits, one at each cutoff, and each sees only what was known at its cutoff. The next section sets the scores side by side.
Working rule: Add a model only with a baseline it has to beat on the same windows. Refit the model at each cutoff, using history from before that cutoff only. A model fitted once on the whole series and then scored on that series has seen the answers, and its score is not a forecast score.
这部分尚未翻译,因此以英文显示。
Score both on a held-out week
Both examples have now made 7 day-ahead forecasts, from the two sections above. A score turns the errors of a set of forecasts into one number. The error of an hour is the actual demand minus the forecast. This chapter uses two scores. The mean absolute error, MAE, is the average size of the miss: MAE = mean(abs(actual - forecast)). The root mean squared error, RMSE, is RMSE = sqrt(mean((actual - forecast)^2)). Both are in kWh, and they answer different questions. Hyndman and Athanasopoulos, in Forecasting: Principles and Practice, ch. 5, note that a forecast minimising MAE is a forecast of the median, and one minimising RMSE is a forecast of the mean. Because RMSE squares each error, a few large misses raise it more than they raise MAE.
Both scores come from utilsforecast (0.2.17). Its mae is the mean of the absolute errors, and its rmse is the square root of the mean of the squared errors (utilsforecast/losses.py, functions mae and rmse). The scores pool the 168 scored hours. Each hour counts once, and each of the 7 windows contributes 24 of them.
Read the table against the mean demand of 46.62 kWh an hour: a lower number means forecasts closer to the readings.
| Model | MAE (kWh) | RMSE (kWh) |
|---|---|---|
| SeasonalNaive | 8.36 | 10.87 |
| AutoETS | 8.86 | 10.91 |
AutoETS's errors are higher than the baseline's on both scores, as the table shows, with MAE at 8.86 kWh against 8.36. The MAE is the number to plan with, because it is the typical miss in each hour. RMSE is always at least MAE. For normal errors RMSE is about 1.25 times MAE, so a ratio well above that means a few large misses. This section reads the two scores together and goes no further, because one client over one week cannot show the spread of the misses.
Both models do worst around Christmas, but on different days. The daily lines show where: the baseline's worst day is Dec 26, the day after Christmas, when it copies Christmas Day, at 12.16 kWh an hour, the largest of the 7. AutoETS's worst day is Dec 25 itself, at 13.51 kWh, against 9.41 for the baseline. A gap of this size on one client over one week is not a verdict. Seven forecasts make a small sample, and a ranking built on one week can flip on the next. Chapter 3 backtests seasonal naive over a year of Sunday cutoffs.
The score also has to match the decision, and the purchase is lopsided: as the case says, buying too little costs more than buying too much. MAE and RMSE treat a miss in either direction alike, because they use the size of each miss and not its sign. That is enough for this chapter, which asks whether a forecast is close. It is not enough for the purchase. Chapter 8 builds ranges for that decision, and scores them against what happened.
Working rule: Score each model on forecasts it made without the scored hours in its history, over more than one day, and report the number of windows and hours behind each score. Compare models only on the same windows. Read MAE and RMSE together. If they disagree about which model is better, look at the largest misses in the windows before you choose, because a few large misses can decide the result.
这部分尚未翻译,因此以英文显示。
What goes wrong in production
The forecasts and scores above can go wrong in 5 ways, and only some of them print an error. The cutoff rule and the seasonal naive rule say what each window must hold.
The first failure is a label that is off by an hour, and no score in this chapter detects it. If a reader takes ds as the end of its hour rather than the start, the forecasts and the readings they are scored against carry the same shift, so the score does not change. The error is in the purchase instead: the forecast would cover different hours from the ones the supplier buys for. The data card fixes the label, so it is the first thing to check when a forecast is moved to new data.
Leakage flatters a window whose history includes the hours it predicts, and nothing in the score says so. Hewamalage, Ackermann and Bergmeir (2022) warn that rolling-origin evaluation is prone to this leak when it is not done with care. The checks here are the cutoff rule and the history length. Each history must end before its cutoff and hold 1344 rows. history_before raises an error when a history is short or long. A history with one hour removed is refused: the check at the end of the seasonal naive example prints yes for it.
Seasonal naive copies yesterday, so an unusual day becomes tomorrow's forecast, and the held-out week holds one. Dec 25, 2014 is Christmas Day, and the lead client's mean demand that day is 38.40 kWh an hour, against 47.58 kWh on Dec 24. The window for Dec 26 copies that day, so it has the largest MAE of the 7 windows, 12.16 kWh. That is the failure, and the scores show it. One holiday is too few to measure a holiday effect, so the book leaves it alone, as the case and its data explains. Chapter 10 shows its cost.
A missing reading gets through unchecked. The statsforecast seasonal naive does not check its input. It repeats the last season's values, so a missing value in that season becomes a missing forecast (statsforecast 2.1.1, statsforecast/utils.py, function _seasonal_naive). The seasonal naive example counts missing forecasts, 0 here, because a hole in the forecast is an hour the score does not describe. Chapter 3 fills the hours that need filling, from data before the cutoff, before any model runs.
Last, the window itself can flatter the method. A week with no unusual days can make almost any forecast look good, and a week with one can make every forecast look bad. The held-out week has a holiday in it, and it is still one week for one client, so its scores describe that week more than the method. The fix is breadth: compare models on several windows of different kinds before you trust a ranking.
Working rule: Before you trust a score, check three things in this order: each window's first forecast hour is its cutoff, each history ends before its cutoff and holds the full history length, and no forecast is missing. The helpers raise an error for the first two, and the examples print the third. A score counts as a finding only after all three pass.
本章做出的决定
本章共做出九项选择。其中大多数是 examples/lib/settings.py 中的设置,因此后续版次若修改其中一项,所有用到该设置的章都会随之改变。其余几项在数据卡或本章中说明。第 2 章从这两个预测及其两个得分出发,考察其中任何一个是否好到可以据以行动。
- 每个窗口的截止时间是它所预测那一天的 00:00,预测范围为 24 小时,因此每个窗口覆盖那一整天。
- 每个截止时间之前的历史为 1344 小时,即 8 周。
- 主要客户是
MT_014。留出的一周是 2014 年 12 月 25 日至 12 月 31 日:7 个窗口,168 个计分小时。 - 得分为 MAE 和 RMSE,在这些计分小时上汇总计算,并保留两位小数输出。
- 模型是季节长度为 24 小时的季节性朴素模型,以及模型字符串为
ZZA、季节长度为 24 小时的 AutoETS。每次运行使用 statsforecast,任务数为 1。两个点预测都不抽取随机数,因此 AutoETS 示例按惯例设置的种子对它没有影响。 - 如数据卡所述,裁剪会去掉
MT_223,保留 30 个客户。 - 时钟变更行和晚启动行保持原样,因为本章用到的历史中都不包含它们。第 3 章和第 4 章会处理这些行。
- 正文引用的每个数字都绑定到其示例记录的输出中带标签的一行,因此正文与输出不会在无人察觉的情况下出现不一致。
- 本章只构建一个客户的预测,不含区间。区间从第 8 章开始。
本章,在本版次中
版次 2026.11.11示例于 2026年11月20日 通过本章 3个示例 个示例中有 3 个通过
译自英文版图书,版次 2026.11.11。