モデルが超えるべきベースラインを定める

読了まで約45 分分、7 節 節の 2 例 例。

第2026.11.11版 2026年11月20日時点で例が通過 41 例中 41 例が合格 変更点

AIによる翻訳。英語版は人による検証済みである。 当社の書籍の作り方

英語版の書籍(版2026.11.11)から翻訳した。 原文を読む

本章では、ある顧客の翌日需要予測に対して、ナイーブ予測、季節ナイーブ予測、週平均予測の三つのベースラインを計算する。さらに、予測対象の週より前の測定値だけから求めたスケールを用いて、その顧客の誤差を MASE で尺度化する。

第1章は、ホールドアウトした週について二つのスコアを示して終わった。しかし、kWh で表した誤差はそれ単独では何も意味しないため、どちらのスコアもまだ評価できない。各時間帯の予測に基づいて電力を購入する供給事業者は、各モデルの誤差を、同じ時間帯で最も単純な予測が記録するスコアと比べなければならない。あわせて、その顧客の需要が日ごとにどの程度変動するかとも比べなければならない。本章はこの二つの比較を構築する。供給事業者は、モデルが費用に見合う価値を持つと言えるようになる前に、この二つの比較を必要とする。

すべての誤差は、ある1時間における kWh 単位の外れであり、ここでのスコアはそれらの外れの1時間あたりの平均である。ベースラインのスコアも同種の数値である。それは、最も単純な規則が1日の平均的な1時間に残す誤差が何 kWh かを表しており、この値を下回れないモデルは、追加の費用に見合う成果を挙げていない。そのため、各スコアは、ほかの行と比べるだけでなく、主要顧客の平均需要とも照らして読む。

なぜ最初にベースラインを置くのか

最終変更:版2026.11.11

ベースラインとは、モデルの当てはめを必要としない予測である。履歴がすでに持っている値を写し取るだけなので、実行にかかる費用はほとんどなく、どのモデルも超えなければならない基準を与える。モデルが採用に値するのは、費用のかからない予測を上回ったときだけである。当てはめの時間、チューニング、モデルの運用の継続はいずれも費用であり、ベースラインのスコアは、それらの費用で何が得られるかを測る尺度になる。

ここで重要な用語が三つある。カットオフは、予測を行う時刻(1時間単位の時刻)である。カットオフは予測が対象とする最初の時刻であり、履歴とはカットオフより前のすべての観測値を指す。ホライズンは、予測がどれだけ先まで届くかを表し、ここでは24時間である。ウィンドウは、一つのカットオフと、それが対象とするホライズンとの組である。バックテストとは多数のウィンドウのスコアであり、各ウィンドウはその日に実際に行われたはずの方法で作られる。

比較は公平でなければならない。公平でなければ、モデルではなく設定を測ることになる。異なる時刻、異なる履歴、異なる採点処理で評価されたベースラインは、隣に並べたモデルについて何も語らない。そのため、この章のすべての手法は、カットオフをheld_out_cutoffs()から取り(保留期間の週の00:00における毎日7回のカットオフである)、履歴をhistory_before()を通して読み(カットオフより前の8週間分の時刻を取得する)、同一のコードで採点される。これらは第1章で用いた7つのウィンドウである。

実践ルール: すべてのベースラインを、比較対象となるモデルと同じウィンドウ、履歴、採点コードで採点し、スコアを読む前に各ベースラインの欠損した予測を数えること。異なる時刻で採点されたベースラインを上回ったモデルは、そのベースラインに勝ったことにはならない。

この部分はまだ翻訳されていないため、英語で表示している。

Three baselines to beat

最終変更:版2026.11.11

Each baseline copies the history in a different way. Naive carries the last hour it has seen forward across the whole day. Seasonal naive copies the day before, hour for hour. Average of weeks takes the mean of that hour on that weekday over the four weeks before.

Every rule covers the 24 hours after a cutoff. Call the cutoff T, the hour at which the forecast is made, and let k run from 0 to 23 across the hours the forecast covers. The three rules are these:

  • Naive repeats the last reading before the cutoff: forecast(T + k) = y(T - 1).
  • Seasonal naive repeats the reading one day earlier: forecast(T + k) = y(T + k - 24).
  • Average of weeks takes the mean of the same hour on the same weekday over the four weeks before: forecast(T + k) = (y(T + k - 168) + y(T + k - 336) + y(T + k - 504) + y(T + k - 672)) / 4.

The lags are in hours, so 168 is one week. Every reading a rule uses comes from before the cutoff: naive's is the hour before it, seasonal naive's are the 24 hours before it, and average of weeks reaches back one to four weeks. Take the window at 00:00 on Dec 25, 2014 as a worked case. Naive gives every hour of Dec 25 the reading at 23:00 on Dec 24, so the forecast is flat. Seasonal naive gives 00:00 on Dec 25 the reading at 00:00 on Dec 24, and so copies the whole previous day's shape. Average of weeks gives 00:00 on Dec 25 the mean of the 00:00 readings on Dec 18, Dec 11, Dec 4 and Nov 27. That mean smooths out one unusual day, but it also averages in any level change across the four weeks.

Each rule fails in a known way. Naive gives every hour of the day the same value, so it cannot follow the daily peak at all. Seasonal naive copies one day, so an unusual day is copied into the forecast for the next day, as the per-day errors later in this section show on the held-out week. Average of weeks needs four clean weeks, and a holiday in any of them enters the mean with the same weight as an ordinary day. A baseline's score therefore describes its rule on the windows it was run on, and these failures show up only on the windows where they happen.

Naive and seasonal naive come from statsforecast (2.1.1), whose classes Naive and SeasonalNaive are in statsforecast/models.py. The seasonal naive rule is the one Hyndman and Athanasopoulos give for seasonal data: the forecast is the last observed value from the same season. Average of weeks is not a library method, so examples/lib/baselines.py computes it in pandas, where the rule can be read, and each window reads only its own history. A lag missing from that history raises an error instead of being skipped. One script scores all three rules through those seven windows, and its first lines count the windows, scored hours and missing forecasts, so you can check them before you read a score.

naive-baselines-held-out-week.py Python 3.13.16 · numpy 2.5.5 · pandas 2.3.3 · statsforecast 2.1.1 · utilsforecast 0.2.17 合格
"""Score the three baselines for the lead client over the held-out week, on the same seven windows. The point rests on the missing-forecasts line, which must be zero for the scores to compare, and on the three MAE lines."""import pandas as pdfrom lib.backtest import held_out_cutoffs, score_windows, window_maefrom lib.baselines import BASELINES, baseline_forecastsfrom lib.electricity import loadfrom lib.settings import LEAD, showcutoffs = held_out_cutoffs()                                 # seven daily cutoffs at 00:00; every baseline uses these same windowsdf = load([LEAD])[["unique_id", "ds", "y"]]                  # unique_id, ds and y only: the baselines read no other columnforecasts = baseline_forecasts(df, cutoffs)                  # one row per forecast hour, one column per baseline; each window reads its own historylabels = ["naive", "seasonal naive", "average of weeks"]     # printed names, in the order of BASELINES, which the loops below zip withshow("windows", len(cutoffs))show("scored hours", len(forecasts))show("missing forecasts", int(forecasts[BASELINES].isna().sum().sum()))   # NaN marks a forecast that could not be made; the two sums count them over every columnshow("mean demand", df[df["ds"].isin(forecasts["ds"])]["y"].mean())       # the mean over the scored hours only, not over the whole historyfor model, label in zip(BASELINES, labels):    show(f"{label} MAE", score_windows(df, forecasts, model)["mae"])      # pooled over every scored hour; the result is keyed by metric namefor model, label in zip(BASELINES, labels):    per_window = window_mae(df, forecasts, model)                         # one MAE per window, keyed by the day its forecast hours fall on    show(f"{label} worst window MAE", per_window.max())    show(f"{label} worst window", per_window.idxmax().strftime("%b %d, %Y"))    for day in ["2014-12-25", "2014-12-26"]:                              # Dec 25 is the holiday and Dec 26 the day after: the two windows the prose reads        show(f"{label} MAE {pd.Timestamp(day):%b %d} window", per_window[pd.Timestamp(day)])   # windows are keyed by midnight of their day, so a Timestamp at 00:00 finds one
出力python naive-baselines-held-out-week.py
windows: 7
scored hours: 168
missing forecasts: 0
mean demand: 46.62
naive MAE: 8.16
seasonal naive MAE: 8.36
average of weeks MAE: 8.96
naive worst window MAE: 11.01
naive worst window: Dec 30, 2014
naive MAE Dec 25 window: 5.84
naive MAE Dec 26 window: 10.36
seasonal naive worst window MAE: 12.16
seasonal naive worst window: Dec 26, 2014
seasonal naive MAE Dec 25 window: 9.41
seasonal naive MAE Dec 26 window: 12.16
average of weeks worst window MAE: 22.09
average of weeks worst window: Dec 25, 2014
average of weeks MAE Dec 25 window: 22.09
average of weeks MAE Dec 26 window: 12.33

