Skip to content

charlieviettq/awesome-agent-skill / .claude/skills/algo-forecast-arima

"algo-forecast-arima"

Verified

"Build ARIMA models for time series forecasting with trend and seasonality decomposition. Use this skill when the user needs to forecast future values from historical sequential data, test for stationarity, or select ARIMA parameters — even if they say 'time series forecast', 'predict next month sales', or 'ARIMA model'.".

FileKindSize
SKILL.mdskill md4.5 KB
examples/sample_scenario.mdmarkdown3.8 KB
references/acf-pacf.mdmarkdown12.4 KB
references/seasonal-arima.mdmarkdown13.8 KB

examples/sample_scenario.md

View on GitHub
# Example: 台灣連鎖藥局月銷售量預測

## Scenario

大樹藥局採購部門需要預測 2025 年 Q2(4–6 月)的維他命 C 補充劑銷售量,以便提前備貨。歷史資料為 2020-01 至 2025-03 共 63 個月的月銷售量(單位:盒)。資料顯示每年 Q1 有明顯旺季峰值(流感季),整體有緩慢上升趨勢。

原始月銷售量(63 個月,擷取最後 18 個月代表):

| 月份 | 銷售量 |
|------|--------|
| 2023-10 | 8,420 |
| 2023-11 | 8,650 |
| 2023-12 | 9,100 |
| 2024-01 | 12,300 |
| 2024-02 | 11,800 |
| 2024-03 | 10,200 |
| 2024-04 | 8,800 |
| 2024-05 | 8,500 |
| 2024-06 | 8,200 |
| 2024-07 | 8,350 |
| 2024-08 | 8,600 |
| 2024-09 | 8,750 |
| 2024-10 | 8,900 |
| 2024-11 | 9,150 |
| 2024-12 | 9,600 |
| 2025-01 | 13,100 |
| 2025-02 | 12,500 |
| 2025-03 | 10,800 |

---

## Analysis

### Phase 1:Input Validation

- **觀測期數**:63 個月(> 50,且涵蓋 5 個完整年度季節週期)✓
- **時間間隔**:每月固定,無缺口 ✓
- **缺漏值**:無 ✓
- **目視判斷**:有正向趨勢 + 明顯年度季節性(s=12)

**ADF 檢定(原始序列):**
- 統計量 = −1.83,p = 0.37 → **p > 0.05,非穩態 (non-stationary)**,需要差分

**Gate passed:** 資料完整,需進行差分處理。

---

### Phase 2:Stationarity 處理

**一階差分(d=1)後 ADF 檢定:**
- 統計量 = −5.62,p = 0.000 → **p < 0.05,穩態** ✓

一階差分已足夠;不需要 d=2(避免 over-differencing)。

---

### Phase 3:Parameter Selection

**ACF / PACF 分析(一階差分後序列):**

- ACF:lag 12 出現顯著負峰值(seasonal MA);lag 1 輕微截尾 → q=1、Q=1
- PACF:lag 12 出現顯著正峰值(seasonal AR);lag 1 輕微截尾 → p=1、P=1

初始候選模型:**SARIMA(1,1,1)(1,1,1,12)**

**Auto-ARIMA AIC 比較(top 3):**

| 模型 | AIC |
|------|-----|
| SARIMA(1,1,1)(1,1,1,12) | 892.4 |
| SARIMA(0,1,1)(0,1,1,12) | 896.1 |
| SARIMA(1,1,0)(1,1,0,12) | 901.7 |

選定:**SARIMA(1,1,1)(1,1,1,12)**(最低 AIC)。

---

### Phase 4:Model Fit & Residual Diagnostics

**Ljung-Box 檢定(殘差,lag=24):**
- Q 統計量 = 21.3,p = 0.56 → **p > 0.05,殘差無自相關** ✓

**殘差常態性(Shapiro-Wilk):**
- p = 0.18 → 不拒絕常態假設 ✓

**Gate passed:** 殘差為白噪音,模型可用。

---

### Phase 5:Forecast(2025-04 to 2025-06)

以訓練期末值(2025-03 = 10,800)為基礎,模型捕捉到:
- 長期月增趨勢 ≈ +42 盒/月
- Q1 後的季節性回落(4 月較 1 月低約 30%)

---

## Result

```json
{
  "forecasts": [
    {"period": "2025-04", "forecast": 9100, "lower_95": 8450, "upper_95": 9750},
    {"period": "2025-05", "forecast": 8800, "lower_95": 7950, "upper_95": 9650},
    {"period": "2025-06", "forecast": 8550, "lower_95": 7550, "upper_95": 9550}
  ],
  "model": {
    "order": [1, 1, 1],
    "seasonal_order": [1, 1, 1, 12],
    "aic": 892.4
  },
  "metadata": {
    "training_periods": 63,
    "forecast_horizon": 3
  }
}
```

**採購建議:**

| 月份 | 預測銷量 | 建議備貨(加 10% 安全庫存) |
|------|----------|---------------------------|
| 2025-04 | 9,100 盒 | 10,010 盒 |
| 2025-05 | 8,800 盒 | 9,680 盒 |
| 2025-06 | 8,550 盒 | 9,405 盒 |

**注意事項:**
- 95% 信賴區間在 3 個月後已達 ±1,000 盒以上,建議不要將此模型延伸超過 Q3(6 個月以上的預測不確定性急遽擴大)。
- 2025 年若有政策性健保給付調整或重大流感疫情,屬於結構性斷裂(structural break),需重新訓練模型。
- 此序列未包含節假日效應變數;若農曆春節落點年份不同(如 2024 vs 2025),可能造成 Q1 峰值偏移,建議未來加入「春節週數」作為外生回歸項。
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall