AI로 번역함. 영어 원문을 사람이 검증함. 원문 읽기

시계열 예측

교육 자료 키트

2026.11.23판으로, 책의 현재 판이다. 책이 바뀌면 함께 바뀐다. 출처를 밝히면 자유롭게 사용하고 수정할 수 있다.

강의 계획서

읽기 시간은 장의 본문 기준이다. 학습자는 Lab 또는 자신의 컴퓨터에서 예제도 실행한다.

주당 한 장: 10주

5주 후

학습 목표와 개요

각 장의 학습 목표는 첫 문장이다. 각 개요는 장의 절을 따르며, 절이 정의하는 용어, 예제가 실행되기 전에 요구하는 예측, 그리고 각 절이 끝나는 규칙을 담는다.

1. 내일의 수요 예측하기

읽는 데 약 35분, 4개 예제.

이 장에서는 내일의 수요에 대한 첫 번째 예측과, 이후의 모든 예측이 넘어서야 하는 단순한 기준선을 만든다. 한 고객의 시간별 수요를 불러오고, 계절성 나이브(seasonal naive) 기준선과 통계 모형 하나로 다음 날을 예측한 뒤, 두 예측을 같은 7일에 대해 채점한다. 결과는 의도적으로 거칠다. 예측 구간도 없고, 튜닝도 없으며, 판단의 근거도 고객 한 명뿐이다. 이후의 각 장은 이 가운데 한 부분씩을 탄탄하게 만든다. 필요한 것은 Python, pandas, 표본의 평균, 오차가 무엇인지에 대한 이해뿐이며, 그 밖의 지식은 필요하지 않다. 핵심 용어는 처음 나올 때 한 줄로 정의한다。

강의 개요: 7절
  1. 사례와 데이터
    • 작업 규칙 어떤 예측을 하기 전에 잘라 낸 데이터를 데이터 카드와 대조한다. 파일에는 고객이 30개 들어 있어야 하며, 예제는 그중 몇 개가 두 해 전체의 시간별 행을 갖추었는지 센다. 이 개수들은 카드와 일치해야 한다. MT_223이 빠져 있고 그 이유가 설명되어 있는지 확인한다. 카드와 맞지 않는 데이터는 다른 데이터이며, 그로부터 계산한 모든 수치는 이 책의 데이터가 아니라 그 데이터를 설명한다.
  2. 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_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.
  3. 계절성 나이브로 다음 날 예측하기
    • 실행 seasonal-naive-next-day.py
    • 작업 규칙 하루 주기가 있는 시간 단위 시계열을 비교할 때는 항상 계절성 나이브를 포함한다. 적합이 필요 없으므로 추가 비용 없이 모든 윈도에서 실행된다. 같은 윈도에서 이를 이기지 못하는 모델은 추가 작업의 값어치를 증명하지 못한 것이다. 점수를 읽기 전에 예측에 결측값이 있는지 확인한다. 마지막 계절의 결측 측정값은 결측 예측이 되기 때문이다. 모델을 실행하기 전에 그 시간을 채우는 규칙은 3장에서 다룬다.
  4. 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.
  5. 보류한 한 주로 두 모델 점수 매기기
    • 실행 figure-held-out-week-forecasts.py
    • 작업 규칙 각 모델은 채점 대상 시간이 이력에 없는 상태에서 만든 예측으로, 하루가 넘는 기간에 대해 점수를 매기고, 각 점수의 바탕이 된 윈도 수와 시간 수를 함께 보고한다. 모델은 같은 윈도에서만 비교한다. MAE와 RMSE는 함께 읽는다. 어느 모델이 더 나은지에 대해 둘이 엇갈리면, 고르기 전에 윈도에서 가장 큰 빗나감을 살펴본다. 몇 번의 큰 빗나감이 결과를 좌우할 수 있기 때문이다.
  6. 운영 환경에서 잘못되는 것들
    • 작업 규칙 점수를 신뢰하기 전에 세 가지를 이 순서로 확인한다. 각 윈도의 첫 예측 시간이 그 기준 시점인지, 각 이력이 기준 시점 이전에 끝나며 전체 이력 길이를 담고 있는지, 누락된 예측이 없는지이다. 도우미 함수는 앞의 두 가지에 오류를 발생시키고, 예제는 세 번째를 출력한다. 점수는 세 가지를 모두 통과한 뒤에야 결과로 인정된다.
  7. 이 장에서 내린 결정