The three scores are comparable only because they cover the same hours: 168 scored hours in 7 windows, one for each hour of the seven days, and 0 missing forecasts across the three rules. That count is the one the working rule in the first section asks for, and zero is the only value that lets the three be compared on the same hours.

Read each error below against the lead client's mean demand of 46.62 kWh. Each score below is a MAE, the mean absolute miss in kWh that Chapter 1 defines. The three baselines score:

  • naive: 8.16 kWh
  • seasonal naive: 8.36 kWh
  • average of weeks: 8.96 kWh

The simplest rule has the lowest error on this week, and average of weeks, which averages four weeks, is the weakest. Nothing here explains that order, and this is one client and one week, so it is a result for this week only. Chapter 3 is where the book backtests seasonal naive across many cutoffs.

The totals hide where the errors sit. The week begins on Dec 25, 2014, a Portuguese national holiday, and its first window is where the rules part company. Naive has the lowest error on it, at 5.84 kWh, against 9.41 kWh for seasonal naive. Average of weeks is worse still, and its largest error of the week falls on that window, at 22.09 kWh, because its four lags are ordinary days and the holiday has no match among them.

The day after the holiday is where copying costs seasonal naive. Its largest error of the week falls on Dec 26, 2014, at 12.16 kWh, because that window copies the holiday's pattern. On that day naive is still the lowest, at 10.36 kWh.

We recommend reporting all three baselines every time. Use seasonal naive as the main reference for MASE, because it carries the daily cycle that makes hourly demand predictable, and keep naive beside it, because on some weeks the flat rule is the stronger one.

Working rule: 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

最終変更:版2026.11.11

A kilowatt-hour error means different things for different clients. A miss of 8.36 kWh an hour is small for a client that uses 46.62 kWh an hour, and the same miss would be large for a hypothetical client that uses 4 kWh an hour. Scaling the error removes that difference. A scaled error divides each absolute error by a scale, the typical error of a simple method on the same client's own history. MASE, the mean absolute scaled error, is the mean of the scaled errors. Hyndman and Koehler introduced it in a 2006 paper in the International Journal of Forecasting. The link is the authors' preprint, dated 2005. They noted that the scaled error does not depend on the units of the data, so the same number can be read across clients of very different size. This chapter scores one client, so that comparison across clients is the reason for the scale, not a result shown here.

The 2006 paper scales by the one-step naive error: the mean absolute difference between each reading and the one before it. That is the natural scale for non-seasonal series. For hourly demand, this book uses the seasonal form that Hyndman and Athanasopoulos give for seasonal data, because the comparison a reader wants is with seasonal naive: under the seasonal scale, the denominator is seasonal naive's error on the client's own history. A MASE below 1 then says the forecast's error on the scored hours is smaller than seasonal naive's error on that history. A one-step scale would compare it with a method this book does not use for hourly demand.

