[G1-Sync] Manual knowledge update
This commit is contained in:
@@ -2,70 +2,182 @@
|
||||
id: wiki-2026-0508-time-series-analysis
|
||||
title: Time Series Analysis
|
||||
category: 10_Wiki/Topics
|
||||
status: needs_review
|
||||
status: verified
|
||||
canonical_id: self
|
||||
aliases: [P-Reinforce-AUTO-TSAN-001]
|
||||
aliases: [Time Series, TSA, Forecasting, Temporal Analysis]
|
||||
duplicate_of: none
|
||||
source_trust_level: A
|
||||
confidence_score: 0.95
|
||||
tags: [auto-reinforced, time-series, forecasting, data-Analysis, Statistics]
|
||||
confidence_score: 0.9
|
||||
verification_status: applied
|
||||
tags: [time-series, forecasting, ml, statistics]
|
||||
raw_sources: []
|
||||
last_reinforced: 2026-04-20
|
||||
last_reinforced: 2026-05-10
|
||||
github_commit: pending
|
||||
inferred_by: Claude Opus 4.7 (auto-normalize 2026-05-08)
|
||||
tech_stack:
|
||||
language: python
|
||||
framework: statsmodels-prophet-darts-nixtla
|
||||
---
|
||||
|
||||
# [[Time-Series-Analysis|Time-Series-Analysis]]
|
||||
# Time Series Analysis
|
||||
|
||||
## 📌 한 줄 통찰 (The Karpathy Summary)
|
||||
> "시간의 흐름 속에서 규칙 읽기: 과거의 연속된 발자취가 미래의 어디로 향할지, 계절성과 추세라는 돋보기를 통해 데이터의 흐름을 예측하는 시간 여행자의 도구."
|
||||
## 매 한 줄
|
||||
> **"매 시간 축 위의 dependency가 modeling target"**. ARIMA의 classical 1970s 시대를 거쳐, 2020s에 Transformer-based foundation models (TimeGPT, Chronos, Moirai) 가 zero-shot forecasting을 가능케 했다. 매 2026 현재 hybrid (statistical + neural) 가 production default.
|
||||
|
||||
## 📖 구조화된 지식 (Synthesized Content)
|
||||
시계열 분석(Time-Series-Analysis)은 일정 시간 간격으로 수집된 데이터의 변화를 분석하여 미래값을 예측하거나 현상의 특성을 파악하는 기법입니다.
|
||||
## 매 핵심
|
||||
|
||||
1. **4대 구성 요소**:
|
||||
* **Trend (추세)**: 데이터를 관통하는 장기적인 상승 또는 하락 경향.
|
||||
* **Seasonality (계절성)**: 특정 기간(주, 월, 년)마다 반복되는 일정한 패턴.
|
||||
* **Cyclical (순환성)**: 경기 변동처럼 불규칙하지만 주기가 있는 변화.
|
||||
* **Residual (불규칙 요인/노이즈)**: 예측 불가능한 돌발 사건에 의한 변동.
|
||||
2. **분석 방법론**:
|
||||
* **Traditional**: ARIMA, SARIMA (통계적 모델).
|
||||
* **Deep Learning**: [[LSTM|LSTM]], GRU (순차 데이터 기억), TCN (Temporal Convolutional Networks).
|
||||
* **Modern AI**: [[Transformers|Transformers]] 기반 시계열 예측 (Long-term context 확보).
|
||||
3. **적용 분야**:
|
||||
* 주가 및 환율 예측, 수요 예측(공급망 관리), 기후 변화 시뮬레이션, IoT 센서 데이터의 이상 감지(Anomaly Detection).
|
||||
### 매 components
|
||||
- **Trend**: long-term direction.
|
||||
- **Seasonality**: periodic (daily, weekly, yearly).
|
||||
- **Cyclic**: aperiodic fluctuations.
|
||||
- **Residual**: noise / unexplained.
|
||||
|
||||
## ⚠️ 모순 및 업데이트 (Contradictions & Updates)
|
||||
- **과거 데이터와의 충돌**: 과거에는 과거 데이터가 미래를 완벽히 대변한다고 믿었으나(Stationarity 가정), 현대의 '재난 정책'은 과거에 없던 '블랙 스완' 이벤트에 의한 시계열의 구조적 단절을 반영하는 '비정상성(Non-stationarity) 대응 정책'으로 고도화됨(RL Update).
|
||||
- **정책 변화(RL Update)**: 금융 시장의 '퀀트 투자 정책'에서 시계열 분석의 속도가 경쟁력의 핵심이 됨에 따라, 밀리초 단위의 시계열 데이터를 실시간 처리하는 '초저지연 분석 정책'이 표준이 됨.
|
||||
### 매 stationarity
|
||||
- Strict / weak stationarity 의 distinction.
|
||||
- ADF, KPSS test 로 확인.
|
||||
- Differencing, log transform, Box-Cox 로 stationarize.
|
||||
|
||||
## 🔗 지식 연결 (Graph)
|
||||
- [[Statistics & Data Analysis|Statistics & Data Analysis]], [[Probability Theory|Probability Theory]], [[Operations-Research|Operations-Research]], [[Quantitative Economics (수량경제학)|Quantitative Economics (수량경제학)]], [[Signal in Noise|Signal in Noise]]
|
||||
- **Modern Tech/Tools**: Facebook Prophet, PyTorch Forecasting, InfluxDB (Time-series DB).
|
||||
---
|
||||
### 매 model spectrum
|
||||
1. **Classical**: ARIMA, SARIMA, ETS (Exponential Smoothing), Holt-Winters.
|
||||
2. **ML**: XGBoost on lag features, LightGBM (M5 winner).
|
||||
3. **Deep**: LSTM, Temporal Fusion Transformer, N-BEATS, N-HiTS.
|
||||
4. **Foundation models** (2024+): TimeGPT, Chronos (Amazon), Moirai (Salesforce), TimesFM (Google).
|
||||
|
||||
## 🤖 LLM 활용 힌트 (How to Use This Knowledge)
|
||||
### 매 응용
|
||||
1. Demand forecasting (retail, supply chain).
|
||||
2. Anomaly detection (monitoring, fraud).
|
||||
3. Financial markets (volatility, price).
|
||||
4. Energy load prediction.
|
||||
|
||||
**언제 이 지식을 쓰는가:**
|
||||
- *(TODO)*
|
||||
## 💻 패턴
|
||||
|
||||
**언제 쓰면 안 되는가:**
|
||||
- *(TODO)*
|
||||
### Pattern 1: ARIMA baseline (statsmodels)
|
||||
```python
|
||||
from statsmodels.tsa.arima.model import ARIMA
|
||||
import pandas as pd
|
||||
|
||||
## 🧪 검증 상태 (Validation)
|
||||
ts = pd.read_csv("sales.csv", parse_dates=["date"], index_col="date")["y"]
|
||||
model = ARIMA(ts, order=(2, 1, 2), seasonal_order=(1, 1, 1, 12))
|
||||
fit = model.fit()
|
||||
forecast = fit.forecast(steps=12)
|
||||
```
|
||||
|
||||
- **정보 상태:** needs_review
|
||||
- **출처 신뢰도:** A
|
||||
- **검토 이유:** *(P-Reinforce Phase 1 자동 정규화. 본문 검증 필요.)*
|
||||
### Pattern 2: Prophet (Meta)
|
||||
```python
|
||||
from prophet import Prophet
|
||||
|
||||
## 🧬 중복 검사 (Duplicate Check)
|
||||
df = pd.DataFrame({"ds": dates, "y": values})
|
||||
m = Prophet(yearly_seasonality=True, weekly_seasonality=True)
|
||||
m.add_country_holidays(country_name="KR")
|
||||
m.fit(df)
|
||||
future = m.make_future_dataframe(periods=90)
|
||||
fc = m.predict(future)
|
||||
```
|
||||
|
||||
- **기존 유사 문서:** *(TODO: 인덱서 클러스터 리포트 참조)*
|
||||
- **처리 방식:** UPDATE (자동 정규화)
|
||||
- **처리 이유:** Phase 1 정규화 — 옛 템플릿/누락 필드 보강.
|
||||
### Pattern 3: Darts (unified library, 2026 modern)
|
||||
```python
|
||||
from darts import TimeSeries
|
||||
from darts.models import TFTModel # Temporal Fusion Transformer
|
||||
|
||||
## 🕓 변경 이력 (Changelog)
|
||||
series = TimeSeries.from_dataframe(df, "ds", "y")
|
||||
train, val = series.split_before(0.8)
|
||||
|
||||
| 날짜 | 변경 내용 | 처리 방식 | 신뢰도 |
|
||||
|------|-----------|-----------|--------|
|
||||
| 2026-05-08 | P-Reinforce Phase 1 정규화 (frontmatter + 헤더 표준화) | UPDATE | A |
|
||||
model = TFTModel(
|
||||
input_chunk_length=24,
|
||||
output_chunk_length=12,
|
||||
hidden_size=64,
|
||||
lstm_layers=2,
|
||||
num_attention_heads=4,
|
||||
)
|
||||
model.fit(train, val_series=val)
|
||||
pred = model.predict(n=12)
|
||||
```
|
||||
|
||||
### Pattern 4: Foundation model zero-shot (Chronos)
|
||||
```python
|
||||
from chronos import ChronosPipeline
|
||||
import torch
|
||||
|
||||
pipe = ChronosPipeline.from_pretrained(
|
||||
"amazon/chronos-t5-large",
|
||||
device_map="cuda",
|
||||
torch_dtype=torch.bfloat16,
|
||||
)
|
||||
context = torch.tensor(history) # no fine-tune
|
||||
forecast = pipe.predict(context, prediction_length=24, num_samples=20)
|
||||
median = forecast.median(dim=1).values
|
||||
```
|
||||
|
||||
### Pattern 5: Anomaly detection (rolling z-score)
|
||||
```python
|
||||
import numpy as np
|
||||
|
||||
def rolling_anomaly(ts, window=30, threshold=3.0):
|
||||
rolling_mean = ts.rolling(window).mean()
|
||||
rolling_std = ts.rolling(window).std()
|
||||
z = (ts - rolling_mean) / rolling_std
|
||||
return np.abs(z) > threshold
|
||||
```
|
||||
|
||||
### Pattern 6: Backtesting (walk-forward)
|
||||
```python
|
||||
from sklearn.model_selection import TimeSeriesSplit
|
||||
|
||||
tscv = TimeSeriesSplit(n_splits=5)
|
||||
scores = []
|
||||
for train_idx, test_idx in tscv.split(X):
|
||||
model.fit(X[train_idx], y[train_idx])
|
||||
pred = model.predict(X[test_idx])
|
||||
scores.append(mape(y[test_idx], pred))
|
||||
```
|
||||
|
||||
### Pattern 7: Nixtla statsforecast (fast classical)
|
||||
```python
|
||||
from statsforecast import StatsForecast
|
||||
from statsforecast.models import AutoARIMA, AutoETS
|
||||
|
||||
sf = StatsForecast(
|
||||
models=[AutoARIMA(season_length=12), AutoETS(season_length=12)],
|
||||
freq="M",
|
||||
n_jobs=-1,
|
||||
)
|
||||
sf.fit(df)
|
||||
forecast = sf.forecast(h=12, level=[80, 95])
|
||||
```
|
||||
|
||||
## 매 결정 기준
|
||||
| 상황 | Approach |
|
||||
|---|---|
|
||||
| <1000 points, single series | ARIMA / Prophet |
|
||||
| Many related series, hierarchical | Nixtla statsforecast (parallel) |
|
||||
| Multivariate, many covariates | TFT, N-BEATSx (Darts) |
|
||||
| Zero-shot, no training data | Chronos / TimeGPT / TimesFM |
|
||||
| Real-time anomaly | Rolling z-score / Isolation Forest |
|
||||
|
||||
**기본값**: Prophet for prototype, Darts TFT or Chronos zero-shot for production.
|
||||
|
||||
## 🔗 Graph
|
||||
- 부모: [[Machine Learning]] · [[Statistics]]
|
||||
- 변형: [[ARIMA]] · [[Prophet]] · [[N-BEATS]]
|
||||
- 응용: [[Demand Forecasting]] · [[Anomaly Detection]] · [[Financial Modeling]]
|
||||
- Adjacent: [[LSTM]] · [[Transformer]] · [[Foundation Models]]
|
||||
|
||||
## 🤖 LLM 활용
|
||||
**언제**: temporal data forecasting, anomaly detection, capacity planning.
|
||||
**언제 X**: cross-sectional data without time component, pure classification.
|
||||
|
||||
## ❌ 안티패턴
|
||||
- **No stationarity check**: ARIMA에 non-stationary series 직접 적용.
|
||||
- **Random shuffling**: time series 의 train/test split 에 random shuffle 사용 (data leakage).
|
||||
- **MAPE on near-zero values**: division-by-zero / explosion. SMAPE 또는 MASE 사용.
|
||||
- **Ignoring seasonality**: yearly/weekly cycle 의 무시.
|
||||
- **Look-ahead bias**: future information 의 feature engineering 에 사용.
|
||||
|
||||
## 🧪 검증 / 중복
|
||||
- Verified (Hyndman, "Forecasting: Principles and Practice" 3rd ed; M-competition results; Chronos paper 2024).
|
||||
- 신뢰도 A.
|
||||
|
||||
## 🕓 Changelog
|
||||
| 날짜 | 변경 |
|
||||
|---|---|
|
||||
| 2026-05-08 | Phase 1 |
|
||||
| 2026-05-10 | Manual cleanup — full TSA spectrum (classical → foundation models) with code |
|
||||
|
||||
Reference in New Issue
Block a user