2. 모델이 넘어야 할 기준선 설정하기

읽는 데 약 38분, 3개 예제.

이 장에서는 한 고객의 하루 전 예측에 대해 나이브(naive), 계절성 나이브(seasonal naive), 주간 평균(average of weeks)이라는 세 가지 기준선을 계산한다. 그리고 예측 주 이전의 측정값만 읽는 척도를 사용하여 MASE로 고객의 오차를 척도화한다。

강의 개요: 7절
  1. 기준선이 먼저 와야 하는 이유
    • 작업 규칙 모든 기준선은 비교할 모델과 같은 윈도, 같은 이력, 같은 채점 코드로 점수를 매기고, 점수를 읽기 전에 각 기준선에서 빠진 예측의 수를 센다. 다른 시간으로 점수를 매긴 기준선을 이긴 모델은 (같은 조건의) 기준선을 이긴 것이 아니다.
  2. 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.
  3. 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.
  4. 이력에서 MASE 척도 구하기
    • 작업 규칙 척도에는 첫 테스트일 이전의 관측값만 넘기고, 시계 변경 관측값을 마스킹하고, 사용하는 마지막 관측값을 출력한다. 이 관측값이 첫 테스트일 직전 시간인지 확인한다. 두 척도의 차이가 작다고 해서 절차가 옳다는 증거가 되지는 않는다. 행 검사가 그 증거다.
  5. 기준선의 점수 읽기
    • 작업 규칙 각 기준선의 MASE를 1과, 그리고 다른 기준선과 비교해 읽고, 한 주의 결과만으로 승자를 지명하지 않는다. 모델은 둘 이상의 윈도 집합에서 가장 좋은 기준선을 이기고, 그 차이가 출력된 점수의 반올림보다 클 때에만 더 낫다고 본다.
  6. 운영 환경에서 무엇이 잘못되는가
    • 작업 규칙 기준선의 입력과 그 척도의 입력을 다음 순서로 점검한다. 모든 방법에 같은 윈도를 쓰는지, 척도가 이전 관측값만 읽고 그 마지막 관측값이 출력되는지, 계절 지연에 대해 시간별 이력이 끊김 없이 이어지는지, 계절이 데이터의 주기와 일치하는지이다. 각 점검은 한 줄의 출력 또는 하나의 개수이며, 점검에 실패하면 문제를 고칠 때까지 비교를 중단한다.
  7. 이 장에서 내린 결정

3. 미래를 미리 보지 않는 백테스트

읽는 데 약 46분, 8개 예제.

이 장에서는 예측 시점의 기록에 미래가 섞여 들어가지 않도록 하면서 1년 치 예측 시점에 걸쳐 하루 앞 예측을 평가하는 방법을 배운다. 또한 데이터에 들어 있는 두 번의 시계 변경 시간대를 처리하는 방법과, 예측 시점 이후의 값을 읽는 피처를 잡아내는 이동 검정을 실행하는 방법도 배운다. 2장에서 다룬 내용, 곧 계절성 나이브 기준선, MAE, 기록에서 구한 척도가 필요하다. 방법은 그대로이다. 달라지는 것은 평가를 반복하는 횟수와, 매번 데이터를 얼마나 주의 깊게 나누는가이다。