The two formulas are these:

  • scale = mean of |y(t) - y(t - 24)| over every reading t before the first test day, with the pairs that touch a masked clock-change hour left out
  • MASE = mean of |actual(t) - forecast(t)| / scale over the scored hours

The scale reads every reading before the first test day, 17352 hours, about two years. That is longer than each window's eight-week history, and a longer history gives a steadier estimate of the client's usual swing. One scale for the week also means every window is read against the same number. The function seasonal_scale in examples/lib/baselines.py computes it for one client or for many, and returns one value per client. To see whether the cut matters, score the three baselines on the held-out week twice: with the scale from history, and with the scale from the whole series, both with the clock-change readings masked.

mase-scale-leak-check.py Python 3.13.16 · numpy 2.5.5 · pandas 2.3.3 · statsforecast 2.1.1 · utilsforecast 0.2.17 合格
"""Score the lead client's held-out week in MASE with a scale from history and with one from the whole series, both with the clock-change readings masked. The point rests on the two last-reading lines, which show where each scale stops, and on the MASE ratio lines."""import pandas as pdfrom lib.backtest import held_out_cutoffsfrom lib.baselines import BASELINES, baseline_forecasts, mase_scores, scale_history, seasonal_scalefrom lib.electricity import loadfrom lib.quirks import mask_clock_changesfrom lib.settings import HELD_OUT_WEEK, LEAD, showLABELS = ["naive", "seasonal naive", "average of weeks"]    # printed names, in the order of BASELINESfirst_day = pd.Timestamp(HELD_OUT_WEEK[0])                   # the first test day: the history scale may read only readings before itfull = load([LEAD])                                          # every reading of the lead client, with the quirk column that marks clock-change hoursdf = full[["unique_id", "ds", "y"]]                          # the three columns the baselines and mase_scores read; quirk is for masking onlyforecasts = baseline_forecasts(df, held_out_cutoffs())       # the same windows and history rule as naive-baselines-held-out-week.pyhistory = scale_history(full, first_day)                     # keeps only rows strictly before the first test day, so no test hour reaches this scalemasked_history = mask_clock_changes(history)                 # clock-change hours set to NaN, so the pairs that touch them drop out of the meanmasked_whole = mask_clock_changes(full)                      # the same masking on the whole series, so the test week is the only differencetest_rows = len(full[full["ds"] >= first_day])               # readings from the first test day on: the test week's rowsshow("scale rows from history", len(history))show("last scale reading from history", history["ds"].max().strftime("%b %d, %Y %H:%M"))   # this must be the hour before the first test day; the line is the checkshow("scale rows from whole series", len(full))show("last reading of whole series", full["ds"].max().strftime("%b %d, %Y %H:%M"))show("test week share of whole-series rows in percent", 100 * test_rows / len(full), digits=3)show("clock-change rows in scale history", int(history["quirk"].ne("normal").sum()))   # every quirk but normal; for the lead client these are the clock-change hours, as it has no late startshow("test week own mean day-to-day difference", seasonal_scale(full[full["ds"] >= first_day - pd.Timedelta(hours=24)]).loc[LEAD], digits=4)   # starts 24 hours early, so its first pair is the first test day against the day beforeshow("scale from history as recorded", seasonal_scale(history).loc[LEAD], digits=4)          # seasonal_scale returns one value per client, so .loc picks the lead client; the clock-change pairs are kept hereshow("scale from history clock changes masked", seasonal_scale(masked_history).loc[LEAD], digits=4)   # pairs with a NaN are left out of the meanshow("scale from whole series clock changes masked", seasonal_scale(masked_whole).loc[LEAD], digits=4)hist = mase_scores(df, forecasts, BASELINES, masked_history).loc[LEAD]   # the scale comes from the rows passed as train, not from df; that choice is what this example testswhole = mase_scores(df, forecasts, BASELINES, masked_whole).loc[LEAD]for model, label in zip(BASELINES, LABELS):    show(f"{label} MASE from history scale", hist[model])    show(f"{label} MASE from whole-series scale", whole[model])    show(f"{label} MASE ratio whole-series over history", whole[model] / hist[model], digits=4)   # both MASEs share the same errors, so this ratio is the history scale over the whole-series scaleshow("seasonal naive MASE from history scale at four decimals", hist["SeasonalNaive"], digits=4)   # two decimals hide the leak, so the last two lines print fourshow("seasonal naive MASE from whole-series scale at four decimals", whole["SeasonalNaive"], digits=4)
出力python mase-scale-leak-check.py
scale rows from history: 17352
last scale reading from history: Dec 24, 2014 23:00
scale rows from whole series: 17520
last reading of whole series: Dec 31, 2014 23:00
test week share of whole-series rows in percent: 0.959
clock-change rows in scale history: 4
test week own mean day-to-day difference: 8.3607
scale from history as recorded: 7.1121
scale from history clock changes masked: 7.1005
scale from whole series clock changes masked: 7.1126
naive MASE from history scale: 1.15
naive MASE from whole-series scale: 1.15
naive MASE ratio whole-series over history: 0.9983
seasonal naive MASE from history scale: 1.18
seasonal naive MASE from whole-series scale: 1.18
seasonal naive MASE ratio whole-series over history: 0.9983
average of weeks MASE from history scale: 1.26
average of weeks MASE from whole-series scale: 1.26
average of weeks MASE ratio whole-series over history: 0.9983
seasonal naive MASE from history scale at four decimals: 1.1775
seasonal naive MASE from whole-series scale at four decimals: 1.1755

