Prophet と基盤モデルの比較
読了まで約55 分分、7 節 節の 6 例 例。
この章を終えると、本書で標準とする三つのカットオフに Prophet を適合させ、記録済みの基盤モデル(Chronos-2)と記録済みのニューラルモデル(NHITS)を読み込み、すべてを同じ実測値に対して一つの MASE の尺度で評価できるようになる。
読者は本書の外で Prophet やニューラル予測モデルに出会うが、それぞれが独自の主張を掲げている。この章では、供給事業者の顧客に対して、標準のカットオフである 2014 年 12 月 29 日から 31 日の期間に、それぞれのモデルがどのような結果を示すかを問う。供給事業者がどのモデルにも求めるのは、より限定されたものである。すなわち、顧客ごとの翌日予測と、それを根拠に購入を判断できる範囲である。第 8 章では、以前の期間を用いてこのような範囲を較正した。ここでの範囲はその方法では較正されていないため、この章では被覆率を確認するにとどめ、修正は行わない。すべてのモデルは、第 2 章の季節ナイーブ予測および第 6 章のグローバルモデルと、同じ時間帯、同じ MASE の尺度で比較して評価する。モデルのうち二つは、実行するのではなく記録済みの結果を用いる。
Prophet の位置づけ
Prophet は、ベースラインの次に読者が試すモデルである。そのため最初に検証する。その仮定が、Prophet が役に立つ場面を決める。
Prophet は時系列を、トレンド、フーリエ項による季節項、祝日効果、誤差項の和として書く。著者らはこれを、分析者がパラメータを読み取って調整できるモジュール式の回帰モデルであると述べている(Taylor and Letham (2018))。既定では、Prophet の当てはめは最大事後確率推定であり、サンプリングされた標本ではなく最適化によって求める。バージョン 1.5.0 のコードは、最適化の呼び出しでこの既定を設定している(models.py、165 行目と 172 行目)。また mcmc_samples 引数の既定値は 0 である(forecaster.py、144 行目)。どちらも固定されたバージョンの Prophet ソース配布物にある。クライアントごとに別々の当てはめを行うため、Prophet は他のクライアントから学習しない。
Prophet にはうまく扱える点がいくつかある。欠測した観測値を補間する必要がない。コードは、当てはめの前に y が欠けている行を除外する(forecaster.py、1335 行目)。時計の切り替えが起こる時間帯は、第 3 章の規則により履歴上では欠測となるが、Prophet は追加のコードなしにそれらを除外する。Prophet は祝日を日付と効果の表として受け取る。この章で検証する表には、2013 年と 2014 年のポルトガルの国民の祝日が入っている。著者らは、自分たちの系列に既定の設定を適用した場合、Prophet の誤差が auto.arima、ETS、季節ナイーブ、TBATS より小さかったと報告している(Taylor and Letham (2018))。この結果は著者らのデータに基づくため、著者らの結果として引用するにとどめ、本件についての根拠としては用いない。
ここでは、いくつかの既定値が妨げとなる。年次の季節性は、履歴が 730 日以上ある場合にのみ有効になる(forecaster.py、1187 行目)。そのため 8 週間の履歴では無効のままである。既定の区間は 95% ではなく 80% である(forecaster.py、145 行目)。この区間が対象とするのは、トレンドの不確実性と観測ノイズであり、完全なサンプリングでモデルを当てはめない限り、季節パターンは含まれない(Prophet documentation)。したがって、その被覆率が主張する内容は、「区間」という語から受ける印象よりも限定的である。Prophet はまた、将来のトレンドが履歴と同じ頻度、同じ大きさで変化すると仮定する(Prophet documentation)。履歴が 8 週間では、トレンドの変化を学習できる材料がほとんどない。このため、予測の大部分はこの仮定が担っていると、我々は読んでいる。
実践ルール: 読者がトレンドと季節性の設定を、読み取れるパラメータとして必要とし、かつ採点した予測が、採点前に選んだ判断対象の期間で季節ナイーブを上回る場合に、クライアントごとに Prophet を使う。区間幅はコードで設定する。既定の 80% 区間は 80% 区間として読み、95% の範囲として読んではならない。被覆率は、モデルが主張する水準に照らして確認する。
この部分はまだ翻訳されていないため、英語で表示している。
Run Prophet on the same cutoffs
The last section named Prophet's assumptions. This one fixes its settings and runs it on the same hours as every other model.
The comparison uses the three standard cutoffs, at 00:00 on Dec 29, Dec 30 and Dec 31, 2014. These are the windows Chapters 4 to 8 score. Each window's history is the 1,344 hours, eight weeks, before its cutoff, with the start rule applied, so a late starter's history begins at its first reading. Prophet is fitted once for each client and cutoff, which makes 90 fits.
We chose the holiday table on decision windows, not on the standard cutoffs. The ordinary decision windows hold no holiday in their scored hours, so they cannot test a holiday table at all, while the holiday decision windows can. So the choice uses both kinds. A run with the table and one without it shows what the table does on those windows for SUBSET8: the four ordinary days and seven holidays, Apr 18, Apr 20, Apr 25, May 1, Jun 10, Aug 15 and Dec 8, 2014. All of them come before the held-out week, and none has Christmas Day in its history.
1"""Prophet with and without the Portuguese holiday table, on the eleven decision windows for SUBSET8 (B-9, B-10),2before any standard cutoff is scored. The point that the table stays off rests on the two mean MASE lines and on3holiday table kept, which says whether the table lowers the mean per-client MASE."""4from lib.compare import prophet_windows, seasonal_naive, score5from lib.electricity import load6from lib.features import is_holiday7from lib.panel import DECISION_CUTOFFS, HOLIDAY_DECISION_CUTOFFS8from lib.quirks import mask_clock_changes9from lib.settings import SUBSET8, show1011# the four ordinary and seven holiday windows, in date order12DECISION = sorted([*DECISION_CUTOFFS, *HOLIDAY_DECISION_CUTOFFS])13raw = load(SUBSET8)14# clock-change hours set to missing, so Prophet fits without them15df = mask_clock_changes(raw)[["unique_id", "ds", "y"]]16keys = ["unique_id", "ds"]17# one fit per client and window, with the Portuguese holidays as Prophet's holiday table; two processes, and the same18# fits at any count19with_holidays = prophet_windows(df, DECISION, use_holidays=True, workers=2)[keys + ["Prophet"]].rename(20 columns={"Prophet": "WithHolidays"})21without = prophet_windows(df, DECISION, use_holidays=False, workers=2)[keys + ["Prophet"]].rename(22 columns={"Prophet": "NoHolidays"})23forecasts = with_holidays.merge(without, on=keys, validate="one_to_one").merge(24 seasonal_naive(df, DECISION), on=keys, validate="one_to_one")25models = ["WithHolidays", "NoHolidays", "SeasonalNaive"]26# per_client: one MASE per client and model; scored: forecasts beside readings27per_client, scored = score(raw, forecasts, models, SUBSET8, DECISION)2829show("decision windows", len(DECISION))30show("holiday decision windows", len(HOLIDAY_DECISION_CUTOFFS))31show("clients", len(SUBSET8))32show("scored hours", len(scored))33# 1 for each hour on a Portuguese national holiday34show("holiday hours in the decision windows", int(is_holiday(scored["ds"]).sum()))35for model in models:36 # the mean of the per-client MASEs, not a pooled error37 show(f"mean MASE {model}", per_client[model].mean(), digits=3)38show("hours where the forecasts differ", int((scored["WithHolidays"] != scored["NoHolidays"]).sum()))39show("clients where holidays help", int((per_client["WithHolidays"] < per_client["NoHolidays"]).sum()))40# the table is kept only on a strictly lower mean; a tie keeps the simpler model, with the table off41show("holiday table kept", "yes" if per_client["WithHolidays"].mean() < per_client["NoHolidays"].mean() else "no")
python prophet-holiday-decision.pydecision windows: 11
holiday decision windows: 7
clients: 8
scored hours: 2112
holiday hours in the decision windows: 1344
mean MASE WithHolidays: 1.070
mean MASE NoHolidays: 1.061
mean MASE SeasonalNaive: 0.934
hours where the forecasts differ: 768
clients where holidays help: 2
holiday table kept: no
On the decision windows the table makes Prophet worse. Over the eleven of them, its mean per-client MASE is 1.070 with the table and 1.061 without it, against 0.934 for seasonal naive.
A setting is kept only if it lowers the decision-window MASE, and a tie keeps the simpler model. The example's verdict on keeping the table is no, so the table stays off.
The holiday windows hold 1344 client-hours of holiday, and they are the only place the table can change a forecast. 768 of the 2112 scored hours differ between the two variants.
The standard cutoffs tell a different story, which we report without using it to choose. Their histories include Christmas Day, and the holiday windows' histories do not. That is a likely reason for the gap, but we did not test which holiday causes it. With the table on, Prophet's mean per-client MASE on the standard cutoffs would be 1.27, against 1.35 with it off. A team that wants the table should test it on its own decision windows before it scores anything.
Daily and weekly seasonality are on, and yearly is off. These are the choices Prophet makes for itself on eight weeks of hourly data: yearly needs at least 730 days, weekly at least two weeks, and daily at least two days of sub-daily data (forecaster.py, lines 1187, 1209 and 1223). We set them explicitly and did not tune them. The interval is 95%, set in code and printed as Prophet interval level, so coverage sits beside the recordings' 95% ranges. Prophet draws its interval samples from numpy's global generator, so the code sets the seed (SEED) before each predict. The fit itself is deterministic.
Every model is scored on the book's one MASE scale: the seasonal naive error in sample, over every reading before Dec 29, 2014, with the clock-change hours masked. A MASE below 1 means the model's error on the scored hours is smaller than seasonal naive's in-sample error. Each client has its own scale, so a large client does not outweigh a small one. The next run fits Prophet for all thirty clients and scores it beside seasonal naive and the global model on this scale, which is the comparison every later result in the chapter uses.
1"""Prophet for each of the thirty clients on the three standard cutoffs, with a 95% interval, scored on the book's MASE2scale beside seasonal naive and the Chapter 6 global model. The point that Prophet's mean MASE is higher rests on3the mean MASE lines, and the coverage line says whether its 95% interval holds."""4import pandas as pd56from lib.compare import (PROPHET_HOLIDAYS, PROPHET_LEVEL, global_forecasts, prophet_windows, report_range,7 report_subset, score, seasonal_naive)8from lib.electricity import load9from lib.panel import ALL3010from lib.quirks import mask_clock_changes11from lib.scoring import report_scores12from lib.settings import EVAL_CUTOFFS, show1314raw = load(ALL30)15# clock-change hours set to missing, as chapter 3 sets them16df = mask_clock_changes(raw)[["unique_id", "ds", "y"]]17cutoffs = pd.DatetimeIndex(EVAL_CUTOFFS)18# Prophet at the book's settings from lib.compare: holiday table off, 95% interval, one fit per client and cutoff19forecasts = prophet_windows(df, cutoffs).merge(20 seasonal_naive(df, cutoffs), on=["unique_id", "ds"], validate="one_to_one").merge(21 global_forecasts(df, cutoffs), on=["unique_id", "ds"], validate="one_to_one")22models = ["Prophet", "SeasonalNaive", "Global"]23# per_client: one MASE per client and model; scored: forecasts beside readings24per_client, scored = score(raw, forecasts, models, ALL30)2526show("Prophet interval level", PROPHET_LEVEL)27show("Prophet holiday table", "on" if PROPHET_HOLIDAYS else "off")28show("clients scored", scored["unique_id"].nunique())29show("scored hours", len(scored))30show("clients where Prophet beats seasonal naive", int((per_client["Prophet"] < per_client["SeasonalNaive"]).sum()))31show("clients where Prophet beats the global model", int((per_client["Prophet"] < per_client["Global"]).sum()))32report_scores(scored, per_client, models)33report_subset(per_client, models)34# the 95% range from Prophet's lower and upper interval columns35report_range(scored, "Prophet", "ProphetLo", "ProphetHi", PROPHET_LEVEL)36# Sensitivity only, not used to choose: the holiday table on the same cutoffs, which the decision windows37# did not favour.38# two processes; each fit is the same at any worker count39on = prophet_windows(df, cutoffs, use_holidays=True, workers=2)[["unique_id", "ds", "Prophet"]].rename(40 columns={"Prophet": "ProphetHolidays"})41per_holiday, _ = score(raw, forecasts.merge(on, on=["unique_id", "ds"], validate="one_to_one"),42 ["ProphetHolidays"], ALL30)43show("mean MASE Prophet with holidays, not chosen", per_holiday["ProphetHolidays"].mean())
python prophet-thirty-clients-backtest.pyProphet interval level: 95
Prophet holiday table: off
clients scored: 30
scored hours: 2160
clients where Prophet beats seasonal naive: 9
clients where Prophet beats the global model: 6
MAE Prophet: 182.44
MAE SeasonalNaive: 148.26
MAE Global: 122.81
RMSE Prophet: 764.88
RMSE SeasonalNaive: 780.48
RMSE Global: 678.81
mean MASE Prophet: 1.35
mean MASE SeasonalNaive: 1.18
mean MASE Global: 0.91
mean MASE Prophet SUBSET8: 1.39
mean MASE SeasonalNaive SUBSET8: 1.16
mean MASE Global SUBSET8: 1.03
coverage 95 Prophet: 0.918
interval score 95 Prophet: 932.66
mean MASE Prophet with holidays, not chosen: 1.27
On these cutoffs Prophet has a higher mean per-client MASE than seasonal naive: 1.35 over the thirty clients, against 1.18 for seasonal naive and 0.91 for the global model.
The loss is on most clients too, not only on average: Prophet beats seasonal naive on only 9 of the thirty clients, and the global model on 6.
Pooled over every scored hour, Prophet's RMSE is 764.88 kWh, against 780.48 for seasonal naive, so it makes fewer very large misses. It loses to seasonal naive on MAE and MASE, and to the global model on every measure. Its 95% interval covers 0.918 of the readings, and its interval score is 932.66. Coverage below 0.95 means the interval is too narrow for its stated level on these hours.
Working rule: 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
Prophet fits each client from its own eight weeks. A foundation model brings what it learned from other series, and this section shows how the book holds its forecasts.
A foundation model is trained once on many series and then applied to a context, with no fitting on that series. Chronos-2 is one such model. Chronos-2 is an encoder-only transformer that takes a context of past values and outputs quantiles for the next steps (Ansari et al. (2025); the earlier Chronos model is described in Ansari et al. (2024)). Its weights are published as amazon/chronos-2 on Hugging Face under the Apache-2.0 licence, not gated (model card).
Its pretraining covers this dataset, which limits how far its score can be read. The Chronos-2 report lists the electricity dataset in its pretraining corpus. Appendix A, Table 6 gives "Electricity", with 370 series in the energy domain (Ansari et al. (2025)). Those series match the UCI ElectricityLoadDiagrams20112014 dataset the book reads, and the book's thirty clients are drawn from them. The report notes partial overlap with some GIFT-Eval training portions. For strictly zero-shot results it points to a variant trained only on synthetic data, in its Section 5.4. We have not run that variant. The report does not show which readings of these clients the model saw, so the scores below are upper bounds, not out-of-sample results.
We do not run Chronos-2 in an example. Its forecasts are recorded: the model ran once, outside the examples, on a CPU, with the revision pinned to 29ec3766d36d6f73f0696f85560a422f50e8498c, and the examples read the saved output. The recording is dated Nov 10, 2026. Examples must run offline and give the same output every time, and a model call does neither. A downloaded model can change, and a reader's machine may not hold the files at all.
The input for each client and cutoff is the 1,344 hours before the cutoff, with the start rule applied. None of the standard cutoffs needs that step. Their histories begin on Nov 3, 2014 or later, after the autumn clock change, and the three late starters had their first readings before Nov 3, 2014. The manifest counts no missing values in the contexts, so the clock-change handling changes no scored number here. The package builds a mask from missing values and scales around them (chronos-forecasting source, chronos2/model.py, line 398). The 90 contexts went in one batch, with each series kept separate. Cross-learning, which would let one series inform another, is off by default, and the recording does not turn it on (chronos2/pipeline.py, line 833). So the Dec 30 context does not inform the Dec 29 forecast.
The output is, for each client, cutoff and hour, five quantiles for the next 24 hours: 0.025, 0.1, 0.5, 0.9 and 0.975. That is 2160 rows in all. The manifest lists the SHA-256 of the output and of inputs.csv.gz, which keeps the exact context each window was given, along with the package versions and the machine, described only as a 4-vCPU Linux container with no GPU.
Not every requested quantile is trained. The package is trained on 21 levels, from 0.01 to 0.99 (Ansari et al. (2025)). The levels 0.1, 0.5 and 0.9 are among them, so they are read directly. The levels 0.025 and 0.975 are not, so the package interpolates each one linearly between the two nearest trained levels: 0.01 and 0.05 for the lower, and 0.95 and 0.99 for the upper. The code is interpolate_quantiles in chronos/utils.py, called from predict_quantiles in chronos2/pipeline.py (chronos-forecasting source). The manifest names the interpolated levels, and a 95% range built from them is partly the package's interpolation.
Before any score reads the recording, run the check. It hashes each output and compares it with manifest.json, counts the rows, clients and cutoffs in the forecast file, and looks for quantiles that run out of order.
1"""Checks the recorded Chronos-2 outputs before any score reads them: each file's SHA-256 against manifest.json, the2shape of the forecast file, and any quantiles out of order, without running the model. The point that the recording3is intact rests on the hash mismatches line and the rows with quantiles out of order line."""4from lib.compare import check_recording5from lib.settings import show67for label, value in check_recording().items(): # the default name is the chronos-2 folder in examples/data/recorded/8 show(label, value)
python recorded-chronos2-check.pyoutputs checked: 2
hash mismatches: 0
rows: 2160
clients: 30
windows: 3
interpolated levels: 2
rows with quantiles out of order: 0
largest quantile crossing, kWh: 0.00
inverted 80 or 95 ranges: 0
The recording is intact: 0 of its 2 outputs fail their hashes, and 0 rows have quantiles out of order. The check verifies the output files, not the prompt hash, which covers the input and the configuration.
The licence decides which weights the book can run or record: this book uses only Apache-2.0 or MIT weights. Chronos-2's weights and the chronos-forecasting package are Apache-2.0 (model card; package metadata). Two other families were considered and are not used. The TimesFM 3.0 weights carry a non-commercial licence, which allows non-commercial and non-production use only (TimesFM 3.0 licence). TimesFM 2.5 is Apache-2.0 (TimesFM 2.5 card), so the licence depends on the version named. The Moirai R-series checkpoints are tagged CC-BY-NC-4.0, which is also non-commercial (Moirai 2.0 card).
A later edition can run Chronos-2 live once its weights and package fit the release service's limits. Until then the recording stands in for the live run.
Working rule: 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.
同じカットオフで記録を採点する
記録が意味を持つのは、Prophet やベースラインと同じ時間帯で採点した場合に限られる。
5 つの分位点を持つ予測は、2 通りの方法で採点できる。中央値、すなわち 0.5 分位点は点予測であり、本書のスケールで MASE を用いて採点する。0.1 分位点と 0.9 分位点は 80% 範囲を、0.025 分位点と 0.975 分位点は 95% 範囲を構成する。各範囲は、範囲内に収まった測定値の割合であるカバレッジと、幅に範囲外の各測定値へのペナルティを加えた区間スコアで採点する。ペナルティは、2 を名目上の外れ率(95% 範囲では 0.05)で割った値に、範囲外への距離を掛けたものである。第 8 章では、区間スコアをその出典とともに定義している。各分位点は分位点損失でも採点する。これは、測定値が分位点より上に外れる場合は 1 kWh ごとに tau を、下に外れる場合は 1 kWh ごとに 1 − tau を課すものである(第 8 章)。
記録の採点には 2 つの例を用い、モデルごとに 1 つずつ、Prophet の実行と同じ 30 クライアント、同じカットオフ、同じ MASE スケールで行う。いずれの例も、第 6 章から流用せずにグローバルモデルと季節ナイーブを作り直すため、すべてのモデルが 1 本の採点経路を通る。
1"""Scores the recorded Chronos-2 forecasts on the three standard cutoffs and the MASE scale of the other models: the2median is the point forecast, the 0.1 and 0.9 quantiles the 80% range, and the 0.025 and 0.975 quantiles the 95%3range. The point about the lead rests on the mean MASE lines, and the code reads the recording only, never the4model."""5import pandas as pd67from lib.compare import (global_forecasts, recorded_forecasts, report_pinball, report_range, report_subset, score,8 seasonal_naive)9from lib.electricity import load10from lib.panel import ALL3011from lib.quirks import mask_clock_changes12from lib.scoring import report_scores13from lib.settings import EVAL_CUTOFFS, show1415raw = load(ALL30)16# clock-change hours set to missing, as chapter 3 sets them17df = mask_clock_changes(raw)[["unique_id", "ds", "y"]]18cutoffs = pd.DatetimeIndex(EVAL_CUTOFFS)19# the recording, read only after each output matches its manifest hash; its median is the Chronos column20forecasts = recorded_forecasts().merge(21 seasonal_naive(df, cutoffs), on=["unique_id", "ds"], validate="one_to_one").merge(22 global_forecasts(df, cutoffs), on=["unique_id", "ds"], validate="one_to_one")23models = ["Chronos", "SeasonalNaive", "Global"]24# per_client: one MASE per client and model; scored: forecasts beside readings25per_client, scored = score(raw, forecasts, models, ALL30)2627show("clients scored", scored["unique_id"].nunique())28show("scored hours", len(scored))29show("clients where Chronos beats seasonal naive", int((per_client["Chronos"] < per_client["SeasonalNaive"]).sum()))30report_scores(scored, per_client, models)31report_subset(per_client, models)32report_pinball(scored, "Chronos", "q10", 0.1) # quantile loss at tau 0.1: the 0.1 quantile column33report_pinball(scored, "Chronos", "q50", 0.5) # at tau 0.5 the loss is half the absolute error34report_pinball(scored, "Chronos", "q90", 0.9)35report_range(scored, "Chronos", "q10", "q90", 80)36report_range(scored, "Chronos", "q025", "q975", 95)
python recorded-chronos2-score.pyclients scored: 30
scored hours: 2160
clients where Chronos beats seasonal naive: 27
MAE Chronos: 100.13
MAE SeasonalNaive: 148.26
MAE Global: 122.81
RMSE Chronos: 655.39
RMSE SeasonalNaive: 780.48
RMSE Global: 678.81
mean MASE Chronos: 0.81
mean MASE SeasonalNaive: 1.18
mean MASE Global: 0.91
mean MASE Chronos SUBSET8: 0.87
mean MASE SeasonalNaive SUBSET8: 1.16
mean MASE Global SUBSET8: 1.03
quantile loss 0.1 Chronos: 39.44
quantile loss 0.5 Chronos: 50.07
quantile loss 0.9 Chronos: 17.85
coverage 80 Chronos: 0.749
interval score 80 Chronos: 572.89
coverage 95 Chronos: 0.944
interval score 95 Chronos: 958.19
1"""Scores the recorded NHITS forecasts on the same three cutoffs and MASE scale as Chronos-2 and the other models: the2median is the point forecast, and each range comes from levels trained directly, so none is interpolated. The point3about its ranges rests on the coverage and interval score lines, and the code reads the recording only, never the4model."""5import pandas as pd67from lib.compare import (global_forecasts, recorded_forecasts, report_pinball, report_range, report_subset, score,8 seasonal_naive)9from lib.electricity import load10from lib.panel import ALL3011from lib.quirks import mask_clock_changes12from lib.scoring import report_scores13from lib.settings import EVAL_CUTOFFS, show1415raw = load(ALL30)16# clock-change hours set to missing, as chapter 3 sets them17df = mask_clock_changes(raw)[["unique_id", "ds", "y"]]18cutoffs = pd.DatetimeIndex(EVAL_CUTOFFS)19# the NHITS recording, read only after each output matches its manifest hash; its median is the NHITS column20forecasts = recorded_forecasts("nhits", "NHITS").merge(21 seasonal_naive(df, cutoffs), on=["unique_id", "ds"], validate="one_to_one").merge(22 global_forecasts(df, cutoffs), on=["unique_id", "ds"], validate="one_to_one")23models = ["NHITS", "SeasonalNaive", "Global"]24# per_client: one MASE per client and model; scored: forecasts beside readings25per_client, scored = score(raw, forecasts, models, ALL30)2627show("clients scored", scored["unique_id"].nunique())28show("scored hours", len(scored))29show("clients where NHITS beats seasonal naive", int((per_client["NHITS"] < per_client["SeasonalNaive"]).sum()))30report_scores(scored, per_client, models)31report_subset(per_client, models)32report_pinball(scored, "NHITS", "q10", 0.1) # quantile loss at tau 0.1: the 0.1 quantile column33report_pinball(scored, "NHITS", "q50", 0.5) # at tau 0.5 the loss is half the absolute error34report_pinball(scored, "NHITS", "q90", 0.9)35report_range(scored, "NHITS", "q10", "q90", 80)36report_range(scored, "NHITS", "q025", "q975", 95)
python recorded-nhits-score.pyclients scored: 30
scored hours: 2160
clients where NHITS beats seasonal naive: 24
MAE NHITS: 136.61
MAE SeasonalNaive: 148.26
MAE Global: 122.81
RMSE NHITS: 649.41
RMSE SeasonalNaive: 780.48
RMSE Global: 678.81
mean MASE NHITS: 1.03
mean MASE SeasonalNaive: 1.18
mean MASE Global: 0.91
mean MASE NHITS SUBSET8: 1.17
mean MASE SeasonalNaive SUBSET8: 1.16
mean MASE Global SUBSET8: 1.03
quantile loss 0.1 NHITS: 27.66
quantile loss 0.5 NHITS: 68.31
quantile loss 0.9 NHITS: 40.58
coverage 80 NHITS: 0.700
interval score 80 NHITS: 682.37
coverage 95 NHITS: 0.877
interval score 95 NHITS: 1250.94
| モデル | 平均 MASE、ALL30 | 平均 MASE、SUBSET8 | MAE、ALL30 (kWh) |
|---|---|---|---|
| 季節ナイーブ | 1.18 | 1.16 | 148.26 |
| グローバルモデル(第 6 章) | 0.91 | 1.03 | 122.81 |
| Chronos-2、中央値 | 0.81 | 0.87 | 100.13 |
| NHITS、中央値 | 1.03 | 1.17 | 136.61 |
| Prophet、点予測 | 1.35 | 1.39 | 182.44 |
Chronos-2 は、どちらのクライアント集合でも 5 つのモデルの中でクライアントごとの平均 MASE が最も低い。30 クライアント全体で 0.81、SUBSET8 で 0.87 である。30 クライアントのうち 27 で季節ナイーブを上回る。第 6 章のグローバルモデルは、どちらの集合でも 2 位である。同じ 8 クライアント、同じカットオフ、同じスケールでの第 4 章の固定季節 ARIMAは、SUBSET8 で 1.09 となり、グローバルモデルと季節ナイーブの間に位置する。
NHITS は、30 クライアントでは 3 位、SUBSET8 では 4 位であり、後者では季節ナイーブにわずかに及ばない(1.17 対 1.16)。Prophet は、どちらの集合でも平均が最も高い。
この首位には注意書きが必要である。Chronos-2 の事前学習コーパスにはこのデータセットが含まれているため(記録の節)、これらの測定値は学習に使われた可能性があり、ここでの成績は、見たことのない測定値で期待できる成績の上限を示すものである(良く見積もりすぎている可能性がある)。NHITS にはそのような利点はなく、各カットオフはそのカットオフ自身のコンテキストだけで学習されている。NHITS は同じ時間帯で Chronos-2 に後れを取るが、両者は対等な条件にはなく、本章ではこの比較で両者に順位をつけない。
中央値は、分位点の計算の検算にもなる。0.5 でのピンボール損失は絶対誤差の半分なので、中央値の損失はその MAE の半分になるはずである。Chronos-2 では、0.5 での損失が 50.07 であり、MAE 100.13 kWh を 2 で割った値と比べられる。NHITS では、0.5 での損失が 68.31 であり、MAE 136.61 kWh の半分に対応する。
Chronos-2 の 95% 範囲は測定値の 0.944 をカバーし、水準に近い。80% 範囲は 0.749 をカバーし、水準の 0.80 をやや下回る。Chronos-2 の 95% 範囲は一部が補間されているため、その得点はモデルとパッケージを合わせたものに対するものである。
Prophet の 95% 範囲の区間スコアは Chronos-2 よりやや低く、932.66 対 958.19 だが、カバレッジの 0.918 は水準からより離れている。
NHITS の範囲は、これらの時間帯では水準に対して狭すぎる。80% 範囲は測定値の 0.700 を、95% 範囲は 0.877 をカバーするにとどまる。
その 95% 区間スコアは、3 つの 95% 範囲の中で最も高く、分位点は直接学習されているため、補間された範囲はない。ただし、記録では分位点が順序どおりに並んでいない。検査では、隣り合う分位点の組が逆順になっている行が 22 行あり、その差は最大 21.11 kWh で、80% 範囲または 95% 範囲が逆転しているものが 0 件ある。スコアは記録されたままの値を用いている。
3 つの制約がある。これらは 1 つのデータセットの 1 週間における 3 つのカットオフであり、結果はどのモデルについても一般的な主張にはならない。どちらの範囲も、第 8 章で用いた較正ウィンドウでは較正されておらず、ここでのカバレッジは較正ではなく検査である。この比較は選択を行わない。本書での判断は判断ウィンドウで行うが、記録にはそこでの予測がなく、これらの得点では何も選ばないからである。
実践ルール: 記録された予測は、ほかのすべてのモデルと同じウィンドウ、同じスケール、同じ測定値で採点し、補間された分位点は、その範囲を報告するたびに明記する。首位を読む前に、そのモデルが何で学習されたかを確認する。採点対象の測定値を見たモデルは、それらについて技能を示せないからである。これらのウィンドウでモデルや設定を選んではならない。判断ウィンドウでの予測がない記録された予測は、それを備えるまで本番用に選べない。
ニューラルモデルを記録として扱う理由
この版ではニューラルモデルを実行しない。2 つのニューラル予測は記録として用意してあり、その理由は実行環境のコストにある。ニューラルモデルを否定する判断ではない。
NHITS は neuralforecast ライブラリのニューラル予測器である。neuralforecast は、複数の系列からなるパネルデータ向けにニューラル予測器をまとめたライブラリであり、ライセンスは Apache-2.0 である(neuralforecast metadata)。NHITS は Chronos-2 と同じ方法で記録する。つまり、専用のスクリプト、固定されたバージョン、マニフェストを用意し、同じ文脈、同じカットオフ、同じスケール、同じ指標で Chronos-2 と並べて採点する。記録の際は、Chronos-2 に与えたものと同じ 30 本の 1,344 時間の文脈を使い、カットオフごとに 1 回ずつ学習する。入力ウィンドウは 168 時間(1 週間)、予測期間は 24 時間である。5 つの水準は MQLoss 損失のもとで直接学習し、水準ごとに 1 つの出力を持たせる。スケーラーは neuralforecast の標準スケーラーを用い、乱数シードは固定し、実行は CPU で行う。各カットオフのモデルはそのカットオフの文脈だけを見るので、カットオフ後の観測値がモデルに届くことはない。重みは配布しない。
NHITS にも、自身のマニフェストにあるハッシュと照合する同じ検査を行う。
1"""Checks the recorded NHITS outputs before any score reads them: each file's SHA-256 against manifest.json, the shape2of the forecast file, and any quantiles out of order, without running the model. The point that the recording is3intact rests on the hash mismatches line; the interpolated levels line shows that every level is trained directly, and4the rows with quantiles out of order line is the one the chapter reports."""5from lib.compare import check_recording6from lib.settings import show78for label, value in check_recording("nhits").items(): # "nhits" is the NHITS folder in examples/data/recorded/9 show(label, value)
python recorded-nhits-check.pyoutputs checked: 1
hash mismatches: 0
rows: 2160
clients: 30
windows: 3
interpolated levels: 0
rows with quantiles out of order: 22
largest quantile crossing, kWh: 21.11
inverted 80 or 95 ranges: 0
NHITS のファイルはマニフェストと一致しており、どの水準も補間されていない。各水準を直接学習しているためである。
2 つのコストが、NHITS を例から外す理由である。このライブラリは torch、ray、pytorch-lightning を持ち込み、例の環境は 687 MB から 1.7 GB に膨らむ。また、CPU での学習は、リリースサービスの 2 vCPU とメモリ 4 GiB では、例に許容される時間より長くかかる。バージョンの衝突は関係しない。NHITS の requirements ファイルである recordings/requirements-nhits.txt は、例が固定している pandas と同じバージョン(2.3.3)で neuralforecast をインストールする。
Chronos-2 は独自のスタックを持つ。その requirements ファイルである recordings/requirements.txt は、transformers と torch とともに chronos-forecasting をインストールし、記録のために pandas 3 を固定している。このパッケージは pandas 3 を必要としない。メタデータは pandas 2.0 以上 4 未満を受け入れる(chronos-forecasting source、pyproject.toml)。例はどちらのパッケージもインポートしない。保存された出力を読み込むだけである。
リリースサービスの制限に収まる実行環境が整うか、NHITS 専用の実行環境が用意できれば、NHITS を後の版でライブ実行できる。どちらの場合でも、この章のウィンドウ、スケール、採点は変わらないので、後から加えるモデルも同じ時間帯で他のモデルと並べて採点できる。
実践ルール: 依存関係が実行環境の予算を超えるモデルは、例の実行環境に入れず、記録として扱い、そのモデルの固定バージョンは別の requirements ファイルに置く。依存関係を追加する前に、クリーンな環境にインストールし、サイズとパッケージ数がどれだけ増えるかを測る。依存関係の解決によって固定済みのパッケージのバージョンが動く場合、それはモデルを記録として扱う理由であり、固定を変更する理由ではない。
この部分はまだ翻訳されていないため、英語で表示している。
What goes wrong in production
Prophet's holiday table covers 2013 and 2014 only. The book's runs leave it off, because the holiday decision windows gave no reason to turn it on, but the standard cutoffs show that it moves the result. A forecast made in 2015 with the table unchanged gets no holiday effect on later holidays, and the run reports nothing wrong. A team that turns the table on must extend it to the forecast's years. Holidays are known in advance, so the fix is to extend the table. Count the holiday hours in each window as well. A window that contains a holiday should show a count above zero, and a count of zero where a holiday falls is the sign to look for.
Interval width fails differently: a Prophet interval left at its default of 80% gets read as a 95% range by a reader who sees only the word "interval" in a report. The coverage line is the check. Printed beside its level, a coverage near 0.8 is correct for an 80% interval and a failure for a 95% one. Print the level with the coverage every time.
A recorded forecast goes stale in a different way. The recording covers three cutoffs. A day-ahead forecast in production needs one cutoff every day, and the release service does not run the model. Covering another cutoff means running the model, saving its output and hashing it, which is work outside the examples. The sign that the recording is out of date is a window with no rows in the file, which the check's window count shows.
A later model revision changes every number that depends on the recording, even when the code does not change. Treat the revision as an update trigger. Record it, score it on the same windows as the old one, and compare the two before the replacement recording is used. A package that changes its interpolation between versions changes the 95% range without touching the median, so the manifest's list of interpolated levels should be compared as well.
A recorded forecast can also break the order of its own quantiles. The NHITS recording does in 22 of its 2160 rows, by at most 21.11 kWh. A range built from a crossed pair would be read as inverted. The check counts the crossings, and a consumer should sort or reject such rows before it uses them.
Prophet's trend assumption fails when a client's demand moves to a different level, as it does after a change of contract or the loss of a large load. Prophet expects the trend to change as often as it did in the history, and its default interval does not cover the seasonal pattern. The sign is residuals that keep one sign across successive windows, and a coverage line that falls over them. The fix is a refit on a shorter history for that client, not a wider interval.
Working rule: 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.
この章で下した決定
- Prophet は
SUBSET8だけでなく、30 のクライアントすべてで実行する。 30 すべてで実行することで、Prophet を同じクライアント上でグローバルモデルと並べて比較できる。SUBSET8の平均値は同じ実行から出力している。 - Prophet の区間は 95% とし、コードで設定して出力する。 こうすることで、Prophet のカバレッジと区間スコアを、各記録の 95% 範囲と並べて比較できる。既定の 80% は用いない。
- Prophet の季節性フラグはコードで固定する。 日単位と週単位の季節性は有効にし、年単位は無効にする。これらは、8 週間の毎時データに対して Prophet が選ぶ設定であり、ここでは明示的に指定している。
- 祝日テーブルは使わない。 祝日の決定ウィンドウでは、このテーブルによって平均 MASE が上がったため、より単純なモデルを採用した。標準のカットオフでは、このテーブルによって Prophet の平均 MASE は下がるが、その値は選択には用いず、報告のみを行う。
- Chronos-2 と NHITS は実行せず、記録として扱う。 例では、保存済みの出力を読み込み、そのハッシュを検査するだけで、モデルは一切呼び出さない。例はオフラインで実行でき、毎回同じ出力を返す必要があるためである。
- NHITS は実行時コストの観点から記録として扱う。 NHITS の依存関係を入れると、例の実行環境は 687 MB から 1.7 GB に増え、リリースサービスの 2 vCPU と 4 GiB を超える。また、CPU での学習は、例として許容できる時間を超える。
- Chronos-2 の 95% 範囲は、補間した 2 つの分位点で採点し、その旨を章に明記する。 NHITS の分位点は直接学習したものであるため、補間された範囲は一つもない。
- Chronos-2 の優位は上限として読む。 事前学習コーパスにこのデータセットが含まれているため、ここでのスコアは標本外のものではない。
- 選択は決定ウィンドウのみから行う。 各記録にはそこでの予測がないため、この章では記録を用いた選択は行わない。
この版における本章
第2026.11.11版2026年11月20日時点で例が通過この章の6 例件のうち6件が合格
英語版の書籍(版2026.11.11)から翻訳した。