강의 개요: 10절
  1. 테스트 한 주가 오해를 부르는 이유
    • 작업 규칙 두 방법의 차이를 신뢰하기 전에 1년치 기준 시점을 쓰는 쪽을 우선한다. 비용 때문에 더 적게 쓸 수밖에 없다면 4장부터 9장까지처럼 각 점수 옆에 그 사실을 밝힌다. 표본이 1년 중 특이한 날들에 닿도록 한다. 각 수치의 근거가 된 윈도 수와 채점된 시간 수를 함께 보고한다. 한 주에서 나온 수치는 표본 하나이며, 독자가 그 점을 알아볼 수 있어야 한다.
  2. 컷오프를 앞으로 굴리기
    • 실행 backtest-sundays-2014.py
    • 실행 figure-rolling-windows.py
    • 작업 규칙 히스토리 길이를 시간 단위로 명시적으로 정하고, 모든 윈도에서 같은지 확인한다. 라이브러리가 윈도를 대신 순회할 때는 출력을 신뢰하기 전에 학습 구간을 어떻게 정하는지 읽어야 한다. 기본값이 여러분이 고른 길이가 아니라 확장 윈도일 수 있기 때문이다.
  3. 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.
  4. 시계 변경 시각 살펴보기
  5. 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.
  6. The October hour that holds two
    • 실행 clock-repeat-daily-cutoffs.py
    • 작업 규칙 Treat the October 01:00 label as two hours of energy in one slot, and never as an ordinary hour. Do not halve it to make it look like one, for the reason the next section gives.
  7. Mark clock-change hours as missing
    • 실행 clock-masked-backtest.py
    • 작업 규칙 Mark both clock-change hours missing in every history and every score, count the masked hours in your report, and fill them from the history before the cutoff only when the model cannot take missing values. If the count of masked hours changes from one run to the next, the sample or the file's flags have changed, and you should find out why before you rerun the scores.
  8. 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.
  9. 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.
  10. 이 장에서 내린 결정

4. 고객별 통계 모델 적합하기

읽는 데 약 43분, 9개 예제.

공급업체의 각 고객에게는 저마다 하루 전 예측이 필요한데, 2장의 계절 나이브 모델은 모든 고객에게 같은 답, 즉 어제 같은 시각의 값을 내놓는다. 이 규칙은 고객의 수준(level)이나 추세(trend)를 전혀 추정하지 않으며, 고객들은 두 가지 모두에서 서로 다르다. 공급업체는 고객별로 전력을 구매하므로, 각 예측은 그 자체로 정확해야 한다。

강의 개요: 10절
  1. 다음에 통계 모델이 오는 이유
    • 실행 figure-lead-client-fortnight.py
    • 작업 규칙 기준선과 백테스트를 갖춘 뒤에만 고객별로 모델 하나씩을 적합한다. 윈도 수를 정하기 전에 적합 횟수를 센다. 고객 수에 윈도 수를 곱하고, 모델을 매일 실행한다면 재적합 횟수까지 곱한다. 비교에 들어가는 모든 모델에는 같은 컷오프와 같은 이력을 사용한다. 그렇지 않으면 비교가 모델이 아니라 윈도를 측정하게 된다.
  2. 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 with model="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.
  3. 고정된 계절 ARIMA 적합
    • 실행 figure-seasonal-difference.py
    • 실행 arima-summary-look.py
    • 작업 규칙 탐색이 너무 느려 기준 시점마다 실행할 수 없으면 차수를 고정하고 호출에 적는다. 요약은 한 번 출력하여 나열된 항이 의도한 항인지 확인한다. 고정한 차수는 다른 모형과 마찬가지로 기준 시점마다 다시 적합한다. 차수는 고정되어 있지만 계수는 그렇지 않다.
  4. 같은 기준 시점에서 모델 비교하기
    • 실행 arima-subset-backtest.py
    • 작업 규칙 모든 후보를 같은 기준 시점, 같은 이력, 같은 척도로 채점하고 MAE와 MASE를 나란히 보고한다. 두 측도가 엇갈리면 결정에 어느 쪽이 필요한지 밝힌다. MASE 차이가 약 0.1 미만인 두 모델 중에서 고르기 전에는 더 많은 구간을 확보하기를 권한다. 이 기준은 측정값이 아니라 이 표본에서 나온 판단이다.
  5. 늦게 시작하는 고객 살펴보기
  6. 0으로 시작하는 이력
  7. Start each series at its first reading
    • 작업 규칙 When a client's history holds zeros, check whether its first non-zero reading falls inside the history. If it does, apply the start rule before any model sees the history, whatever the zero share, because leading zeros are not use. Run check_start_rule on the whole series first, and if it fails, find out why before you trim anything. Print the history length at each cutoff, because a short history is the first sign that the rule has taken too much.
  8. 이 책이 24 주기에서 자동 ARIMA를 피하는 이유
    • 작업 규칙 매일 다시 적합하는 일정에서 시간 단위 데이터에 주기 24로 자동 탐색을 실행하지 않는다. 탐색을 적용하기로 정하기 전에 고객 한 명에 대해 탐색 시간을 잰다. 너무 느리면 차수를 고정하고, 그 차수를 백테스트에서 검증한다.
  9. 운영 환경에서 잘못되는 것
  10. 이 장에서 내린 결정