The scale from history is 7.1005 kWh, the average gap between each hour and the same hour the day before, and it reads against the mean demand the way an MAE does. A scale that is a large share of the mean says the client's own day-to-day swing is large, and every error for that client is read against that swing. Dividing seasonal naive's MAE of 8.36 kWh by the scale gives its MASE, 1.18. utilsforecast's mase, reached through the helper mase_scores, computes this MASE by dividing the same MAE by the same seasonal scale (utilsforecast 0.2.17, utilsforecast/losses.py, function mase), so the division by hand gives the same figure.

utilsforecast (0.2.17) computes MASE with its mase function in utilsforecast/losses.py. The function takes its scale from the train_df it is given, and it shifts that frame by rows, not by time, so a missing hour moves every later lag and nothing reports it. It also needs sorted input. Its time filter runs only when the scored frame has a cutoff column (function _create_train_with_cutoffs). So the library does not decide which readings the scale may read. The caller does, and the next section is about that choice.

Working rule: 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のスケールは履歴から取る

最終変更:版2026.11.11

スケールが記述するのは、最初のテスト日より前の履歴であり、系列全体ではない。スケールが系列全体を読むと、予測を採点する対象の時間帯まで読むことになり、保持した週が自分自身の誤差の分母に入り込む。これはリークであり、エラーは出ない。そうして得られたMASEは、他のMASEと見分けがつかない。本書の規則は、スケールが読むのは採点する週の最初のテスト日より前の読み取り値だけ、とするものである。保持した週の場合、その日は Dec 25, 2014 である。

系列全体のスケールは、より多くの読み取り値を使うので、安全な選択に見える。しかし、より多くの読み取り値を使うといっても、それは誤った期間のものである。余分な読み取り値は、予測が評価される対象そのものであり、スケールはもはやカットオフ時点で既知であったことの尺度ではなくなる。データを増やしてもこれは直らない。直すのは、カットだけである。

前の節のスクリプトは、各スケールが読む行を出力する。その出力行が検査になる。履歴スケールが読む読み取り値は 17352 行であり、最後の読み取り値は Dec 24, 2014 23:00 で、最初のテスト日の1時間前である。ここにそれより後の日付が現れれば、テスト時間帯がスケールに届いたことを意味する。

系列全体のスケールが読む読み取り値は 17520 行で、Dec 31, 2014 23:00 までに及び、保持した週全体を含む。両方のスケールとも時刻変更に当たる読み取り値はマスクしてあるので、両者の違いは保持した週だけである。

