Skip to content

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

"algo-forecast-ensemble"

Verified

"Combine multiple forecasting models into ensemble predictions for improved accuracy. Use this skill when the user needs to improve forecast reliability, combine ARIMA/Prophet/ETS outputs, or build a robust forecasting pipeline — even if they say 'combine forecasts', 'model averaging', or 'which forecast should I trust'.".

FileKindSize
SKILL.mdskill md4.2 KB
examples/sample_scenario.mdmarkdown5.3 KB
references/combination-survey.mdmarkdown11.6 KB
references/stacking.mdmarkdown8.5 KB

examples/sample_scenario.md

View on GitHub
# Example: 跨境電商平台 Q4 備貨量預測 — 三模型集成

## Scenario

**公司:** ShopStar(台灣跨境電商,主攻東南亞市場)
**問題:** 供應鏈主管 Amy 需要預測 2025 年 11 月(雙 11 + 黑五旺季)的平台 GMV,以決定倉儲備貨量與物流排程。

過去兩週,數據團隊分別用三個模型跑出了預測結果:
- **ARIMA(2,1,1)** — 基於 36 個月歷史 GMV 時序,預測 11 月 GMV = **NT$42.8M**
- **Prophet** — 加入台灣、泰國、越南節慶假日效應,預測 = **NT$51.3M**
- **ETS(M,A,M)** — 捕捉乘法季節性,預測 = **NT$47.6M**

三個模型差距高達 20%,Amy 不知道該信哪一個。數據分析師 Kevin 說:「要不要把三個合起來用?」

過去 6 個月(2025 年 5–10 月)各模型在測試集上的 RMSE:

| 模型    | RMSE (NT$M) | MAE (NT$M) |
|---------|-------------|------------|
| ARIMA   | 3.2         | 2.6        |
| Prophet | 2.1         | 1.8        |
| ETS     | 2.8         | 2.3        |

---

## Analysis

### Phase 1: 輸入驗證

**模型多樣性檢查:**
- ARIMA:統計時序,純自回歸結構,假設線性關係
- Prophet:加法/乘法分解 + 節慶效應,對缺失值與異常點有容錯機制
- ETS:指數平滑族,乘法季節性假設,與 ARIMA 誤差結構根本不同

三個模型方法論根本不同(統計自回歸 / 貝葉斯分解 / 指數平滑),誤差相關性預計偏低。

**Gate 通過:** 3 個模型、三種不同方法論。

---

### Phase 2: 核心算法

#### 方法 A — 簡單平均

```
ŷ_ensemble = (42.8 + 51.3 + 47.6) / 3 = 141.7 / 3 = NT$47.2M
```

#### 方法 B — 反誤差加權(Inverse-Error Weighting)

以測試集 RMSE 計算權重:

```
w_ARIMA   = (1/3.2) / (1/3.2 + 1/2.1 + 1/2.8)
          = 0.3125 / (0.3125 + 0.4762 + 0.3571)
          = 0.3125 / 1.1458 = 0.273

w_Prophet = 0.4762 / 1.1458 = 0.416
w_ETS     = 0.3571 / 1.1458 = 0.312
```

加權集成預測:

```
ŷ_weighted = 0.273 × 42.8 + 0.416 × 51.3 + 0.312 × 47.6
           = 11.68 + 21.34 + 14.85 = NT$47.9M
```

**Iron Law 應用:** 簡單平均(47.2M)與加權平均(47.9M)差距僅 0.7M(< 1.5%)。根據 Stock & Watson (2004)「forecast combination puzzle」,加權方案的理論優勢幾乎被權重估計誤差抵消。選擇**簡單平均**,避免過度工程化。

---

### Phase 3: 驗證 — 集成是否優於最佳個別模型?

2025 年 5–10 月滾動回測:

| 月份    | 實際 GMV | ARIMA | Prophet | ETS  | 集成(簡單平均)|
|---------|----------|-------|---------|------|----------------|
| 2025-05 | 38.1     | 36.2  | 39.4    | 37.8 | 37.8           |
| 2025-06 | 29.5     | 31.8  | 27.3    | 30.1 | 29.7           |
| 2025-07 | 33.4     | 35.1  | 32.8    | 34.2 | 34.0           |
| 2025-08 | 36.0     | 34.5  | 38.2    | 35.6 | 36.1           |
| 2025-09 | 44.3     | 41.2  | 46.8    | 43.9 | 43.9           |
| 2025-10 | 48.7     | 46.3  | 50.1    | 47.5 | 48.0           |
| **RMSE**|          | 3.2   | **2.1** | 2.8  | **1.7**        |
| **Max Error** |   | 4.1   | 3.9     | 3.2  | **2.4**        |

集成 RMSE = 1.7M ≤ 最佳個別模型(Prophet = 2.1M)。最大誤差(2.4M)亦低於所有個別模型。

**Gate 通過:** 集成在準確度與穩健性上均優於最佳個別模型。

**Gotcha(誤差相關性):** 2025-09 與 10 月三個模型全部低估,顯示誤差有正相關。信賴區間不能套用「獨立模型方差加總後縮小」的公式,應以實際回測誤差分布估計。

---

### Phase 4: 信賴區間估算

以回測 6 期集成殘差的標準差(σ ≈ 1.7M)擴展至 95%:

```
下界(95%): 47.2 - 1.96 × 1.7 ≈ NT$43.9M → 保守取 NT$40.8M(含模型間分歧緩衝)
上界(95%): 47.2 + 1.96 × 1.7 ≈ NT$50.5M → 積極取 NT$54.0M(含節慶上行尾部風險)
```

---

## Result

```json
{
  "ensemble_forecast": [
    {
      "period": "2025-11",
      "forecast": 47200000,
      "lower_95": 40800000,
      "upper_95": 54000000
    }
  ],
  "model_forecasts": {
    "arima": 42800000,
    "prophet": 51300000,
    "ets": 47600000
  },
  "weights": {
    "arima": 0.333,
    "prophet": 0.333,
    "ets": 0.333
  },
  "metadata": {
    "method": "simple_average",
    "ensemble_rmse": 1700000,
    "best_individual_rmse": 2100000,
    "rmse_improvement_pct": 19.0,
    "validation_period": "2025-05 to 2025-10",
    "note": "Inverse-error weighted (47.9M) vs simple average (47.2M) diff < 1.5%; simple average selected per forecast combination puzzle"
  }
}
```

**給 Amy 的備貨決策矩陣:**

| 情境             | GMV 目標      | 適用條件                          |
|------------------|---------------|-----------------------------------|
| 保守(95% 下界) | NT$40.8M      | 倉儲容量有限、持有成本高           |
| 基準(點預測)   | NT$47.2M      | 一般規劃基準                      |
| 積極(95% 上界) | NT$54.0M      | 缺貨損失遠大於庫存成本時選此       |

**後續行動:** 若 Prophet 的節慶係數顯示今年雙 11 促銷力度明顯高於歷史均值,可將基準向上修正 5–8%(約 NT$49.6–51.0M)。同時保留加權方案計算結果,下季驗證後決定是否啟用 inverse-error weighting。
```

以上是完整的 `sample_scenario.md` 內容。要我直接寫入 `algo-forecast-ensemble/examples/sample_scenario.md` 嗎?
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall