Ch02: Supervised Learning
一句話解釋
從有標註的資料中學習 input → output 的映射,並期望在未見資料上表現良好。
基本框架
監督式學習的組成
三個關鍵決策
| 決策 | 說明 |
|---|---|
| **1. Model(Hypothesis Space H)** | 定義候選模型的範圍 例:線性模型、決策樹、神經網路 |
| **2. Loss Function** | 如何衡量預測錯誤 例:0/1 loss、squared loss、cross-entropy |
| **3. Optimization Algorithm** | 如何找到最佳 h 例:梯度下降、EM algorithm |
Hypothesis Space
Hypothesis h:候選的「機器」(模型),從 hypothesis space $\mathcal{H}$ 中挑選。
$\mathcal{H}$ 的選擇決定了模型的表達能力和學習難度。
誤差類型
核心問題
⚠️ 關鍵挑戰:
Training error 低 $\neq$ Generalization error 低
Overfitting:模型在訓練資料上表現完美,但在新資料上表現差。
為什麼會 Overfitting?
- 模型太複雜: $\mathcal{H}$ 太大,能「記住」訓練資料的雜訊
- 訓練資料太少: 無法充分代表真實分佈
- 訓練時間太長: 過度優化訓練誤差
VC Dimension
定義
直觀理解
VC dimension 是 $\mathcal{H}$ 能完美記住(shatter)的最大資料集大小。
VC dimension 越大 → 模型越複雜 → 表達能力越強 → 需要更多資料才能學好。
經典例子
例 1:平面上的直線分類器
$\mathcal{H} = {h(x, y) = \text{sign}(ax + by + c)}$
問:VC dimension 是多少?
答:$VC(\mathcal{H}) = 3$
證明概念:
- 存在 3 個點,可以被直線 shatter(任意 $2^3 = 8$ 種 labeling 都能分開)
- 任意 4 個點,至少有一種 labeling 無法被直線分開(XOR 問題)
![]()
例 2:$\mathbb{R}^n$ 上的線性分類器
$\mathcal{H} = {h(x) = \text{sign}(w^T x + b)}$,其中 $x \in \mathbb{R}^n$
\[VC(\mathcal{H}) = n + 1\]意義:參數數量 = $n + 1$($w$ 有 $n$ 個元素 + bias $b$)
一般來說,參數數量可以作為 VC dimension 的粗略估計。
VC Dimension 與 Generalization
PAC Learning
定義
Sample Complexity
問:需要多少訓練資料 $N$?
三個變數的關係
實務意涵
Occam’s Razor(奧坎剃刀原則):
在表現相同時,偏好較簡單的模型。
原因:
- 簡單模型需要較少資料
- 泛化能力更好
- 更易理解和維護
⚠️ No Free Lunch Theorem:
沒有一個演算法在所有問題上都最優。
必須根據問題特性和先驗知識選擇合適的 $\mathcal{H}$。
Regression vs. Classification
| Classification | Regression | |
|---|---|---|
| **Output 空間** | 離散(class label) | 連續(實數) |
| **例子** | 垃圾郵件偵測、圖像識別 | 房價預測、溫度預測 |
| **常見 Loss** | 0/1 loss, cross-entropy | Squared loss, absolute loss |
| **評估指標** | Accuracy, Precision, Recall, F1 | MSE, MAE, $R^2$ |
共同點:
- 都屬於 supervised learning
- 都需要標註資料
- 都面臨 overfitting 問題
- 都可用 VC dimension 和 PAC learning 理論分析
總結
監督式學習的核心:
- 從 hypothesis space $\mathcal{H}$ 中選擇最佳 $h$
- 平衡 training error 與 generalization error
- 模型複雜度與資料量的權衡
理論工具:
- VC Dimension: 衡量模型複雜度
- PAC Learning: 分析樣本複雜度
- Occam’s Razor: 偏好簡單模型
下一步:
- Bayesian Decision Theory:如何做最優決策
- 具體演算法:Linear Models, SVM, Decision Trees 等
參考資料
- Shalev-Shwartz & Ben-David, Understanding Machine Learning, Chapters 2-6
- Abu-Mostafa et al., Learning from Data, Chapters 1-2
- Vapnik, The Nature of Statistical Learning Theory