---
id: wiki-2026-0508-time-series-analysis
title: Time Series Analysis
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Time Series, TSA, Forecasting, Temporal Analysis]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [time-series, forecasting, ml, statistics]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
  language: python
  framework: statsmodels-prophet-darts-nixtla
---

# Time Series Analysis

## 매 한 줄
> **"매 시간 축 위의 dependency가 modeling target"**. ARIMA의 classical 1970s 시대를 거쳐, 2020s에 Transformer-based foundation models (TimeGPT, Chronos, Moirai) 가 zero-shot forecasting을 가능케 했다. 매 2026 현재 hybrid (statistical + neural) 가 production default.

## 매 핵심

### 매 components
- **Trend**: long-term direction.
- **Seasonality**: periodic (daily, weekly, yearly).
- **Cyclic**: aperiodic fluctuations.
- **Residual**: noise / unexplained.

### 매 stationarity
- Strict / weak stationarity 의 distinction.
- ADF, KPSS test 로 확인.
- Differencing, log transform, Box-Cox 로 stationarize.

### 매 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).

### 매 응용
1. Demand forecasting (retail, supply chain).
2. Anomaly detection (monitoring, fraud).
3. Financial markets (volatility, price).
4. Energy load prediction.

## 💻 패턴

### Pattern 1: ARIMA baseline (statsmodels)
```python
from statsmodels.tsa.arima.model import ARIMA
import pandas as pd

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)
```

### Pattern 2: Prophet (Meta)
```python
from prophet import Prophet

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)
```

### Pattern 3: Darts (unified library, 2026 modern)
```python
from darts import TimeSeries
from darts.models import TFTModel  # Temporal Fusion Transformer

series = TimeSeries.from_dataframe(df, "ds", "y")
train, val = series.split_before(0.8)

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]]
- 응용: [[Anomaly Detection]]
- Adjacent: [[데이터_사이언스_및_ML_엔지니어링|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 |