系列全体のスケールの方が大きいので、それで計算したMASEはすべて小さくなる。小数点以下2桁では、どちらのスケールでも季節ナイーブは 1.18 となり、リークは表に出ない。4桁では差が現れ、季節ナイーブのMASEは 1.1775 対 1.1755 である。重要なのは丸めではなく、次に示す比率である。

スケールは、履歴からでは 7.1005 kWh、系列全体からでは 7.1126 kWh であり、3つの予測規則のMASEはそれぞれ、同じ比率 0.9983 で小さくなる。

この週でリークが小さいのは、保持した週が系列に占める割合が小さいからである。その週は系列全体の読み取り値の 0.959 パーセントを占めるので、系列全体のスケールは、履歴のスケールを、その割合の分だけ保持した週自身の変動の方へ寄せたものにほぼ等しい。保持した週自身の日々の差の平均は 8.3607 kWh で、履歴の 7.1005 kWh より大きく、この週は履歴よりも大きく変動する。この割合とその差の積がリークであり、上の比率がその大きさである。リークは2通りの仕方で大きくなる。1つは、スケールの行のうちテスト時間帯が占める分が増えるときで、第3章の1年分のカットオフのように、テスト期間が1週間よりはるかに長い場合がこれに当たる。もう1つは、保持した週の変動が履歴の変動からより遠いときである。より静かな週であれば、系列全体のスケールを押し下げ、すべてのMASEを大きくする。したがって、同じリークが、ある週ではモデルを有利に見せ、別の週では不利にしうる。

時刻変更は第2の、より小さな論点であり、本章では第3章と同じやり方で扱う。履歴には時刻変更の読み取り値が 4 行ある。2013年と2014年の3月と10月の変更に伴う、欠落する2時間と重複する2時間である。欠落する時間の読み取り値は0を示し、重複する時間には2時間分のエネルギーが入っている。これはデータカードに記述されているとおりで、その影響は第3章に示してある。記録のままにすると、これらの対によるスケールは 7.1121 kWh になる。マスクすると、マスクされた読み取り値に触れる対が平均から外れるので、スケールは 7.1005 kWh になる。マスクされた読み取り値は0でも複製でもなく、欠測である。本章のスケールはそれらをマスクしており、第3章がその理由を述べている。そこでは、すべての訓練セットとすべての採点で、それらを欠測に設定する。

実践ルール: スケールには最初のテスト日より前の読み取り値だけを渡し、時刻変更に当たる読み取り値をマスクし、使う最後の読み取り値を出力する。その読み取り値が最初のテスト日の1時間前であることを確認する。2つのスケールの差が小さくても、手順が正しいことの証拠にはならない。証拠になるのは、行の検査である。

ベースラインのスコアを読む

最終変更:版2026.11.5

MASE は、予測の誤差を、顧客自身の履歴における季節ナイーブの誤差と比較する指標である。値が 1 を下回れば、採点対象の時間帯における予測の誤差は、その履歴で季節ナイーブが出した誤差より小さい。1 を上回れば大きい。Hyndman と Koehlerは、1 ステップのスケールについて論文でこの読み方を述べており、季節スケールでも計算は同じである。本書は、良いスコアの基準値を示さない。何をもって良いとするかは、予測が外れたときに供給事業者が負う費用で決まる。その費用は供給事業者が知っており、本書は知らない。

次の表は、3 つのベースラインを 1 行ずつ並べたものである。MAE の単位は kWh であり、MASE には時計の切り替えをマスクした履歴スケールを用いている。前の節で示したリークは小数第 2 位では現れないため、表の MASE 列は 1 つにしている。

ベースライン MAE (kWh) MASE
ナイーブ 8.16 1.15
季節ナイーブ 8.36 1.18
週の平均 8.96 1.26

