11. Machine Learning (2)
More Details on (Supervised) Machine Learning
- ๋ถ์ผ ํ์ ์ ํ์ํ ํต์ฌ concepts
Supervised Learning
- Supervised learning์ ๊ณต์์ ์ธ ์์
- ๊ฐ์ ์ ์ถ๋ ฅ ์ ์ training set์ด ์ฃผ์ด์ง
- ๊ฐ ์์ ์ ์ ์๋ ํจ์ ์ ์ํด ์์ฑ
- ์ค์ ํจ์ ๋ฅผ ๊ทผ์ฌํ๋ ํจ์ ์ ๋ฐ๊ฒฌ
- ํจ์ : Hypothesis
- ๊ฐ๋ฅํ ํจ์ ์งํฉ์ธ hypothesis space ์์ ๋์ถ
- ์: Hypothesis space๋ 3์ฐจ ๋คํญ์(polynomials)์ ์งํฉ์ผ ์ ์์
- ๋ model class ์์ ๋์ถ๋ model์ด๊ฑฐ๋ function class์์ ๋์ถ๋ ํจ์
- ์ถ๋ ฅ : Ground truth (๋๋ gold-standard)
- Model์ด ์์ธกํ๋๋ก ์์ฒญ๋ฐ๋ ์ค์ ์ ๋ต
How Do We Choose a Hypothesis Space?
- ๋ฐ์ดํฐ ์์ฑ process์ ๋ํ ์ฌ์ ์ง์ ํ์ฉ
- ์ฌ์ ์ง์์ด ์๋ ๊ฒฝ์ฐ: Exploratory Data Analysis (EDA) ์ํ
- ํต๊ณ์ test ๋ฐ ์๊ฐํ(histograms, scatter plots, box plots ๋ฑ)๋ฅผ ํตํด ๋ฐ์ดํฐ ํ์ ๋ฐ ์ ์ ํ hypothesis space์ ๋ํ insight ์ป๊ธฐ
- ๋๋ ์ฌ๋ฌ hypothesis spaces๋ฅผ ์๋ํ๊ณ ๊ฐ์ฅ ์ ์๋ํ๋ ๊ฒ์ ํ๊ฐ

How Do We Choose a Good Hypothesis from the Hypothesis Space?
- ์ผ๊ด๋(consistent) hypothesis ๊ธฐ๋: Training set์ ๋ชจ๋ ์ ๋ํด
- Continuous-valued ์ถ๋ ฅ: Ground truth์ ์ ํํ ์ผ์นํ๊ธฐ ์ด๋ ค์. ๋์ ๊ฐ ์ ๊ฐ๊น์ด best-fit ํจ์ ํ์
- Hypothesis์ ์ง์ ํ ์ฒ๋: Training set์ด ์๋, ์์ง ๋ณด์ง ๋ชปํ ์ ๋ ฅ(test set)์ ์ฒ๋ฆฌํ๋ ๋ฅ๋ ฅ
- Test set: ์์ ๋ ๋ฒ์งธ sample๋ก ํ๊ฐ
- ๊ฐ test set์ ์ถ๋ ฅ์ ์ ํํ๊ฒ ์์ธกํ๋ฉด '์ผ๋ฐํ(generalizes well)'๊ฐ ์ ๋์๋ค๊ณ ํจ
Bias and Variance
- Hypothesis space ๋ถ์ ๋ฐฉ๋ฒ: Bias (๋ฐ์ดํฐ์ ๊ณผ ๋ฌด๊ด)์ variance (training set ๊ฐ์ ์ฐจ์ด)
- Bias: ๋ค๋ฅธ training sets์ ๋ํด ํ๊ท ์ ๋์ ๋, ์์ธก hypothesis๊ฐ ๊ธฐ๋๊ฐ์์ ๋ฒ์ด๋๋ ๊ฒฝํฅ
- Bias๋ ์ข ์ข hypothesis space์ ์ํด ๋ถ๊ณผ๋ ์ ์ฝ์ผ๋ก ์ธํด ๋ฐ์
- ์: ์ ํ ํจ์(linear functions)์ hypothesis space๋ ๊ฐํ bias๋ฅผ ์ ๋ (์ง์ ์ผ๋ก๋ง ๊ตฌ์ฑ)
- Hypothesis๊ฐ ๋ฐ์ดํฐ์์ pattern์ ์ฐพ์ง ๋ชปํ ๋: Underfitting
- Variance: Training data์ ๋ณ๋(fluctuation)์ผ๋ก ์ธํ hypothesis์ ๋ณํ๋
- Low variance: ๋ฐ์ดํฐ์ ์ ์์ ์ฐจ์ด๊ฐ hypothesis์ ์์ ์ฐจ์ด๋ก ์ด์ด์ง (์ฒ์ 3๊ฐ ์ด)
- High variance: 12์ฐจ ๋คํญ์(degree-12 polynomials)์ ๋์ variance๋ฅผ ๊ฐ์ง (x์ถ ์ ๋์์ ๋ ํจ์๊ฐ ๋งค์ฐ ๋ค๋ฆ)
- ํจ์๊ฐ ํ๋ จ๋ ํน์ data set์ ๋๋ฌด ์ง์คํ์ฌ, ๋ณด์ง ๋ชปํ ๋ฐ์ดํฐ(unseen data)์์ ์ฑ๋ฅ์ด ์ ํ๋ ๋: Overfitting
Bias-Variance Tradeoff
- ์ข ์ข bias-variance tradeoff ๋ฐ์
- ๋ณต์กํ๊ณ low-bias์ธ (training data์ ์ ๋ง๋) hypothesis์, ๋จ์ํ๊ณ low-variance์ธ (์ผ๋ฐํ๊ฐ ๋ ์ ๋ ์ ์๋) hypothesis ๊ฐ์ ์ ํ
- Ockham's razor (์ค์ปด์ ๋ฉด๋๋ )
- 14์ธ๊ธฐ ์๊ตญ ์ฒ ํ์ William of Ockham
- "ํ์ ์์ด (์ค์ฒด์) ๋ณต์์ฑ(plurality)์ ๊ฐ์ ํด์๋ ์ ๋๋ค"๋ ์์น. ์์ฌ์ค๋ฌ์ด ์ค๋ช ์ "๊น์๋ด๋(shave off)" ๋ฐ ์ฌ์ฉ๋จ

