AI 翻译。由人工以英文核验。 阅读原文
教学套件
来自版次 2026.11.23,即本书当前版次。本书变更时,此版次随之变更。可自由使用和改编,但须注明出处。
教学大纲
阅读时长仅针对本章正文。学生还可在实验环境或自己的机器上运行其中的示例。
每周一章:10周
| 周 | 各章 | 阅读 | 示例 |
|---|---|---|---|
| 1 | 1. 预测明天的需求 | 50 分钟 | 4 |
| 2 | 2. 设定模型必须超越的基线 | 56 分钟 | 3 |
| 3 | 3. 不看未来的回测 | 70 分钟 | 8 |
| 4 | 4. 为每个客户拟合统计模型 | 58 分钟 | 9 |
| 5 | 5. 添加日历特征与滞后特征 | 69 分钟 | 4 |
| 6 | 6. 用一个模型预测多个客户 | 67 分钟 | 5 |
| 7 | 7. 让总量相加一致 | 35 分钟 | 3 |
| 8 | 8. 量化预测的不确定性 | 62 分钟 | 7 |
| 9 | 9. 比较 Prophet 与基础模型 | 80 分钟 | 7 |
| 10 | 10. 让预测持续运行 | 50 分钟 | 6 |
5 周后
| 周 | 各章 | 阅读 | 示例 |
|---|---|---|---|
| 1 | 1. 预测明天的需求 2. 设定模型必须超越的基线 | 106 分钟 | 7 |
| 2 | 3. 不看未来的回测 4. 为每个客户拟合统计模型 | 128 分钟 | 17 |
| 3 | 5. 添加日历特征与滞后特征 6. 用一个模型预测多个客户 | 136 分钟 | 9 |
| 4 | 7. 让总量相加一致 8. 量化预测的不确定性 | 97 分钟 | 10 |
| 5 | 9. 比较 Prophet 与基础模型 10. 让预测持续运行 | 130 分钟 | 13 |
学习目标与大纲
每章的学习目标即其第一句。每份大纲依循该章的节,列出该章定义的术语、运行示例前要求做出的预测,以及每节结尾的规则。
1. 预测明天的需求
阅读约 50 分钟,4个示例。
本章构建第一个对明天需求的预测,以及此后每个预测都必须超越的简单基线。
讲义大纲:7节
-
案例与数据
- 工作准则 在作出任何预测之前,先对照数据卡检查截取版本。文件中应有 30 个客户,示例会统计其中有多少个具有完整两年的逐小时数据行。这些计数应与数据卡一致。确认
MT_223缺失且有说明。与数据卡不符的截取版本是另一份数据,由它算出的每个数字描述的都是那份数据,而不是本书所用的数据。
- 工作准则 在作出任何预测之前,先对照数据卡检查截取版本。文件中应有 30 个客户,示例会统计其中有多少个具有完整两年的逐小时数据行。这些计数应与数据卡一致。确认
-
Load one client's hourly demand
- 运行
load-lead-client.py - 工作准则 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_readingrow, 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.
- 运行
-
用季节性朴素法预测次日
- 运行
seasonal-naive-next-day.py - 工作准则 对于具有日周期的小时序列,在每一次比较中都保留季节性朴素法。它不需要拟合,因此可以在每个窗口上运行,不增加额外成本。如果一个模型在相同窗口上不能胜过它,就没有证明自己值得多付出的工作。在查看得分之前,先检查预测中是否有缺失值,因为最后一个季节中的缺失读数会变成缺失的预测。第 3 章给出了在任何模型运行之前填补这些小时的规则。
- 运行
-
Forecast the next day with one model
- 运行
autoets-next-day.py - 工作准则 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.
- 运行
-
在留出的一周上为两者评分
- 运行
figure-held-out-week-forecasts.py - 工作准则 对每个模型的评分,应基于它在历史数据中不含被评分小时的情况下做出的预测,覆盖不止一天,并报告每个评分背后的窗口数和小时数。只在相同的窗口上比较模型。把 MAE 和 RMSE 放在一起读。如果两者对哪个模型更好意见不一,先查看这些窗口中最大的几次偏差再作选择,因为少数几次大的偏差就可能决定结果。
- 运行
-
生产中会出什么问题
- 工作准则 在相信一个得分之前,按以下顺序检查三件事:每个窗口的第一个预测小时就是它的截断点;每段历史都在其截断点之前结束,并包含完整的历史长度;没有缺失的预测。辅助函数会对前两项报错,示例会打印第三项。三项都通过之后,得分才算得上一个结论。
- 本章做出的决定
2. 设定模型必须超越的基线
阅读约 56 分钟,3个示例。
本章为某客户的日前预测计算三条基线,即朴素预测、季节性朴素预测和周平均预测,并使用 MASE 对该客户的误差进行缩放,所用的尺度只读取预测周之前的读数。
讲义大纲:7节
-
为什么先做基线
- 工作准则 对每个基线,都要使用与将要同它比较的模型相同的窗口、历史和评分代码来评分,并且在阅读每个基线的得分之前,先统计它缺失的预测数量。一个模型如果胜过的是在不同小时上评分的基线,就不能说它已经胜过了该基线。
-
Three baselines to beat
- 运行
naive-baselines-held-out-week.py - 运行
figure-baseline-window-errors.py - 工作准则 Start from naive and seasonal naive, both from the library, and add average of weeks when the series has a weekly rhythm worth testing. Check one forecast by hand against its formula before you rely on a baseline: pick one cutoff, compute one hour from the readings in its history, and compare the result with the forecast.
- 运行
-
Scale errors with MASE
- 运行
mase-scale-leak-check.py - 工作准则 Report MASE beside MAE whenever the clients you compare differ in size, and say in the same sentence which history the scale comes from. Read MASE as a ratio of two mean errors, one from the scored hours and one from the history. It is not a percentage gain over seasonal naive, even when the MASE is well below 1.
- 运行
-
从历史数据取 MASE 的尺度
- 工作准则 只向尺度传入第一个测试日之前的读数,屏蔽其中的换时读数,并打印它所用的最后一条读数。检查这条读数是否为第一个测试日之前的那个小时。两种尺度之间差别很小,并不能证明流程正确,行检查才能证明。
-
解读基线的得分
- 工作准则 将每种基线的 MASE 与 1 相比,也与其他基线相比,不要凭一周的数据宣布胜者。只有当模型在不止一组窗口上胜过最好的基线,并且领先幅度大于所印得分的舍入误差时,才算它更好。
-
生产中会出什么问题
- 工作准则 按以下顺序检查基线的输入及其尺度的输入:每种方法使用相同的窗口;尺度只读取更早的读数,并打印其最后一个读数;季节性滞后所用的小时历史连续无缺口;季节与数据的周期相符。每项检查都只是一行输出或一个计数,检查未通过就要停止比较,直到问题修复。
- 本章做出的决定
3. 不看未来的回测
阅读约 70 分钟,8个示例。
本章教你在一年的预测截止时间点上,为日前预测打分,同时不让未来信息进入它的历史数据;教你处理数据中两个时钟变更的小时;还教你运行一项平移检验,用来发现读取了截止时间之后数据的特征。
讲义大纲:10节
-
为什么只用一周测试会产生误导
- 工作准则 在相信两种方法之间的差异之前,优先使用一整年的截止点。若成本迫使你使用更少的截止点,就在每个分数旁注明,如第 4 章至第 9 章所做的那样。要确保样本覆盖一年中的特殊日子。说明每个数字背后有多少个窗口、多少个计分小时。来自一周的数字只是一个样本,读者应当能看出这一点。
-
Roll the cutoff forward
- 运行
backtest-sundays-2014.py - 运行
figure-rolling-windows.py - 工作准则 Set the history length explicitly, in hours, and check that it is the same for every window. When a library loops over windows for you, read how it sets the training slice before you trust its output, because its default may be an expanding window rather than the length you chose.
- 运行
-
Keep the future out of the history
- 运行
history-cut-check.py - 工作准则 Slice each window's history by its cutoff, never by the start of its test window, and pass a library only the rows it may use. Check the first and last timestamps of every history, and make sure the last one is an hour before the cutoff.
- 运行
- 认识时钟变更
-
The March hour that reads zero
- 运行
clock-change-census.py - 运行
clock-gap-daily-cutoffs.py - 工作准则 Treat a 01:00 reading of zero on a March clock-change day as a missing hour, not as zero demand. Keep it out of a model's history and out of the scores, and do not let a seasonal method copy it into the next day.
- 运行
-
包含两小时的十月那一小时
- 运行
clock-repeat-daily-cutoffs.py - 工作准则 应把十月的 01:00 标签视为一个时段内含两小时的电量,绝不能当作普通小时。不要为了让它看起来像一小时而将其减半,原因见下一节。
- 运行
-
将换钟时段标记为缺失
- 运行
clock-masked-backtest.py - 工作准则 在每份历史数据和每次评分中,都将两个换钟时段标记为缺失;在报告中统计被屏蔽的时段数;仅当模型不能处理缺失值时,才只用截止时间之前的历史数据来填充这些时段。如果被屏蔽的时段数在两次运行之间发生变化,说明样本或文件的标记已经改变,应先查明原因,再重新运行评分。
- 运行
-
Check a backtest for leakage
- 运行
leakage-shift-check.py - 工作准则 Keep every lag at least the horizon, 24 hours, so that the reading a lag uses for any target hour was known at the cutoff. Before you trust a backtest with features, run both halves of the shift test on every feature, at several cutoffs spread through the year, and require zero differing rows for every feature the model reads. A feature that differs is reading the future, so fix or remove it before you score anything.
- 运行
-
What goes wrong in production
- 工作准则 Run the clock and shift checks again on every data refresh, and before any change to the sample's dates, the history length or the scale. Keep the masked-hour count, the census counts and the shift-test counts in the run log next to the scores, so that a later change in either can be traced to its cause.
- 本章做出的决定
4. 为每个客户拟合统计模型
阅读约 58 分钟,9个示例。
供应商的每个客户都需要各自的次日预测,而第 2 章的季节性朴素法对所有客户给出同一个答案:昨天的同一小时。
讲义大纲:10节
-
为什么接下来是统计模型
- 运行
figure-lead-client-fortnight.py - 工作准则 只有在基准和回测都已就位之后,才为每个客户拟合一个模型。选定窗口数量之前先数一数拟合次数:客户数乘以窗口数,若每天都重新运行模型,还要再乘以重新拟合的次数。比较中的每个模型都使用相同的截止点和历史。否则,比较衡量的是窗口,而不是模型。
- 运行
-
Fit exponential smoothing
- 运行
figure-smoothing-weights.py - 运行
autoets-subset-backtest.py - 运行
flat-form-check.py - 运行
autoets-forced-season-backtest.py - 工作准则 Start with AutoETS for hourly demand with
season_length=24, and print the chosen forms in every backtest. When a client takes a flat form, check that its seasonal form is not failing. If the seasonal fit has the lower likelihood, force the season withmodel="ZZA", and score both forms on earlier windows before you keep either: cutoffs before the held-out week that the report does not score, such as the four ordinary days in late November and early December 2014, which Chapter 5 sets aside for choices. The standard cutoffs show the comparison here, but they do not decide it. When a forecast gets worse, look first for a form that changed between cutoffs.
- 运行
-
拟合固定的季节性 ARIMA
- 运行
figure-seasonal-difference.py - 运行
arima-summary-look.py - 工作准则 当搜索太慢,无法在每个截止点都运行时,就固定阶数,并写在调用中。只打印一次摘要,检查其中列出的项是否就是你想要的那些。在每个截止点重新拟合这一固定阶数,就像重新拟合任何模型一样。阶数保持固定,系数则不然。
- 运行
-
在相同的截止点上比较模型
- 运行
arima-subset-backtest.py - 工作准则 在相同的截止点上,用相同的历史和相同的尺度为每个候选模型打分,并同时报告 MAE 和 MASE。当两者不一致时,要说明决策需要的是哪一个。当两个模型的差异小于约十分之一个 MASE 时,我们建议先增加窗口数量,再在两者之间做选择。这个阈值是根据本样本做出的判断,不是测量得到的结果。
- 运行
- 认识晚开始的客户
- 以零开头的历史数据
-
让每条序列从第一个读数开始
- 工作准则 当客户的历史中含有零值时,检查它的第一个非零读数是否落在历史之内。如果是,就在任何模型看到该历史之前应用起点规则,无论零值占比多少,因为开头的零值并不是用电。先在整条序列上运行
check_start_rule,如果失败,在裁剪任何数据之前先查明原因。打印每个截止点的历史长度,因为历史过短是规则裁掉过多数据的第一个迹象。
- 工作准则 当客户的历史中含有零值时,检查它的第一个非零读数是否落在历史之内。如果是,就在任何模型看到该历史之前应用起点规则,无论零值占比多少,因为开头的零值并不是用电。先在整条序列上运行
-
为什么本书在季节周期为 24 时避免使用自动 ARIMA
- 工作准则 在每天重新拟合的调度中,不要对按小时的数据以季节周期 24 运行自动搜索。在采用之前,先在一个客户上为搜索计时。如果太慢,就固定阶数,并在回测中检验该阶数。
- 生产中会出什么问题
- 本章做出的决定
5. 添加日历特征与滞后特征
阅读约 69 分钟,4个示例。
学完本章后,你将能够:把一位客户的逐小时历史数据转换成特征表,加入日前预测允许使用的滞后特征、日历特征和节假日特征,在相同的窗口上衡量每个特征带来的增益,并找出读取了待预测日数据的滞后特征。
讲义大纲:8节
-
Turn history into features
- 工作准则 Build every feature row as if the cutoff were the last reading you have. A feature for a forecast hour must be computable from readings at or before the cutoff of its window. Before any shift test, ask whether the feature is known at the cutoff. Then check it with the shift test from Chapter 3, and do not train on a table you have not checked.
-
添加预测时可见的滞后特征
- 工作准则 只使用不短于预测范围的滞后。对 24 小时的预测范围,这意味着 24 小时或更长,本书使用 24 和 168。更短的滞后需要给出理由,使用它的模型在任何人信任其得分之前必须通过平移检验。对滞后保持时钟规则,并统计滞后读取了被屏蔽小时的行数,以及由历史填充的小时数。
-
Add calendar and holiday features
- 运行
figure-holiday-like-sunday.py - 工作准则 Add the calendar features the case's rhythm needs, and keep each one only if it helps on the same windows, as the next section measures. For holidays, use a calendar that covers every year in your data and every year you will forecast, and print how many holidays it holds for those years. A count of zero for a forecast year means the list is missing that year, not that the year had no holidays.
- 运行
-
基于决策窗口进行选择
- 工作准则 应在留出周之前、且包含该特征所针对的那类日子的窗口上选择特征:节假日特征需要节假日窗口。标准截止点与选择结果并列报告,但绝不用于做出选择。
-
衡量每个特征带来的增益
- 运行
lgbm-feature-sets.py - 工作准则 只有当一个特征集在相同窗口上相对于它所扩展的特征集降低了每客户平均 MASE 时,才保留该特征集。同时在旁报告合并 MAE。不要为了消除两种视角之间的分歧而调整模型。
- 运行
-
Catch a lag that leaks the future
- 运行
lag-leak-check.py - 运行
figure-leaky-lag-forecast.py - 工作准则 Run the shift test on every lag and every window feature before a model trains on it, and treat any differing row as a leak until you have shown otherwise. When an error falls sharply after you add a feature, check that feature first, before you credit it.
- 运行
-
生产中会出什么问题
- 工作准则 每当数据或库发生变化时,重新检查每个预测年份的节假日数量、被屏蔽的小时及其波及的行,以及各滞后的长度。对每个滞后运行平移测试,并在汇总 MAE 旁边阅读各客户的 MASE。某项检查的结果发生变化时,应先停下来查明原因,再发布下一次预测。
- Decisions this chapter made
6. 用一个模型预测多个客户
阅读约 67 分钟,5个示例。
本章结束时,你将得到一个适用于全部三十个客户的全局模型,一条让晚启用客户的前导零不进入模型的起始规则,以及一个评分:它在相同的截止点上,为每个客户把该模型与季节性朴素方法并列比较。
讲义大纲:7节
-
One model for many clients
- 工作准则 Fit one global model when your series share a shape and you must forecast many of them on each window. Scale each series' target with statistics from that window's history only, use only lags at least as long as the horizon, and fit once per window, not once per series. Then score the model per series against a baseline on the same windows, as the sections below do, before you trust its pooled error.
-
识别每个客户
- 运行
client-identifier-check.py - 工作准则 按第 5 章的规则,把客户标识符当作又一个特征:只有当它在决策窗口上降低了各客户 MASE 的均值时才保留它,同时把汇总 MAE 一并列出作对照。如果结论接近临界,就如实说明,并在其他窗口上重新测量。如果标识符胜出,要记下它的代价:新客户在有历史数据之前没有学到的分裂,模型必须重新拟合之后才能预测该客户。
- 运行
-
Apply the start rule to every client
- 运行
start-rule-leak-check.py - 运行
global-model-raw-starts.py - 工作准则 Apply the start rule to every series that has leading zeros, and find each first reading from the rows before the cutoff. When the rule refuses a cutoff, stop the run and name the client and the cutoff. Do not fill the zeros, and do not publish a panel with a client missing. Judge the rule by the scale and by the windows where zeros enter the history, and expect the MAE effect to be small and mixed.
- 运行
-
Score thirty clients on the same cutoffs
- 运行
global-model-thirty-clients.py - 运行
figure-client-mase-global-vs-naive.py - 工作准则 Score a global model per client on the same cutoffs as the baseline, with the MASE scale fixed before the first scored cutoff. Report the mean per-client MASE beside seasonal naive, and print the counts of clients and scored hours so a reader can check them. State any client left out of MASE and why. Read the pooled MAE and RMSE as the cost in kilowatt hours, not as the measure of model quality.
- 运行
-
预算运行时间
- 工作准则 运行回测之前,先数一数它的拟合次数:逐客户方法为客户数乘以窗口数再乘以方法数,全局方法为窗口数乘以方法数。如果次数超出预算,就缩减子集或窗口数,绝不缩减参与评分的窗口,并把这一缩减写在分数旁边。这样,读者便能在同等条件下进行比较。
-
生产中会出什么问题
- 工作准则 每次刷新时,先打印并核对各项计数(客户数、窗口数、已评分小时数、被拒绝的截止点数、未纳入 MASE 的客户数),然后再查看任何得分。接着报告逐客户 MASE 的均值,并与季节性朴素方法并列。出现任何拒绝都要停止运行,不要发布由不完整面板得出的总量。
- 本章做出的决定
7. 让总量相加一致
阅读约 35 分钟,3个示例。
你将用两种方式预测三十个客户的总需求,在决策窗口上选出其中一种,并且只使用每个截止时间点之前的历史数据,把这个总量拆分为各客户的份额。
讲义大纲:7节
-
为什么总量需要检验
- 工作准则 只要某项决策依赖总量,就用两种方式分别预测总量。在相同的窗口上为两种方法评分,既对照总量,也对照各个客户。保留在决策窗口上表现更好的方法,绝不因为各部分相加一致就接受某个总量。
-
汇总各客户的预测
- 运行
total-bottom-up-and-direct.py - 工作准则 逐小时汇总各客户的预测,并且事先检查总量序列在每个没有时钟变更标记的小时都等于其读数之和。在求和之前对每个客户应用起始规则,使任何客户的模型都不会用其零值拟合。把这个和当作点预测,不要把各客户中位数之和当作总量的中位数。
- 运行
-
直接预测总量
- 工作准则 使用各客户的特征,根据每个截止点之前总量自身的历史直接预测总量,并在决策窗口上选择目标的缩放方式。两种方法使用相同的窗口,并各自与总量的季节性朴素预测比较评分。两种方法都要报告,而不是只报告自己构建的那一种。
-
比较两种总量
- 工作准则 在决策窗口上,按你将要报告的度量来选择方法。在标准截止点上报告同一度量,并与季节性朴素方法并列,同时给出被评分的小时数和尺度。当两组窗口意见不一时,两者都要报告,说明相差多少,不要挑选读起来更好看的一组。
-
按份额拆分总量
- 运行
figure-client-daily-profiles.py - 运行
total-split-by-share.py - 工作准则 只有在作为基线,或各客户的日内曲线相似时,才按份额拆分总量。每个份额都应由其截断点之前的历史算出,并检查截断点之后的读数改变时没有份额变动,还要在相同尺度上将每个客户与自下而上相比较。只有当拆分在决策窗口上获胜时,才对该客户保留拆分。
- 运行
-
生产环境中会出什么问题
- 工作准则 在生产环境中,每次重新拟合时都要将总量与其读数之和核对,当总量中缺少某个客户时就停止,并对每个份额以及每个窗口的尺度运行投毒检查。在相同的窗口上记录总量在使用和不使用标识符时的误差。当各窗口的结论不一致时,应同时报告两者,不要选择对模型有利的那一个。
- 本章所做的决定
8. 量化预测的不确定性
阅读约 62 分钟,7个示例。
本章为每一个日前预测给出一个区间范围,使你能够判断一次采购是否可以依赖该预测。
讲义大纲:7节
-
为什么一个数字还不够
- 工作准则 凡是两种误差的代价不同,就要求给出区间,并依据这些代价而不是某个看起来令人安心的数字来选择区间的水平。报告覆盖率时,应将其表述为多个窗口内落在区间带内的小时所占的比例,而不是某一天落入区间的概率。
-
由残差构建区间
- 运行
conformal-three-windows.py - 工作准则 每个预测带都用其截止点之前的窗口的残差构建,并在信任它之前,检查它在未用于构建的窗口上达到的覆盖率。先看设计能达到的水平,再看覆盖率。每个客户和小时只有三个残差,无法达到任一标称水平,所以解决办法是更大的校准集,而不是换一种方式解读输出。
- 运行
-
在较早的窗口上校准
- 运行
conformal-decision-windows.py - 运行
figure-client-coverage-scaled.py - 运行
conformal-earlier-windows.py - 工作准则 在早于被评分窗口、且不含假日的窗口上校准,并在汇总残差之前对每个客户做尺度缩放。每个设计选择都要在不属于所报告窗口的窗口上做出。报告有多少窗口和残差进入了区间,以及区间在被评分日上给出的覆盖率,即使该覆盖率达不到标称水平。
- 运行
-
Measure coverage on held-out days
- 运行
total-band-miss-runs.py - 运行
figure-total-band-misses.py - 工作准则 Report coverage on windows that the calibration never used, with the number of windows and the coverage of each. Keep the same measure in a running log once the forecast runs every day, as Chapter 10 does. Read three scored days as a warning, not as a measurement of the level you were promised.
- 运行
-
Choose the level from the cost of error
- 运行
buy-ahead-level-by-cost.py - 工作准则 Set the buy level from the two costs, as
tau = cu / (cu + co), fix it before you score the days, and calibrate the total's bands on the total's own residuals. Show the realised cost at other levels as a check, but never move the level to whichever one would have won on the days you score.
- 运行
- 生产环境中会出什么问题
- 本章做出的决定
9. 比较 Prophet 与基础模型
阅读约 80 分钟,7个示例。
读完本章后,你将能够在本书的三个标准截止点上拟合 Prophet,加载一个已记录的基础模型(Chronos-2)和一个已记录的神经网络模型(NHITS),并在同一个 MASE 尺度上,对照同样的读数为它们全部评分。
讲义大纲:7节
-
Prophet 的适用场景
- 工作准则 当读者需要把趋势和季节性设置作为可读的参数,并且在评分之前选定的决策窗口上,其经过评分的预测优于季节性朴素法时,才对每个客户分别使用 Prophet。在代码中设置其区间宽度,并把它默认的 80% 区间当作 80% 区间来读,绝不能当作 95% 的范围。要对照它所声称的水平来检验它的覆盖率。
-
Run Prophet on the same cutoffs
- 运行
prophet-holiday-decision.py - 运行
prophet-thirty-clients-backtest.py - 工作准则 Set Prophet's seasonality, holidays and interval width in code before you score it, and choose any of them on decision windows, never on the standard cutoffs. Keep the holiday table only if it lowers the MASE on the holiday decision windows. Compare Prophet with seasonal naive and the global model on the same windows and the same scale, and list the clients it loses. Set the seed before each predict, and check that a second run prints the same lines.
- 运行
-
Load a recorded foundation model's forecasts
- 运行
recorded-chronos2-check.py - 工作准则 Record a foundation model only with its script, its pinned revision, its package versions and a manifest that hashes every output. Read the recorded outputs in every example, and check the hashes before any score reads them. Check the licence of the weights, not only the licence of the package, and name the model version in any licence sentence.
- 运行
-
Score the recordings on the same cutoffs
- 运行
recorded-chronos2-score.py - 运行
recorded-nhits-score.py - 运行
figure-chronos-ranges.py - 工作准则 Score a recorded forecast on the same windows, the same scale and the same readings as every other model, and name any interpolated quantile wherever its range is reported. Before you read a lead, check what the model was trained on, because a model that saw the scored readings cannot show skill on them. Do not choose a model or a setting on these windows. A recorded forecast with no forecasts on the decision windows cannot be chosen for production until it has them.
- 运行
-
为什么要记录神经网络模型
- 运行
recorded-nhits-check.py - 工作准则 当某个模型的依赖会突破运行时预算时,就把它排除在示例的运行时之外,改为记录其结果,并把它的固定版本写在单独的依赖文件中。添加依赖之前,先在干净的环境中安装它,并衡量它在体积和软件包数量上增加了多少。如果依赖解析会改动某个已固定的软件包,这是记录该模型的理由,而不是修改固定版本的理由。
- 运行
-
What goes wrong in production
- 工作准则 Before any Prophet or recorded forecast is reported, check that the holiday table covers the forecast's years when the table is on, that the interval level is printed beside its coverage, that the recording has a window for every cutoff in use, that its quantiles are in order, and that the model revision matches the one scored. A failed check stops the report, and the report says which check failed.
- 本章做出的决定
10. 让预测持续运行
阅读约 50 分钟,6个示例。
预测一旦每天运行,问题就从它的得分好不好,变成了它在使用当天是否依然可靠。
讲义大纲:7节
-
Refit on a schedule
- 运行
refit-cadence-decision.py - 工作准则 Choose the refit cadence on ordinary days that come before the held-out week, scored on one scale that was read before the first of those days. Take the cadence with the lower mean MASE, and when the two are close, take the one with fewer refits and say so. Never refit on readings from the day you are forecasting.
- 运行
-
在实际值到达之前记录每一次预测
- 运行
rolling-refit-seven-days.py - 工作准则 在每次预测的截止时间,依据当时已到达的读数写入该次预测的各行,并在旁边附上重新拟合日和两个到达时间。不要用更新的模型或实际值重建过去的日志。如果某一天的行丢失了,就在日志中把那一天标记为缺失,事后不要补填。
- 运行
-
随实际值到达为日志评分
- 运行
late-fill-decision.py - 工作准则 每一天在其最后一个读数到达时评分,依据是在该天截止时刻记录的预测,并使用本章唯一的尺度。读数迟到时,在它到达时评分,在日志中计数,并且不动已记录的预测。截止时刻之后绝不修改预测,即使修改会改善得分。
- 运行
-
对照回测标记漂移
- 运行
drift-flag-rolling.py - 工作准则 当某天的每日 MASE 高于此前校准窗口中位数的两倍时,标记该日,然后检查是否有日历原因可以解释它。若有原因,把原因记录在标记旁边。把连续两次无法解释的标记视为退役检查的开端,绝不要当作模型已损坏的证明。
- 运行
-
了解何时淘汰模型
- 运行
drift-after-a-change.py - 运行
figure-drift-flags.py - 工作准则 当标记连续多日出现且没有日历上的原因,或者 80% 区间在若干天内覆盖的读数远低于 80% 时,应提前重新拟合,并将触发原因与日志一并记录。若提前重新拟合未能消除标记,则淘汰该模型。固定版本的库发布新版本时,重新运行本章的检查,并保持版本固定,直到检查在新版本上通过。
- 运行
-
生产中会出什么问题
- 工作准则 每次运行都要保留三项检查:使未来数据不进入每次重新拟合和预测的历史规则、对日志每一行的两项到达检查,以及第 3 章和第 7 章的泄漏检查。其中任何一项失败时,应停止循环,并在下一次预测之前修复原因。不要手工修补历史或日志,因为手工修补正是这些检查要捕捉的那类改动。
- 本章做出的决定
测验题库
为通过认证的教育者提供每章的习题及参考答案。每个答案均对应其所在的节。 如何获取
正在加载题库…