3 つの MASE の値はすべて 1 を上回っている。したがって、どのベースラインも、履歴における季節ナイーブの典型的な誤差を超えて外した。季節ナイーブ自身については、この週の日ごとの変動が履歴のそれより大きかった。その MAE は、ホールドアウトした週自身の日ごとの差分 8.3607 kWh に等しく、履歴では 7.1005 kWh である。ナイーブと週の平均については、スケールは両者を自身の過去ではなく季節ナイーブと比較する。そのため、この表は、この 2 つの規則が履歴でどうであったかを示さない。この週は祝日から始まっており、前の節は、週の平均では祝日の区間が最大の誤差になることを示している。本書は、ここでは残りの日を検証しない。

順序は両方の指標で同じであり、ナイーブが最初、季節ナイーブが 2 番目、週の平均が 3 番目である。この一致は発見ではない。MASE はすべての MAE を同じスケールで割るので、1 つの顧客について MAE と MASE の順序が食い違うことはない。

この表は、供給事業者にとっての問いも浮かび上がらせる。最も単純な規則で、購入の判断をするのに十分だろうか。それは 1 時間分の誤差の費用によって決まり、MASE はその費用を価格に換算しない。MASE が供給事業者に与えるのは、繰り返せる比較である。後のモデルも同じヘルパーで採点できるので、その MASE は単位を変えずにこれらの行の隣に並べられる。

表は次の順序で読む。第 1 に、前の節に照らして、どの行も同じ時間帯を採点しており、欠けた予測がないことを確認する。第 2 に、MASE の列を 1 と比べて読む。第 3 に、各行を、教科書の数値ではなく、他の行と比較する。最良の行と同程度でしかない学習済みモデルは、多くを示したことにならない。印字された丸めの幅に満たない差で上回るモデルは、何も示したことにならない。

実践ルール: 各ベースラインの MASE を 1 と、また他のベースラインと比べて読み、1 週間だけで勝者を決めてはならない。モデルが優れていると見なせるのは、複数の窓の集合で最良のベースラインを上回り、かつその差が印字されたスコアの丸めより大きいときに限る。

本番運用で起こる問題

最終変更:版2026.11.5

ベースラインを別の時間帯で、あるいは別の履歴を使って採点すると、比較は見かけどおりの意味を持たなくなる。たとえば、モデルは1年分のカットオフで採点し、ベースラインは1週間分だけで採点する場合がある。モデルにベースラインより長い履歴を与える場合もある。このとき比較が測っているのは実験設定の違いであり、印字された数値は証拠のように見えてしまう。検査の方法は、この章で用いているものと同じである。どの手法も、カットオフは held_out_cutoffs から、履歴は history_before から取り、欠けた予測の件数を実行ごとに印字する。

スケールへのリークが生じても、MASE は他と変わらない値に見え、エラーも出ない。この章では、季節ナイーブの MASE がすべて 0.9983 倍になる。小数第2位までの表示では、この変化は見えない。別の週に生じた、より大きなリークも、紙面上では同じように見える。検査の手段は、印字された行数と、スケールが使う最後の読み取り値である。この二つは出力の1行に収まっており、査読者は何も再実行せずに読める。

季節ラグに欠測があると、出力に何の印も出ないまま誤ったスケールが得られる。1時間分が欠けていると、24行のラグは25時間前に達するため、翌日の各ペアは誤った時刻同士を比べることになる。ライブラリの mase には、欠測を調べる仕組みがない。ヘルパー seasonal_scale は各クライアントの時刻が途切れていないかを検査し、mase_scores は、ライブラリがスケールの行を読む前に、同じ検査をそれらの行に対して実行する。この検査では assert 文ではなくエラーを送出する。Python は -O のもとでは assert 文を取り除くからである。採点対象の時刻については、読み取り値の有無と重複だけを検査し、欠測は検査しない。本番の実行では、スケールを計算する前にフィード内の時刻数を数えるべきである。ヘルパー内部の検査では、問題がスケールに達した後で報告されるからである。

季節ラグを誤った周期に対して選ぶこともある。ラグ24は、日周期をもつ時間別の需要に適している。日次データは週周期をもち、週のリズムをもつ時間別データでは、代わりにラグ168が必要になることがある。誤った季節で計算したスケールも数値であることに変わりはなく、出力にはその誤りが現れない。検査の方法は、本文中でスケールの隣に季節を明記し、スケールを使う前にデータの周期と照らして確かめることである。