How to Find the Best Hypothesis
- Supervised learning: Data๊ฐ ์ฃผ์ด์ก์ ๋ ๊ฐ์ฅ ํ๋ฅ ์ด ๋์ hypothesis ์ ํ
- Bayes' rule์ ๋ฐ๋ผ:
- (์ฌ์ ํ๋ฅ , prior probability): ๋ถ๋๋ฌ์ด 1์ฐจ ๋๋ 2์ฐจ ๋คํญ์์์ ๋๊ณ , ํฌ๊ณ ๋พฐ์กฑํ 12์ฐจ ๋คํญ์์์ ๋ฎ์
- Data๊ฐ ์ ๋ง ํ์ํ๋ค๊ณ ํ ๋๋ง ํน์ดํ ํจ์๋ฅผ ํ์ฉํ๊ณ , ๋ฎ์ ์ฌ์ ํ๋ฅ ์ ๋ถ์ฌํ์ฌ ์ต์
- Q: ๋ฅผ ๋ชจ๋ ์ปดํจํฐ program ๋๋ ๋ชจ๋ Turing machine์ class๋ก ์ฌ์ฉํ์ง ์๋ ์ด์ ?
- A: Hypothesis space์ ํํ๋ ฅ(expressiveness)๊ณผ ๊ทธ ๊ณต๊ฐ ๋ด์์ ์ข์ hypothesis๋ฅผ ์ฐพ๋ ๊ณ์ฐ ๋ณต์ก์ฑ(computational complexity) ๊ฐ์ tradeoff ๋๋ฌธ
Model Selection and Optimization
I.I.D. Assumption
- Machine learning์ ๋ชฉํ: ๋ฏธ๋์ ์์(future examples)์ ์ต์ ์ผ๋ก ๋ง๋ hypothesis ์ ํ
- "๋ฏธ๋์ ์์"์ "์ต์ ์ ์ ํฉ(optimal fit)"์ด๋ ๋ฌด์์ธ๊ฐ?
- ๊ฐ์ 1: ๋ฏธ๋์ ์์๊ฐ ๊ณผ๊ฑฐ์ ๊ฐ์ ๊ฒ (Stationarity assumption)
- ๊ฐ ์์ ๋ ๋์ผํ ์ฌ์ ํ๋ฅ ๋ถํฌ(prior probability distribution)๋ฅผ ๊ฐ์ง:
- ๊ฐ ์์๋ ์ด์ ์์์ ๋
๋ฆฝ์ (independent):
- ์ด ๋ ๋ฐฉ์ ์์ ๋ง์กฑํ๋ ์์: Independent and identically distributed (๋ ๋ฆฝ ํญ๋ฑ ๋ถํฌ) ๋๋ i.i.d.
Error Rate and Two Different Datasets
- Optimal fit ์ ์: Error rate (์ค์ฐจ์จ)๋ฅผ ์ต์ํํ๋ hypothesis
- Error rate: ์์์ ๋ํด ์ธ ๋น์จ
- (์ถํ: "๊ฑฐ์" ์ ๋ต์ธ ๋ต๋ณ์ ๋ถ๋ถ ์ ์(partial credit) ํ์ฉ)
- Test set์ ํตํด hypothesis์ error rate ์ถ์
- Hypothesis๊ฐ test ์ ์ test ์ ๋ต์ ๋ณด๋ ๊ฒ์ cheating (๋ถ์ ํ์)
- ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ์ง๋ฒ: ์์๋ฅผ ๋ set์ผ๋ก ๋ถ๋ฆฌ
- Training set: Hypothesis ์์ฑ์ฉ
- Test set: Hypothesis ํ๊ฐ์ฉ
Hyperparameters and Three Datasets
- ๋จ์ผ hypothesis ์์ฑ ์: Training/test set ๋ถ๋ฆฌ๋ก ์ถฉ๋ถ
- ์ฌ๋ฌ hypothesis ์์ฑ ์ (์: ๋ ML model ๋น๊ต, model ๋ด ์ค์ ์กฐ์ ): ๋ถ์ถฉ๋ถ
- Hyperparameters: ๊ฐ๋ณ model์ด ์๋ model class์ parameters
- ์ฐ๊ตฌ์๊ฐ KNN classifier์ hyperparameter๋ฅผ ๋ฐ๊ฟ๊ฐ๋ฉฐ test set error rate๋ฅผ ์ธก์ ํ๋ ๊ฒฝ์ฐ:
- ๊ฐ๋ณ hypothesis๋ test set์ ๋ณด์ง ์์์ง๋ง, ์ฐ๊ตฌ์๋ฅผ ํตํด ์ ์ฒด process๊ฐ test set์ "์ฟ๋ด"
- ํด๊ฒฐ์ฑ : Training, experimenting, hyperparameter-tuning, re-training ๋ฑ์ด ๋ชจ๋ ๋๋ ๋๊น์ง test set์ ์์ ํ ๋ถ๋ฆฌ(hold out)
Three Datasets and Cross-Validation
- 3๊ฐ์ data set ํ์
- Training set: ํ๋ณด models ํ๋ จ
- Validation set (development set ๋๋ dev set): ํ๋ณด models ํ๊ฐ ๋ฐ ์ต์ ์ฑ ์ ํ
- Test set: ์ต์ข model์ ํธํฅ ์๋(unbiased) ์ต์ข ํ๊ฐ
- K-fold cross-validation
- 3๊ฐ set์ ๋ง๋ค๊ธฐ์ data๊ฐ ์ถฉ๋ถํ์ง ์์ ๋ ์ฌ์ฉ
- Data๋ฅผ ๊ฐ์ ๋์ผํ subset์ผ๋ก ๋ถ๋ฆฌ
- ๋ผ์ด๋์ ํ์ต ์ํ: ๋งค ๋ผ์ด๋๋ง๋ค ์ validation set์ผ๋ก, ๋๋จธ์ง๋ training set์ผ๋ก ์ฌ์ฉ
- ๋ง์ด ์ฐ์ด๋ ๊ฐ: 5, 10
- (Cross-validation ์ฌ์ฉ ์์๋) ์ฌ์ ํ ๋ณ๋์ test set ํ์

Model Selection and Optimization
- ์์: ์ ํ ํจ์(linear function)๋ data set์ underfit, ๊ณ ์ฐจ ๋คํญ์(high-degree polynomial)์ overfit
- ์ข์ hypothesis๋ฅผ ์ฐพ๋ ์์ ์ 2๊ฐ์ ํ์ ์์ ์ผ๋ก ๊ฐ์ฃผ ๊ฐ๋ฅ
- Model (class) selection (hypothesis space ์ ํ): ์ข์ hypothesis space ์ ํ
- Optimization (๋๋ training): ํด๋น space ๋ด์์ ์ต์์ hypothesis ํ์
Model Selection
- Model selection์ ์ผ๋ถ๋ ์ง์ (qualitative)์ด๊ณ ์ฃผ๊ด์ (subjective)
- ์: ๋ฌธ์ ์ ๋ํ ์ง์์ ๋ฐํ์ผ๋ก decision trees ๋์ polynomials ์ ํ
- Model selection์ ์ผ๋ถ๋ ์์ (quantitative)์ด๊ณ ๊ฒฝํ์ (empirical)
- ์: Polynomials class ๋ด์์, validation data set ์ฑ๋ฅ์ ๊ธฐ๋ฐํ์ฌ
Degree = 2์ ํ
An Algorithm for Model Selection

Two Different Patterns That Occur in Model Selection

- Model complexity๊ฐ ์ฆ๊ฐํจ์ ๋ฐ๋ผ training set error๋ ๋จ์กฐ๋กญ๊ฒ(monotonically) ๊ฐ์
- ๋ง์ model class์์ complexity๊ฐ ์ฆ๊ฐํ๋ฉด training set error๊ฐ 0์ ๋๋ฌ
- (a) U์ํ validation-error ๊ณก์
- (b) Validation error๊ฐ (์ฝ๊ฐ์ ๋ณ๋๊ณผ ํจ๊ป) ์ง์์ ์ผ๋ก ๊ฐ์ ์์
- ์ด๋ ์๋ก ๋ค๋ฅธ model class๊ฐ ์ด๊ณผ ์ฉ๋(excess capacity)์ ์ด๋ป๊ฒ ํ์ฉํ๋์ง, ๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ด ๋น๋ฉดํ ๋ฌธ์ ์ ์ผ๋ง๋ ์ ์ผ์นํ๋์ง์ ๋ฐ๋ผ ๋ฌ๋ผ์ง