5. 캘린더 특징과 지연 특징 추가하기

읽는 데 약 46분, 4개 예제.

이 장을 마치면 한 고객의 시간별 이력을 특징 테이블로 바꾸고, 하루 앞 예측이 볼 수 있는 지연 특징, 캘린더 특징, 공휴일 특징을 추가하고, 각 특징이 더하는 효과를 같은 윈도에서 측정하고, 예측 대상인 날을 읽는 지연 특징을 찾아낼 수 있다。

강의 개요: 8절
  1. 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.
  2. 예측이 볼 수 있는 래그 추가하기
    • 작업 규칙 예측 구간 이상의 길이를 가진 래그만 사용한다. 24시간 구간이라면 24시간 이상을 뜻하며, 이 책에서는 24와 168을 사용한다. 더 짧은 래그에는 근거가 필요하고, 그런 래그를 쓰는 모델은 점수를 신뢰하기 전에 시프트 테스트를 통과해야 한다. 래그에도 시계 규칙을 유지하고, 마스킹된 시간을 읽는 래그를 가진 행의 수와 이력으로 채운 시간의 수를 센다.
  3. 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.
  4. 결정 구간에서 선택한다
    • 작업 규칙 피처는 홀드아웃 주 이전에 있으면서 그 피처가 겨냥하는 종류의 날을 포함하는 구간에서 선택한다. 휴일 피처에는 휴일 구간이 필요하다. 표준 기준 시점은 선택 결과 옆에 보고하되, 선택에는 쓰지 않는다.
  5. 각 특성이 더하는 것을 측정한다
    • 실행 lgbm-feature-sets.py
    • 작업 규칙 같은 윈도에서 확장 대상 집합과 비교해 고객별 평균 MASE를 낮출 때만 특성 집합을 유지한다. 풀링 MAE를 함께 보고한다. 두 관점의 불일치를 없애려고 모델을 조정하지 않는다.
  6. 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.
  7. 운영에서 문제가 되는 경우
    • 작업 규칙 데이터나 라이브러리가 바뀔 때마다 예측 연도별 휴일 수, 가려진 시간대와 그 영향을 받는 행, 래그 길이를 다시 확인한다. 모든 래그에 시프트 테스트를 실행하고, 통합 MAE와 함께 고객별 MASE를 읽는다. 점검 결과가 달라졌다면, 다음 예측을 발행하기 전에 멈추고 원인을 읽어야 한다.
  8. Decisions this chapter made

6. 하나의 모델로 많은 고객 예측하기

읽는 데 약 44분, 5개 예제.

이 장을 마치면 서른 고객 전체를 위한 하나의 전역 모델, 늦게 시작한 고객의 앞쪽 0이 모델에 들어가지 않게 하는 시작 규칙, 그리고 같은 기준 시점에서 고객별로 이 모델을 계절 순진 예측과 나란히 비교하는 점수를 얻게 된다. 공급자의 익일 구매량은 7장에서 서른 개의 고객 예측으로부터 구성하는 합계이다. 고객별 모델은 윈도마다 고객 수만큼, 즉 서른 번을 적합해야 한다. 고객들은 하루 단위의 리듬을 공유하므로, 전체 고객으로 적합한 하나의 모델은 그 리듬을 한 번만 학습하면 된다。