ホールドアウトの週で設定を選ぶと、比較が損なわれる。週の平均には選択の余地がある。何週分を平均するかである。この数を、ホールドアウトの週で最良のスコアが出るという理由で選ぶと、ベースラインは評価対象の週に合わせて調整されたことになり、モデルとの比較はもはや公正ではない。本書は、スコアを印字する前に4週間と定め、この章ではすべてのウィンドウでそれを保つ。変更する場合は、スコアを見る前に、章末の決定リストに記す。

実践ルール: ベースラインの入力とそのスケールの入力は、次の順で確認する。すべての手法で同じウィンドウを使うこと。以前の読み取り値だけを読み、最後の読み取り値を印字するスケールを使うこと。季節ラグのために途切れのない時間別履歴を用意すること。データの周期に合った季節を用いること。各検査は出力の1行または1つの件数で済み、検査に失敗したときは、修正するまで比較を止める。

この章で行った決定

最終変更:版2026.11.5

この章の内容は七つの選択によって形づくられており、最後の一つは第3章への引き継ぎである。大半は基準予測の補助関数を収めた examples/lib/baselines.py にあるため、そこでの修正は、これらの関数を呼び出すすべての章に反映される。履歴の長さと予測期間は examples/lib/settings.py の設定であり、第1章で使ったものと同じである。したがって、ここでのどの基準予測も、並べて示す予測と異なる履歴を読むことはない。

  • MASE のスケールは季節型であり、ラグは24時間とする。2006年の論文にある1ステップのスケールは用いない。
  • スケールは、予測対象とする1週間について、クライアントごとに1つの数値とし、2014年12月25日より前のすべての観測値から求める。前述のとおり、これは各ウィンドウの履歴より長い。utilsforecast は、フレームにカットオフ列がある場合にカットオフごとのスケールを使えるが、この章ではそのオプションを使わない。このオプションを加える場合は、そのフィルタが ds <= cutoff を保持し、カットオフの時刻自体が含まれることに注意が必要である。本書におけるカットオフとは、予測が対象とする最初の時刻であり、その時刻の観測値は履歴ではない。そのため、本書のカットオフから作ったカットオフ列は、先に1時間前へずらしておかなければならない。
  • 週平均は、各予測日の前の4週間を用い、pandas で計算し、その予測自身の8週間の履歴だけを読む。
  • ナイーブ予測と季節ナイーブ予測には statsforecast のクラスを用いる。スコアは、その週の評価対象となるすべての時刻にわたってプールし、小数第2位まで表示する。
  • スケールでは、第3章の規則に従い、時計の切り替えにあたる 4 件の観測値をマスクする。その結果、表示される履歴のスケールは 7.1005 kWh となる。
  • 基準予測は乱数を使わないため、例では乱数シードを設定しない。
  • 第3章では、季節ナイーブ予測とこれらの補助関数を引き続き用い、1年分の日曜日のカットオフにわたって実行する。そのとき、クライアントごとのスケールは、この章で示した規則どおり、最初のカットオフより前のすべての観測値から1つ求める。1週間ではこの検定はできない。

この版における本章

第2026.11.11版2026年11月20日時点で例が通過この章の2 例件のうち2件が合格

英語版の書籍(版2026.11.11)から翻訳した。

この節を引用する

形式

いずれの形式も、本訳書が従う英語版の書籍を出典として示す。

いずれの形式もこの版を明示している。そのリンクは現行版を開き、節の見出しには本文が最後に変更された日付が示される。アクセス日と取得日は、これを開いた日である。

このページの内容

全10章中の第2章: モデルが超えるべきベースラインを定める

  1. なぜ最初にベースラインを置くのか
  2. Three baselines to beat
  3. Scale errors with MASE
  4. MASEのスケールは履歴から取る
  5. ベースラインのスコアを読む
  6. 本番運用で起こる問題
  7. この章で行った決定

ページの先頭に戻るすべての章