강의 개요: 7절
  1. 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.
  2. 각 클라이언트 식별하기
    • 실행 client-identifier-check.py
    • 작업 규칙 클라이언트 식별자를 5장의 규칙에 따라 또 하나의 피처로 취급한다. 의사결정 윈도에서 클라이언트별 평균 MASE를 낮출 때에만 유지하되, 통합 MAE를 함께 놓고 본다. 판정이 근소하면 그렇게 밝히고 다른 윈도에서 다시 측정한다. 식별자가 이기면 그 비용을 기록한다. 새 클라이언트는 이력이 생기기 전까지 학습된 분기가 없으며, 그 클라이언트를 예측하려면 모델을 다시 적합해야 한다.
  3. 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.
  4. 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.
  5. 실행 시간 예산 잡기
    • 작업 규칙 백테스트를 실행하기 전에 적합 횟수를 세어라. 클라이언트별 방법은 클라이언트 수 곱하기 윈도 수 곱하기 방법 수이고, 전역 방법은 윈도 수 곱하기 방법 수다. 횟수가 예산을 넘으면 부분집합이나 윈도 수를 줄이되, 점수를 매기는 윈도는 줄이지 말고, 줄인 내용을 점수 옆에 적어 두어라. 그러면 독자가 같은 조건끼리 비교할 수 있다.
  6. 운영 환경에서 잘못되는 것
    • 작업 규칙 점수를 읽기 전에, 갱신할 때마다 개수(고객, 윈도, 점수를 매긴 시간, 거부된 기준 시점, MASE에서 제외된 고객)를 출력하고 확인한다. 그런 다음 계절 나이브와 나란히 고객별 MASE의 평균을 보고한다. 거부가 하나라도 있으면 실행을 멈추고, 부족한 패널로 만든 총합은 발표하지 않는다.
  7. 이 장이 내린 결정

7. 총합을 맞추기

읽는 데 약 26분, 3개 예제.

30개 고객의 총수요를 두 가지 방법으로 예측하고, 의사결정 구간에서 두 방법 중 하나를 선택하며, 각 기준 시점 이전의 이력만 사용해 그 총합을 고객별 몫으로 나눈다。

강의 개요: 7절
  1. 총량에 검사가 필요한 이유
    • 작업 규칙 결정이 총량에 달려 있을 때마다 총량을 두 방식으로 모두 예측한다. 두 방식을 같은 구간에서, 총량과 각 고객을 기준으로 채점한다. 결정 구간에서 앞서는 방법을 택하고, 부분의 합이 맞는다는 이유만으로 총량을 받아들이지 않는다.
  2. 고객 예측 합산하기
    • 실행 total-bottom-up-and-direct.py
    • 작업 규칙 시계 변경 플래그가 없는 모든 시간에서 총계 계열이 측정값의 합과 같은지 확인한 뒤, 고객 예측을 시간별로 합산한다. 합산 전에 각 고객에게 시작 규칙을 적용하여 어떤 고객의 모델도 그 0에 적합되지 않게 한다. 합을 점 예측으로 취급하고, 고객들의 중앙값의 합을 총계의 중앙값으로 취하지 않는다.
  3. 합계를 직접 예측하기
    • 작업 규칙 각 기준 시점 이전의 합계 자체 이력으로, 고객별 모델의 특성을 써서 합계를 직접 예측하고, 목표값의 스케일 방식은 결정 구간에서 선택한다. 두 방식에 같은 구간을 쓰고, 각각을 합계에 대한 계절 나이브와 비교해 점수를 매긴다. 직접 만든 방식만이 아니라 두 방식을 모두 보고한다.
  4. 두 총량 비교
    • 작업 규칙 보고할 척도로 의사결정 구간에서 방법을 선택한다. 같은 척도를 표준 기준 시점에서 계절 나이브와 나란히, 평가 대상 시간과 스케일을 함께 보고한다. 두 구간 집합이 엇갈리면 둘 다 보고하고, 얼마나 차이 나는지 밝히며, 더 보기 좋은 쪽을 고르지 않는다.
  5. 합계를 비중으로 나누기
    • 실행 figure-client-daily-profiles.py
    • 실행 total-split-by-share.py
    • 작업 규칙 합계를 비중으로 나누는 방법은 기준선으로만, 또는 고객들의 일간 프로파일이 비슷할 때만 쓴다. 각 비중은 기준 시점 이전의 이력으로 계산하고, 기준 시점 이후의 측정값을 바꿔도 비중이 움직이지 않는지 확인하며, 각 고객을 같은 척도에서 상향식과 비교해 채점한다. 분할은 의사결정 구간에서 상향식을 이기는 고객에게만 유지한다.
  6. 운영 환경에서 무엇이 잘못되는가
    • 작업 규칙 운영 환경에서는 모든 재적합마다 총합을 측정값의 합과 대조하고, 총합에서 클라이언트가 빠지면 중단하며, 각 비율과 각 구간의 스케일에 오염 검사를 실행한다. 같은 구간에서 식별자를 쓸 때와 쓰지 않을 때의 총합 오차를 기록한다. 구간들의 결과가 서로 어긋나면 둘 다 보고하고, 모델에 유리하게 보이는 쪽만 고르지 않는다.
  7. 이 장이 내린 결정

8. 예측 불확실성의 정량화

읽는 데 약 47분, 7개 예제.

이 장에서는 하루 앞 예측마다 범위를 덧붙여, 구매가 그 예측에 의존할 수 있는지 판단할 수 있게 한다. 점수를 매기는 날보다 앞선 날들에서 예측 구간을 보정하고, 그 구간이 얼마나 자주 들어맞는지 측정하며, 오차로 인한 두 가지 비용을 바탕으로 구매할 수준을 정한다。

강의 개요: 7절
  1. 숫자 하나로는 충분하지 않은 이유
    • 작업 규칙 두 오류의 비용이 다른 곳에서는 범위를 요구하고, 그 수준은 안심되어 보이는 숫자가 아니라 그 비용을 근거로 정한다. 커버리지는 여러 기간에 걸쳐 구간 안에 든 시간의 비율로 보고하며, 하루가 구간 안에 들 확률로 보고하지 않는다.
  2. Build intervals from residuals
    • 실행 conformal-three-windows.py
    • 작업 규칙 Build each band from the residuals of windows that come before its cutoff, and check the coverage it reaches on windows it did not use before you trust it. Read the level a design can reach before you read the coverage. Three residuals per client and hour cannot reach either label, so the fix is a larger calibration set, not a different reading of the output.
  3. 이전 윈도로 보정하기
    • 실행 conformal-decision-windows.py
    • 실행 figure-client-coverage-scaled.py
    • 실행 conformal-earlier-windows.py
    • 작업 규칙 점수를 매기는 윈도보다 앞서고 공휴일이 없는 윈도로 보정하고, 잔차를 합치기 전에 각 클라이언트에 규모를 적용한다. 설계상의 각 선택은 보고하는 윈도가 아닌 윈도에서 한다. 구간에 쓴 윈도와 잔차의 수, 그리고 점수를 매긴 날의 포함률을 보고하며, 그 포함률이 수준에 못 미치더라도 그렇게 한다.
  4. 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.
  5. 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.
  6. 운영 환경에서 생기는 문제
  7. 이 장에서 내린 결정

9. Prophet과 파운데이션 모델 비교

읽는 데 약 53분, 7개 예제.

이 장을 마치면 이 책의 표준 기준 시점 세 곳에 Prophet을 적합하고, 기록된 파운데이션 모델(Chronos-2)과 기록된 신경망 모델(NHITS)을 불러와, 모든 모델을 같은 실측값에 대해 하나의 MASE 척도로 평가할 수 있다。

강의 개요: 7절
  1. Prophet이 적합한 곳
    • 작업 규칙 독자가 추세와 계절 설정을 읽을 수 있는 매개변수로 필요로 하고, 점수를 매긴 Prophet 예측이 점수 산정 전에 정한 의사결정 윈도에서 계절 naive보다 나을 때 고객별로 Prophet을 사용한다. 구간 폭은 코드에서 설정하고, 기본 80% 구간은 80% 구간으로 읽으며 95% 범위로 읽지 않는다. 구간의 포괄 범위(커버리지)는 모델이 주장하는 수준과 대조하여 확인한다.
  2. 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.
  3. 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.
  4. 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.
  5. 신경망 모델을 기록해 두는 이유
    • 실행 recorded-nhits-check.py
    • 작업 규칙 어떤 모델의 의존성이 런타임 예산을 깨뜨린다면 그 모델은 예제의 런타임에서 빼고 기록해 둔다. 이때 고정한 버전은 별도의 요구 사항 파일에 둔다. 의존성을 추가하기 전에 깨끗한 환경에 설치해 보고, 크기와 패키지 수가 얼마나 늘어나는지 측정한다. 해석 결과가 고정된 패키지의 버전을 바꾼다면, 그것은 모델을 기록해 두어야 할 이유이지 고정된 버전을 바꿀 이유가 아니다.
  6. 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.
  7. 이 장에서 내린 결정

10. 예측을 계속 운영하기

읽는 데 약 43분, 6개 예제.

예측이 매일 실행되기 시작하면 질문은 예측의 점수가 좋았는지에서, 사용하는 날에도 여전히 유효한지로 바뀐다. 이 장에서는 그 질문에 답하는 루프를 만든다. 일정에 따라 예측을 다시 적합하고, 각 날의 예측을 측정값이 생기기 전에 기록하고, 그 기록이 도착한 데이터만 사용했는지 확인하고, 측정값이 들어오는 대로 점수를 매기고, 오차가 백테스트와 어긋나는 날에 표시를 달고, 모델을 언제 폐기해야 하는지를 정한다。

강의 개요: 7절
  1. 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.
  2. Log every forecast before its actuals arrive
    • 실행 rolling-refit-seven-days.py
    • 작업 규칙 Write each forecast's rows at its cutoff, from the readings that have arrived by then, with the refit day and both arrival times beside them. Never rebuild a past log from a newer model or from the actuals. If a day's rows are lost, mark that day as missing in the log, and do not fill it in afterwards.
  3. 실제값이 도착하는 대로 로그를 채점한다
    • 실행 late-fill-decision.py
    • 작업 규칙 각 날짜는 마지막 관측값이 도착할 때, 그 컷오프에 기록한 예측을 기준으로, 이 장의 단일 스케일로 채점한다. 관측값이 늦게 도착하면 그때 채점하고 로그에 개수를 기록하며, 기록된 예측은 그대로 둔다. 변경이 점수를 개선하더라도 컷오프 이후에는 예측을 바꾸지 않는다.
  4. 백테스트를 기준으로 드리프트 표시하기
    • 실행 drift-flag-rolling.py
    • 작업 규칙 일별 MASE가 앞선 보정 구간 중앙값의 두 배를 넘으면 그날에 표시를 붙이고, 달력상의 원인으로 설명되는지 확인한다. 원인이 있으면 표시 옆에 기록한다. 설명되지 않는 표시가 연속으로 두 번 나오면 모델 은퇴 점검의 시작으로 보되, 모델이 고장 났다는 증거로 취급하지 않는다.
  5. Know when to retire a model
    • 실행 drift-after-a-change.py
    • 실행 figure-drift-flags.py
    • 작업 규칙 Refit early when flags run on several days in a row with no calendar cause, or when the 80% band covers far below 80% of readings on several days, and record the trigger with the log. Retire the model when an early refit does not clear the flags. Re-run this chapter's checks when a pinned library is released, and keep the pins until the checks pass on the new version.
  6. 운영에서 무엇이 잘못되는가
    • 작업 규칙 모든 실행에서 세 가지 점검을 유지한다. 각 재적합과 예측에 미래가 들어가지 않게 하는 이력 규칙, 로그의 각 행에 대한 두 도착 점검, 그리고 3장과 7장의 누수 점검이다. 이 가운데 하나라도 실패하면 루프를 멈추고 다음 예측 전에 원인을 고친다. 이력이나 로그를 손으로 고치지 않는다. 손으로 고치는 것은 점검이 잡아내기 위해 존재하는 바로 그런 변경이기 때문이다.
  7. 이 장에서 내린 결정

퀴즈 모음

인증된 교육자를 위해 모든 장의 질문과 정답 해설을 제공한다. 각 답은 해당 절과 연결된다. 증명을 얻는 방법