SlideShare a Scribd company logo
1 of 33
Download to read offline
Classification & Ensemble (1/33) Deeperence · CGLAB 이명규Deeperence · CGLAB 이명규
「파이썬 머신러닝 완벽 가이드」 Chapter 4
Classification &
Ensemble
Classification & Ensemble (2/33) Deeperence · CGLAB 이명규
I N D E X
01
02
03
Basic of ML
Classification
Ensemble
Classification & Ensemble (3/33) Deeperence · CGLAB 이명규
Basic of ML
Part 01
1. Bayes Theory
2. MLE vs MAP
Classification & Ensemble (4/33) Deeperence · CGLAB 이명규
↳
Bayes Theory
Bayes Rule
1-1
• Posteriori: 어떤 관측값 𝒙𝒙가 주어질 때 𝜽𝜽를 가지는 확률모형
• Prior: Parameter로 구성된 확률모형
(주어진 데이터로 추정하고자 하는 함수의 분포)
• Likelihood: 모델에 Parameter들이 주어질 때 관측값 𝒙𝒙를 얻을 확률
𝑷𝑷 𝜽𝜽 𝒙𝒙 =
𝒑𝒑 𝜽𝜽 𝒇𝒇(𝒙𝒙|𝜽𝜽)
𝒑𝒑(𝒙𝒙)
⇒ 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 ∝
𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 × 𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳
𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆
https://niceguy1575.tistory.com/87
• ML에서 푸는 모든 문제는 Evidence,
즉 발생 가능한 모든 posteriori의 합이
1이라 소거됨. (i.i.d condition)
• 모든 pmf의 합=확률=1(min=0, max=1)
Classification & Ensemble (5/33) Deeperence · CGLAB 이명규
↳
Bayes Theory
Bayes Rule
1-1
• Posteriori(𝑷𝑷 𝒙𝒙 𝒛𝒛 ): 사건이 발생한 후(=관측이 진행된 후) 사건이 특정
모델에서 발생했을 확률
• Prior(𝑷𝑷(𝒙𝒙)): 관측을 하기 전 모델에 대해 가지고 있는 선험적* 확률
• Likelihood(𝑷𝑷 𝒛𝒛 𝒙𝒙 ): 어떤 모델에서 관측값 𝒙𝒙를 얻을 확률
*경험적(기억에서 과거를 봄) ⇔ 선험적(기억의 패턴을 파악해 미래를 봄)
𝑷𝑷 𝒙𝒙 𝒛𝒛 =
𝒑𝒑(𝒙𝒙)𝒑𝒑 𝒛𝒛|𝒙𝒙
𝒑𝒑(𝒙𝒙)
https://niceguy1575.tistory.com/87
Classification & Ensemble (6/33) Deeperence · CGLAB 이명규
↳
Bayes Theory
i.i.d Condition
1-1
https://jgshin.tistory.com/7
• ‘Independent and Identically Distributed Condition’의 약자
• 동일한 모집단에서 동일한 분포를 따르는 데이터들이 독립적으로
샘플링되는 상황을 의미
• 샘플링된 데이터 집합의 평균은 모집단의 평균과 같고 정규분포를 따름.
• 독립된 두 사건의 Joint probability는 두 확률의 곱과 같다.
• 𝑿𝑿𝒏𝒏 = {𝑿𝑿𝟏𝟏, 𝑿𝑿𝟐𝟐, … , 𝑿𝑿𝒏𝒏}까지의 Random variables가 Mutually Independent,
즉 서로에 대해 Independent하지만 각 RV가 갖는 distribution이 같은
경우를 의미(=확률분포 모델이 같은 경우)
Classification & Ensemble (7/33) Deeperence · CGLAB 이명규
↳ MLE vs MAP
• MLE(Maximum Likelihood Estimation): 𝑷𝑷(𝟐𝟐𝟐𝟐𝟐𝟐 종양|암)과
𝑷𝑷(𝟐𝟐𝟐𝟐𝟐𝟐 종양|양성종양)을 비교(가장 큰 Likelihood를 비교)
• MAP(Maximum A Posteriori): 𝑷𝑷(암|𝟐𝟐𝟐𝟐𝟐𝟐 종양)와
𝑷𝑷(양성종양|𝟐𝟐𝟐𝟐𝟐𝟐 종양)을 비교(가장 큰 Posteriori를 비교)
관측치 : 2cm짜리 종양, Parameter : 암
모 대학병원의 의사가 환자의 CT사진을 보고 있습니다.
자세히 보니 특정 부분에 90% 확률로 정상인에게는 보이지 않아야 할
2cm짜리 종양이 찍혀 있습니다. 의사는 자신이 공부해 온 의학 지식들을
바탕으로 이 종양이 암인지 양성 종양인지 진단해야 합니다.
사진 속 종양이 암일 확률은 얼마일까요?
https://niceguy1575.tistory.com/87
1-2 MLE vs MAP
Classification & Ensemble (8/33) Deeperence · CGLAB 이명규
↳ MLE vs MAP
• MLE는 암이 맞을 때 2cm짜리 종양이 검출되었을 확률과
암이 아닐 때 2cm짜리 종양이 검출될 확률을 구함(Maximize likelihood)
• MAP는 종양이 검출되었을 때 그것이 암일 확률과 아닐 확률을 비교해
둘 중 큰 값을 갖는 클래스를 선택(Maximize posterior probability)
1-2 MLE vs MAP
https://niceguy1575.tistory.com/87
Classification & Ensemble (9/33) Deeperence · CGLAB 이명규
↳ 베이즈 이론을 다시 생각해 보면….
1-2
• Posteriori: 암일 확률(𝒙𝒙 =환자의 혈액 등으로부터 나온 feature vector)
• Prior: 암에 대한 확률모형(암 자체의 확률, 즉 의학 서적에 적힌 내용)
• Likelihood: 의사의 암 진단에 대한 경험
𝑷𝑷 𝜽𝜽 𝒙𝒙 =
𝒑𝒑 𝜽𝜽 𝒇𝒇(𝒙𝒙|𝜽𝜽)
𝒑𝒑(𝒙𝒙)
⇒ 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 ∝
𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 × 𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳
𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆
MLE vs MAP
Classification & Ensemble (10/33) Deeperence · CGLAB 이명규
↳ 다양한 곳에서 활용 가능한 베이즈 이론
𝑷𝑷 𝜽𝜽 𝒙𝒙
Feature data
- ‘환자의 혈액’, ‘소변검사결과’ 등
- ‘물고기의 색’, ‘모양’ 등
- ‘Sex’, ‘Age’, ‘SibSp’, ‘Parch’...(Titanic)
Label
- 암이 ‘맞다’, ‘아니다’ 여부
- ‘Salmon(연어)’ 등의 state
- ‘Survived’(Titanic)
“prior 확률 p(x)를 구하는 것은 쉬운 문제가
아니기 때문에 현실적으로는 MAP 대신
MLE가 사용되는 경우가 많다.”
https://darkpgmr.tistory.com/62
1-2 MLE vs MAP
Classification & Ensemble (11/33) Deeperence · CGLAB 이명규
↳ Decision vs. Estimation Problem
• 머신 러닝은 어떤 확률모델(가우스, 베르누이, …)을 써서라도
P가 1에 수렴하도록 학습하는 것
• Decision Problem: 맞다/아니다의 문제
• 자율주행차가 빨강불, 파랑불에 설지 말지 결정하는 문제
• 답해야 하는 질문 개수가 유한한 경우에 해당
• Regression도 Decision의 일종
• Estimation Problem: 무한한 요소들로 추정하는 문제
• 명화에 대해 선화, 채색 스타일 등의 다양한 확률분포 요소들을 두고
누구의 그림인지 추정하거나 모방하는 문제(e.g. Style Transfer)
1-2 MLE vs MAP
Classification & Ensemble (12/33) Deeperence · CGLAB 이명규
Classification
Part 02
1. Overview
2. Decision Tree
「파이썬 머신러닝 완벽 가이드」 Chapter 4
Classification & Ensemble (13/33) Deeperence · CGLAB 이명규
↳ Overview of Classification
• 지도학습의 대표적인 유형 중 하나
• 데이터의 feature과 label값에 존재하는 패턴을 학습해 모델 생성
• 생성된 모델에 새로운 데이터(test)가 주어졌을 때 미지의 label값 예측
• 분류 task를 수행하기 위한 다양한 알고리즘
• Naïve Bayes
• Logistic Regression
• Decision Tree, Random Forest
• SVM, KNN, NN, Ensemble 등
Classification2-1
Classification & Ensemble (14/33) Deeperence · CGLAB 이명규
↳ Overview
Decision Tree2-2
• 학습을 통해 Tree 기반의 분류 규칙 생성
• DT 구성을 위해 고려해야 하는 내용
1. 각 노드에서 몇 개의 가지로 나눌 것인가?
2. 각 노드의 Rule을 어떻게 만들 것인가?
3. 언제 트리 학습을 멈출 것인가?
4. Leaf 노드를 어느 부류에 할당할 것인가?
Root
Rule Rule
RuleLeaf
Leaf Leaf
Leaf Leaf
branch
Classification & Ensemble (15/33) Deeperence · CGLAB 이명규
↳ 결정 트리의 빌드 순서
Decision Tree2-2
• 결정 트리의 빌드 순서
1. 노드 하나를 생성하고 𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹 노드로 삼음. 𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹 𝒏𝒏𝒏𝒏𝒏𝒏𝒏𝒏를 𝒏𝒏𝒏𝒏𝒏𝒏𝒏𝒏 𝑻𝑻에 복사.
2. 루트 노드를 시작점으로 하여 순환 함수('ℝ')를 호출
1. 노드 T에서 후보 질문을 (여러 개) 생성
2. 모든 후보 질문들에 대한 불순도 감소량 측정
3. 불순도 감소량이 최대인 𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸 𝒒𝒒를 택 1.
4. 멈춤 조건에 대한 조건문 실행
1. 𝑵𝑵𝑵𝑵𝑵𝑵𝑵𝑵 𝑻𝑻가 멈춤 조건을 만족하는가? : 𝑻𝑻에 부류를 할당 (Leaf 노드로 삼고 트리의
성장을 멈춤)하고 반복문을 빠져나간다.
2. 𝑵𝑵𝑵𝑵𝑵𝑵𝑵𝑵 𝑻𝑻가 멈춤 조건을 만족하지 않는가? : 질문 𝒒𝒒로 𝑿𝑿𝒕𝒕를 𝑿𝑿𝒍𝒍𝒍𝒍𝒍𝒍𝒍𝒍와 𝑿𝑿𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓로 나눔.
5. 새로운 노드 𝑻𝑻𝒍𝒍𝒍𝒍𝒍𝒍𝒍𝒍와 𝑻𝑻𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓를 생성
6. 각각의 노드들에서 2번 각주의 순환 함수를 돌린다.
Classification & Ensemble (16/33) Deeperence · CGLAB 이명규
↳ Entropy
Decision Tree2-2
• 정보의 단위로, 확률변수가 가진 무질서도의 척도를 의미
• 어떤 𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅 𝒑𝒑(𝒙𝒙)에서 생성되는 𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅 𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗 𝒙𝒙*가
있을 때 이 𝒙𝒙가 전달하는 정보량을 계산하기 위한 것
• 분포가 균일할수록 불확실성이 낮아지고 엔트로피는 적어진다.
http://sanghyukchun.github.io/62/
https://roshansanthosh.wordpress.com/2017/06/16/entropy-and-information-gain/
*Random Variable: 확률적인 과정에 따라 값이 결정되는 변수로, 같은 확률공간*에 정의된 여러 확률
변수에 대해 이들의 조건부 확률이나 독립 여부를 결정 가능.
*Probability Space: 전체 measure가 1인 공간(보통 확률공간의 측도*는 확률을 정의함.)
*Measure(측도,測度): 특정 부분 집합에 일종의 크기를 부여해 계산할 수 있게 하는 함수.
𝑯𝑯 𝑿𝑿 = �
𝑥𝑥
𝑝𝑝 𝑥𝑥 ∗ log2(
1
𝑝𝑝(𝑥𝑥)
)
Classification & Ensemble (17/33) Deeperence · CGLAB 이명규
↳ Information Gain
Decision Tree2-2
https://roshansanthosh.wordpress.com/2017/06/16/entropy-and-information-gain/
• 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 𝑯𝑯 𝑿𝑿 𝒐𝒐𝒐𝒐 𝒂𝒂 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗 𝒙𝒙 = ∑𝒙𝒙 𝒑𝒑 𝒙𝒙 ∗ 𝐥𝐥𝐥𝐥𝐥𝐥𝟐𝟐(
𝟏𝟏
𝒑𝒑(𝒙𝒙)
)
• 𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮 𝑰𝑰𝑰𝑰 𝑻𝑻, 𝒂𝒂 = 𝑯𝑯 𝑻𝑻 − 𝑯𝑯(𝑻𝑻|𝒂𝒂)
• 어떤 변수가 다른 변수를 조건으로 할 때 정보의 증가 또는
엔트로피의 감소를 설명하는 함수(≒loss function)
Classification & Ensemble (18/33) Deeperence · CGLAB 이명규
↳ Information Gain
Decision Tree2-2 • 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 𝑯𝑯 𝑿𝑿 𝒐𝒐𝒐𝒐 𝒂𝒂 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗 𝒙𝒙 =
�
𝑥𝑥
𝑝𝑝 𝑥𝑥 ∗ log2(
1
𝑝𝑝(𝑥𝑥)
)
• 𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮 𝑰𝑰𝑰𝑰 𝑻𝑻, 𝒂𝒂 =
𝐻𝐻 𝑇𝑇 − 𝐻𝐻(𝑇𝑇|𝑎𝑎)
• 𝑰𝑰𝑰𝑰 𝑿𝑿 𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗 − 𝟗𝟗
𝟏𝟏𝟏𝟏
∗ 𝟎𝟎.𝟕𝟕𝟕𝟕𝟕𝟕𝟕𝟕 +
𝟖𝟖
𝟏𝟏𝟏𝟏
∗ 𝟎𝟎.𝟖𝟖𝟖𝟖𝟖𝟖𝟖𝟖
= 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐 bits
• 𝑰𝑰𝑰𝑰 𝑿𝑿 𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗 − 𝟗𝟗
𝟏𝟏𝟏𝟏
∗ 𝟎𝟎.𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗 +
𝟖𝟖
𝟏𝟏𝟏𝟏
∗𝟏𝟏.𝟎𝟎
= 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 bits
• 따라서 𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 변수가 𝑰𝑰𝑰𝑰를 높이는 좋은 Rule.
• Child 노드의 Impurity(순도)가 높을수록 𝑰𝑰𝑰𝑰 상승.
VS.
https://roshansanthosh.wordpress.com/2017/06/16/entropy-and-information-gain/
Classification & Ensemble (19/33) Deeperence · CGLAB 이명규
↳ Rules and Impurity
Decision Tree2-2
• 많은 Rules가 존재하는 것은 분류 결정 방식이 복잡해진다는
의미로, 과적합 가능성 증가
• Tree의 depth가 깊어질수록 예측 성능 저하
• 최대한 균일하게 데이터셋을 구성해야 함
• DT는 정보 균일도가 높은 데이터 셋을 우선 선택하도록 학습된다.
• 노드 균일도 측정에는 대표적으로 Gini Coefficient, Information
Gain 등이 활용
Classification & Ensemble (20/33) Deeperence · CGLAB 이명규
↳ 결정 트리의 장/단점
• 장점
• Information Gain등의 균일도를 기반으로 하므로 직관적
• 보통 각 피쳐의 Scaling과 Normalization을 할 필요가 없다.
• 단점
• 과적합 가능성이 높다(복잡해질수록 실제 상황에 유연한 대처 불가)
• 모든 데이터 상황을 만족하는 완벽한 규칙을 만들 수 없음
Decision Tree2-2
Classification & Ensemble (21/33) Deeperence · CGLAB 이명규
↳ 결정 트리의 파라미터 (1/2)
Decision Tree2-2
파라미터명 설명
min_samples_split
(default = 2)
• 노드를 분할하기 위한 최소한의 샘플 데이터 수 (과적합 제어에 사용)
• 작게 설정할수록 노드가 많아져서 과적합 가능성 증가
min_samples_leaf
• Leaf(말단 노드)가 되기 위한 최소한의 샘플 데이터 수
• Imbalanced data의 경우 특정 클래스의 데이터가 극도로 작을 수 있으므로 해당
경우는 작게 설정해야 함.
max_features
(default = None)
• 최적의 분할을 위해 고려할 최대 피쳐 개수
(None인 경우 데이터셋의 모든 피쳐 사용)
• Int일 경우 대상 피쳐의 개수, float인 경우 전체 중 대상 피쳐의 percentage
• Sqrt는 전체 피쳐 중 전체 피쳐 개수개 만큼 선정(auto=sqrt)
• Log는 전체 피쳐 중 log2(전체 피쳐 개수)개 선정
「파이썬 머신러닝 완벽 가이드」 Chapter 4
Classification & Ensemble (22/33) Deeperence · CGLAB 이명규
↳ 결정 트리의 파라미터 (1/2)
Decision Tree2-2
파라미터명 설명
max_depth
(default = None)
• 트리의 최대 깊이를 설정
• None인 경우 완벽하게 클래스 결정값이 될 때까지 깊이를 계속 키우거나 노드가 가지
는 데이터 개수가 min_samples_split보다 작아질 때까지 계속 깊이 증가
• 깊이가 깊어지면 min_samples_split에 따라 최대 분할하여 과적합 가능성이 있음.
max_leaf_modes • 말단 leaf 노드의 최대 개수를 지정
「파이썬 머신러닝 완벽 가이드」 Chapter 4
Classification & Ensemble (23/33) Deeperence · CGLAB 이명규
Ensemble
Part 03
1. Overview
2. Ensemble with
Resampling Method
「기계학습」 Chapter 12
Classification & Ensemble (24/33) Deeperence · CGLAB 이명규
↳
1. 웬만한 성능을 쉽게 얻을 수 있다.
2. 성능 향상을 꾀할 수 있다.
3. 데이터 양이 적어도 충분한 학습 효과를 거둘 수 있다.
4. 원하는 시점에서 데이터를 융합할 수 있다.
5. 점진적인 학습이 가능하다.
Overview
앙상블을 사용하는 이유
3-1
Classification & Ensemble (25/33) Deeperence · CGLAB 이명규
↳
• 사람들의 의사 결정 방식을 모방 (여러 알고리즘이 협동)
• 앙상블 생성 : 여러 전문가를 확보하는 과정
• 앙상블 선택 : 전문가 집단에서 보다 나은 전문가의 선택에 해당
• 앙상블 결합 : 전문가 의견을 합쳐 최종 의견을 만드는 과정에 해당
• 앙상블 생성 방식 : Voting, Bagging(e.g RF), Boosting(XGBoost),
Stacking, …
앙상블 생성 앙상블 선택 앙상블 결합
앙상블 생성
Overview3-1
Classification & Ensemble (26/33) Deeperence · CGLAB 이명규
↳
• 앙상블 결합에 참여하는 개별 분류기는 다양해야 함.
• 요소 분류기들이 틀리는 샘플이 서로 다를수록 ‘다양하다’ 라고 함.
• 분류기를 생성하는 방법
• 훈련 집합을 재샘플링(Resampling method)하는 방법, 특징 공간의
일부를 선택하는 부분 공간 방법(Subspace method)으로 나뉨
• Bagging과 Boosting은 재샘플링, Random Forest는
부분 공간 방법에 해당
앙상블에 사용되는 분류기의 다양성
3-1 Overview
Classification & Ensemble (27/33) Deeperence · CGLAB 이명규
↳
• DB의 질적 및 양적 품질은 인식기의 성능을 좌우
• 훈련 집합 이외에 별도의 검증 집합 필요
• 그러나 현실적인 문제들이 존재 :
DB수집에는 많은 시간과 비용이 필요
• 이 경우 Resampling Method을 통해 성능측정의 신뢰도 향상 도모
Ensemble with Resampling Method
재샘플링 기법
3-2
Classification & Ensemble (28/33) Deeperence · CGLAB 이명규
↳
• 모델 선택 문제를 푸는 알고리즘.
• Overall Idea
1. 샘플 집합에서 N개 샘플을 임의로 추출
2. 임의로 뽑은 샘플은 다시 넣음.
3. 이렇게 얻은 샘플 집합을 𝑿𝑿𝟏𝟏이라 하고,
이 샘플링 과정을 독립적으로 𝑇𝑇번 수행.
4. 모델 성능을 T번 측정 후 결과를 평균내어
최종 성능으로 취함.
Bootstrap Algorithm
3-2 Ensemble with Resampling Method
Classification & Ensemble (29/33) Deeperence · CGLAB 이명규
↳
• 부트스트랩 알고리즘을 앙상블
생성에 적용한 알고리즘
• Overall Idea
• T개의 샘플 집합 𝑿𝑿𝟏𝟏, 𝑿𝑿𝟏𝟏, …, 𝑿𝑿𝑻𝑻에서 𝑿𝑿𝒕𝒕를
훈련 집합으로 하여 분류기 𝒄𝒄𝒕𝒕를 만듬.
• 이 분류기 학습을 𝟏𝟏 ≤ 𝒕𝒕 ≤ 𝑻𝑻에 대해
독립적으로 수행하여 𝑇𝑇개의 분류기 생성.
Bootstrap Aggregating (Bagging) 기법
3-2 Ensemble with Resampling Method
Classification & Ensemble (30/33) Deeperence · CGLAB 이명규
↳
• 배깅보다 정교한 재샘플링 연산 사용
• 𝒕𝒕번째 분류기 𝒄𝒄𝒕𝒕와 𝒄𝒄𝒕𝒕+𝟏𝟏이 연관성을 갖고
만들어짐.
• 훈련 샘플은 𝒄𝒄𝒕𝒕가 맞춘 샘플과 틀린 샘플로 구분됨
• 맞춘 샘플은 가중치를 낮추지만 틀린 샘플은 높임.
• 𝒄𝒄𝒕𝒕+𝟏𝟏 은 가중치 정보를 고려해 가중치가 높은 샘플을
잘 맞추도록 학습 수행
AdaBoosting 기법
3-2 Ensemble with Resampling Method
Classification & Ensemble (31/33) Deeperence · CGLAB 이명규
↳
1. 라인 3에서 모든 샘플에 같은 가중치를 부여하고 시작
2. 라인 5는 가중치를 고려하여 분류기 𝒄𝒄𝒕𝒕를 학습시킴.
3. 라인 6~8은 새 분류기의 오류율 계산 (가중치 포함)
4. 라인 10는 오류율을 계산
5. 새 분류기가 만들어질 때마다 11~13에서 가중치 갱신
1. 틀린 샘플은 𝒆𝒆𝒆𝒆𝒆𝒆(𝜶𝜶𝒕𝒕)를 곱해 가중치를 높임
AdaBoosting 기법
3-2 Ensemble with Resampling Method
Classification & Ensemble (32/33) Deeperence · CGLAB 이명규
↳
• Bagging은 분류기가 서로 독립하여 학습을 수행
• AdaBoost는 분류기들이 상호 보완적이므로 현재 분류기의 약점을
다음 분류기가 보완해줌. (따라서 라인 5, 11~13의 가중치 관리가 핵심)
대치 허용 안함 대치 허용함
성능 평가에 쓰임 교차 검증 Bootstrap
앙상블 생성에 쓰임 Boosting Bagging
Bagging과 Boosting의 차이
3-2 Ensemble with Resampling Method
Classification & Ensemble (33/33) Deeperence · CGLAB 이명규
Thank you for Listening.
Email : brstar96@naver.com (or brstar96@soongsil.ac.kr)
Mobile : +82-10-8234-3179

More Related Content

Similar to (Book Summary) Classification and ensemble(book review)

Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리SANG WON PARK
 
3.unsupervised learing
3.unsupervised learing3.unsupervised learing
3.unsupervised learingHaesun Park
 
알파고 풀어보기 / Alpha Technical Review
알파고 풀어보기 / Alpha Technical Review알파고 풀어보기 / Alpha Technical Review
알파고 풀어보기 / Alpha Technical Review상은 박
 
Crash Course on Graphical models
Crash Course on Graphical modelsCrash Course on Graphical models
Crash Course on Graphical modelsJong Wook Kim
 
2.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-32.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-3Haesun Park
 
boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)SANG WON PARK
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리Haesun Park
 
Learning by association
Learning by associationLearning by association
Learning by association홍배 김
 
3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)Haesun Park
 
Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...
Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...
Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...태엽 김
 
K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링Edward Yoon
 
천체 유형 분류 대회 2위 수상자 코드 설명
천체 유형 분류 대회 2위 수상자 코드 설명천체 유형 분류 대회 2위 수상자 코드 설명
천체 유형 분류 대회 2위 수상자 코드 설명DACON AI 데이콘
 
(Book summary) Ensemble method 2018summerml_study
(Book summary) Ensemble method 2018summerml_study(Book summary) Ensemble method 2018summerml_study
(Book summary) Ensemble method 2018summerml_studyMYEONGGYU LEE
 
Lecture 4: Neural Networks I
Lecture 4: Neural Networks ILecture 4: Neural Networks I
Lecture 4: Neural Networks ISang Jun Lee
 
발표자료 11장
발표자료 11장발표자료 11장
발표자료 11장Juhui Park
 
[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentation
[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentation[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentation
[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentationtaeseon ryu
 
[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가
[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가
[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가NAVER Engineering
 

Similar to (Book Summary) Classification and ensemble(book review) (20)

Naive ML Overview
Naive ML OverviewNaive ML Overview
Naive ML Overview
 
Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리
 
3.unsupervised learing
3.unsupervised learing3.unsupervised learing
3.unsupervised learing
 
Review MLP Mixer
Review MLP MixerReview MLP Mixer
Review MLP Mixer
 
알파고 풀어보기 / Alpha Technical Review
알파고 풀어보기 / Alpha Technical Review알파고 풀어보기 / Alpha Technical Review
알파고 풀어보기 / Alpha Technical Review
 
Crash Course on Graphical models
Crash Course on Graphical modelsCrash Course on Graphical models
Crash Course on Graphical models
 
DL from scratch(6)
DL from scratch(6)DL from scratch(6)
DL from scratch(6)
 
2.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-32.supervised learning(epoch#2)-3
2.supervised learning(epoch#2)-3
 
boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)
 
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
[홍대 머신러닝 스터디 - 핸즈온 머신러닝] 6장 결정 트리
 
Learning by association
Learning by associationLearning by association
Learning by association
 
3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)3.unsupervised learing(epoch#2)
3.unsupervised learing(epoch#2)
 
Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...
Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...
Progressive Growing of GANs for Improved Quality, Stability, and Variation Re...
 
K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링K means 알고리즘을 이용한 영화배우 클러스터링
K means 알고리즘을 이용한 영화배우 클러스터링
 
천체 유형 분류 대회 2위 수상자 코드 설명
천체 유형 분류 대회 2위 수상자 코드 설명천체 유형 분류 대회 2위 수상자 코드 설명
천체 유형 분류 대회 2위 수상자 코드 설명
 
(Book summary) Ensemble method 2018summerml_study
(Book summary) Ensemble method 2018summerml_study(Book summary) Ensemble method 2018summerml_study
(Book summary) Ensemble method 2018summerml_study
 
Lecture 4: Neural Networks I
Lecture 4: Neural Networks ILecture 4: Neural Networks I
Lecture 4: Neural Networks I
 
발표자료 11장
발표자료 11장발표자료 11장
발표자료 11장
 
[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentation
[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentation[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentation
[2023] Cut and Learn for Unsupervised Object Detection and Instance Segmentation
 
[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가
[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가
[네이버AI해커톤]어떻게 걱정을 멈추고 베이스라인을 사랑하는 법을 배우게 되었는가
 

More from MYEONGGYU LEE

(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...
(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...
(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...MYEONGGYU LEE
 
Survey of HDR & Tone Mapping Task
Survey of HDR & Tone Mapping TaskSurvey of HDR & Tone Mapping Task
Survey of HDR & Tone Mapping TaskMYEONGGYU LEE
 
Survey of Super Resolution Task (SISR Only)
Survey of Super Resolution Task (SISR Only)Survey of Super Resolution Task (SISR Only)
Survey of Super Resolution Task (SISR Only)MYEONGGYU LEE
 
Simple Review of Single Image Super Resolution Task
Simple Review of Single Image Super Resolution TaskSimple Review of Single Image Super Resolution Task
Simple Review of Single Image Super Resolution TaskMYEONGGYU LEE
 
(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...
(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...
(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...MYEONGGYU LEE
 
(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...
(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...
(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...MYEONGGYU LEE
 
(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...
(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...
(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...MYEONGGYU LEE
 
(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...
(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...
(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...MYEONGGYU LEE
 
(Paper Review)Neural 3D mesh renderer
(Paper Review)Neural 3D mesh renderer(Paper Review)Neural 3D mesh renderer
(Paper Review)Neural 3D mesh rendererMYEONGGYU LEE
 
(Paper Review)3D shape reconstruction from sketches via multi view convolutio...
(Paper Review)3D shape reconstruction from sketches via multi view convolutio...(Paper Review)3D shape reconstruction from sketches via multi view convolutio...
(Paper Review)3D shape reconstruction from sketches via multi view convolutio...MYEONGGYU LEE
 
(Paper Review)Image to image translation with conditional adversarial network...
(Paper Review)Image to image translation with conditional adversarial network...(Paper Review)Image to image translation with conditional adversarial network...
(Paper Review)Image to image translation with conditional adversarial network...MYEONGGYU LEE
 
(Paper Review)Towards foveated rendering for gaze tracked virtual reality
(Paper Review)Towards foveated rendering for gaze tracked virtual reality(Paper Review)Towards foveated rendering for gaze tracked virtual reality
(Paper Review)Towards foveated rendering for gaze tracked virtual realityMYEONGGYU LEE
 
(Paper Review)Geometrically correct projection-based texture mapping onto a d...
(Paper Review)Geometrically correct projection-based texture mapping onto a d...(Paper Review)Geometrically correct projection-based texture mapping onto a d...
(Paper Review)Geometrically correct projection-based texture mapping onto a d...MYEONGGYU LEE
 
(Papers Review)CNN for sentence classification
(Papers Review)CNN for sentence classification(Papers Review)CNN for sentence classification
(Papers Review)CNN for sentence classificationMYEONGGYU LEE
 
(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...
(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...
(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...MYEONGGYU LEE
 

More from MYEONGGYU LEE (16)

(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...
(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...
(Paper Review) Abnormal Event Detection in Videos using Generative Adversaria...
 
Survey of HDR & Tone Mapping Task
Survey of HDR & Tone Mapping TaskSurvey of HDR & Tone Mapping Task
Survey of HDR & Tone Mapping Task
 
Survey of Super Resolution Task (SISR Only)
Survey of Super Resolution Task (SISR Only)Survey of Super Resolution Task (SISR Only)
Survey of Super Resolution Task (SISR Only)
 
Simple Review of Single Image Super Resolution Task
Simple Review of Single Image Super Resolution TaskSimple Review of Single Image Super Resolution Task
Simple Review of Single Image Super Resolution Task
 
ICCV 2019 Review
ICCV 2019 ReviewICCV 2019 Review
ICCV 2019 Review
 
(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...
(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...
(Paper Review)Few-Shot Adversarial Learning of Realistic Neural Talking Head ...
 
(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...
(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...
(Paper Review)U-GAT-IT: unsupervised generative attentional networks with ada...
 
(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...
(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...
(Paper Review) Reconstruction of Monte Carlo Image Sequences using a Recurren...
 
(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...
(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...
(Paper Review)A versatile learning based 3D temporal tracker - scalable, robu...
 
(Paper Review)Neural 3D mesh renderer
(Paper Review)Neural 3D mesh renderer(Paper Review)Neural 3D mesh renderer
(Paper Review)Neural 3D mesh renderer
 
(Paper Review)3D shape reconstruction from sketches via multi view convolutio...
(Paper Review)3D shape reconstruction from sketches via multi view convolutio...(Paper Review)3D shape reconstruction from sketches via multi view convolutio...
(Paper Review)3D shape reconstruction from sketches via multi view convolutio...
 
(Paper Review)Image to image translation with conditional adversarial network...
(Paper Review)Image to image translation with conditional adversarial network...(Paper Review)Image to image translation with conditional adversarial network...
(Paper Review)Image to image translation with conditional adversarial network...
 
(Paper Review)Towards foveated rendering for gaze tracked virtual reality
(Paper Review)Towards foveated rendering for gaze tracked virtual reality(Paper Review)Towards foveated rendering for gaze tracked virtual reality
(Paper Review)Towards foveated rendering for gaze tracked virtual reality
 
(Paper Review)Geometrically correct projection-based texture mapping onto a d...
(Paper Review)Geometrically correct projection-based texture mapping onto a d...(Paper Review)Geometrically correct projection-based texture mapping onto a d...
(Paper Review)Geometrically correct projection-based texture mapping onto a d...
 
(Papers Review)CNN for sentence classification
(Papers Review)CNN for sentence classification(Papers Review)CNN for sentence classification
(Papers Review)CNN for sentence classification
 
(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...
(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...
(Paper Review)Kernel predicting-convolutional-networks-for-denoising-monte-ca...
 

(Book Summary) Classification and ensemble(book review)

  • 1. Classification & Ensemble (1/33) Deeperence · CGLAB 이명규Deeperence · CGLAB 이명규 「파이썬 머신러닝 완벽 가이드」 Chapter 4 Classification & Ensemble
  • 2. Classification & Ensemble (2/33) Deeperence · CGLAB 이명규 I N D E X 01 02 03 Basic of ML Classification Ensemble
  • 3. Classification & Ensemble (3/33) Deeperence · CGLAB 이명규 Basic of ML Part 01 1. Bayes Theory 2. MLE vs MAP
  • 4. Classification & Ensemble (4/33) Deeperence · CGLAB 이명규 ↳ Bayes Theory Bayes Rule 1-1 • Posteriori: 어떤 관측값 𝒙𝒙가 주어질 때 𝜽𝜽를 가지는 확률모형 • Prior: Parameter로 구성된 확률모형 (주어진 데이터로 추정하고자 하는 함수의 분포) • Likelihood: 모델에 Parameter들이 주어질 때 관측값 𝒙𝒙를 얻을 확률 𝑷𝑷 𝜽𝜽 𝒙𝒙 = 𝒑𝒑 𝜽𝜽 𝒇𝒇(𝒙𝒙|𝜽𝜽) 𝒑𝒑(𝒙𝒙) ⇒ 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 ∝ 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 × 𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 https://niceguy1575.tistory.com/87 • ML에서 푸는 모든 문제는 Evidence, 즉 발생 가능한 모든 posteriori의 합이 1이라 소거됨. (i.i.d condition) • 모든 pmf의 합=확률=1(min=0, max=1)
  • 5. Classification & Ensemble (5/33) Deeperence · CGLAB 이명규 ↳ Bayes Theory Bayes Rule 1-1 • Posteriori(𝑷𝑷 𝒙𝒙 𝒛𝒛 ): 사건이 발생한 후(=관측이 진행된 후) 사건이 특정 모델에서 발생했을 확률 • Prior(𝑷𝑷(𝒙𝒙)): 관측을 하기 전 모델에 대해 가지고 있는 선험적* 확률 • Likelihood(𝑷𝑷 𝒛𝒛 𝒙𝒙 ): 어떤 모델에서 관측값 𝒙𝒙를 얻을 확률 *경험적(기억에서 과거를 봄) ⇔ 선험적(기억의 패턴을 파악해 미래를 봄) 𝑷𝑷 𝒙𝒙 𝒛𝒛 = 𝒑𝒑(𝒙𝒙)𝒑𝒑 𝒛𝒛|𝒙𝒙 𝒑𝒑(𝒙𝒙) https://niceguy1575.tistory.com/87
  • 6. Classification & Ensemble (6/33) Deeperence · CGLAB 이명규 ↳ Bayes Theory i.i.d Condition 1-1 https://jgshin.tistory.com/7 • ‘Independent and Identically Distributed Condition’의 약자 • 동일한 모집단에서 동일한 분포를 따르는 데이터들이 독립적으로 샘플링되는 상황을 의미 • 샘플링된 데이터 집합의 평균은 모집단의 평균과 같고 정규분포를 따름. • 독립된 두 사건의 Joint probability는 두 확률의 곱과 같다. • 𝑿𝑿𝒏𝒏 = {𝑿𝑿𝟏𝟏, 𝑿𝑿𝟐𝟐, … , 𝑿𝑿𝒏𝒏}까지의 Random variables가 Mutually Independent, 즉 서로에 대해 Independent하지만 각 RV가 갖는 distribution이 같은 경우를 의미(=확률분포 모델이 같은 경우)
  • 7. Classification & Ensemble (7/33) Deeperence · CGLAB 이명규 ↳ MLE vs MAP • MLE(Maximum Likelihood Estimation): 𝑷𝑷(𝟐𝟐𝟐𝟐𝟐𝟐 종양|암)과 𝑷𝑷(𝟐𝟐𝟐𝟐𝟐𝟐 종양|양성종양)을 비교(가장 큰 Likelihood를 비교) • MAP(Maximum A Posteriori): 𝑷𝑷(암|𝟐𝟐𝟐𝟐𝟐𝟐 종양)와 𝑷𝑷(양성종양|𝟐𝟐𝟐𝟐𝟐𝟐 종양)을 비교(가장 큰 Posteriori를 비교) 관측치 : 2cm짜리 종양, Parameter : 암 모 대학병원의 의사가 환자의 CT사진을 보고 있습니다. 자세히 보니 특정 부분에 90% 확률로 정상인에게는 보이지 않아야 할 2cm짜리 종양이 찍혀 있습니다. 의사는 자신이 공부해 온 의학 지식들을 바탕으로 이 종양이 암인지 양성 종양인지 진단해야 합니다. 사진 속 종양이 암일 확률은 얼마일까요? https://niceguy1575.tistory.com/87 1-2 MLE vs MAP
  • 8. Classification & Ensemble (8/33) Deeperence · CGLAB 이명규 ↳ MLE vs MAP • MLE는 암이 맞을 때 2cm짜리 종양이 검출되었을 확률과 암이 아닐 때 2cm짜리 종양이 검출될 확률을 구함(Maximize likelihood) • MAP는 종양이 검출되었을 때 그것이 암일 확률과 아닐 확률을 비교해 둘 중 큰 값을 갖는 클래스를 선택(Maximize posterior probability) 1-2 MLE vs MAP https://niceguy1575.tistory.com/87
  • 9. Classification & Ensemble (9/33) Deeperence · CGLAB 이명규 ↳ 베이즈 이론을 다시 생각해 보면…. 1-2 • Posteriori: 암일 확률(𝒙𝒙 =환자의 혈액 등으로부터 나온 feature vector) • Prior: 암에 대한 확률모형(암 자체의 확률, 즉 의학 서적에 적힌 내용) • Likelihood: 의사의 암 진단에 대한 경험 𝑷𝑷 𝜽𝜽 𝒙𝒙 = 𝒑𝒑 𝜽𝜽 𝒇𝒇(𝒙𝒙|𝜽𝜽) 𝒑𝒑(𝒙𝒙) ⇒ 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 ∝ 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷 × 𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 𝑳𝑳𝑳𝑳𝑳𝑳𝑳𝑳 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 MLE vs MAP
  • 10. Classification & Ensemble (10/33) Deeperence · CGLAB 이명규 ↳ 다양한 곳에서 활용 가능한 베이즈 이론 𝑷𝑷 𝜽𝜽 𝒙𝒙 Feature data - ‘환자의 혈액’, ‘소변검사결과’ 등 - ‘물고기의 색’, ‘모양’ 등 - ‘Sex’, ‘Age’, ‘SibSp’, ‘Parch’...(Titanic) Label - 암이 ‘맞다’, ‘아니다’ 여부 - ‘Salmon(연어)’ 등의 state - ‘Survived’(Titanic) “prior 확률 p(x)를 구하는 것은 쉬운 문제가 아니기 때문에 현실적으로는 MAP 대신 MLE가 사용되는 경우가 많다.” https://darkpgmr.tistory.com/62 1-2 MLE vs MAP
  • 11. Classification & Ensemble (11/33) Deeperence · CGLAB 이명규 ↳ Decision vs. Estimation Problem • 머신 러닝은 어떤 확률모델(가우스, 베르누이, …)을 써서라도 P가 1에 수렴하도록 학습하는 것 • Decision Problem: 맞다/아니다의 문제 • 자율주행차가 빨강불, 파랑불에 설지 말지 결정하는 문제 • 답해야 하는 질문 개수가 유한한 경우에 해당 • Regression도 Decision의 일종 • Estimation Problem: 무한한 요소들로 추정하는 문제 • 명화에 대해 선화, 채색 스타일 등의 다양한 확률분포 요소들을 두고 누구의 그림인지 추정하거나 모방하는 문제(e.g. Style Transfer) 1-2 MLE vs MAP
  • 12. Classification & Ensemble (12/33) Deeperence · CGLAB 이명규 Classification Part 02 1. Overview 2. Decision Tree 「파이썬 머신러닝 완벽 가이드」 Chapter 4
  • 13. Classification & Ensemble (13/33) Deeperence · CGLAB 이명규 ↳ Overview of Classification • 지도학습의 대표적인 유형 중 하나 • 데이터의 feature과 label값에 존재하는 패턴을 학습해 모델 생성 • 생성된 모델에 새로운 데이터(test)가 주어졌을 때 미지의 label값 예측 • 분류 task를 수행하기 위한 다양한 알고리즘 • Naïve Bayes • Logistic Regression • Decision Tree, Random Forest • SVM, KNN, NN, Ensemble 등 Classification2-1
  • 14. Classification & Ensemble (14/33) Deeperence · CGLAB 이명규 ↳ Overview Decision Tree2-2 • 학습을 통해 Tree 기반의 분류 규칙 생성 • DT 구성을 위해 고려해야 하는 내용 1. 각 노드에서 몇 개의 가지로 나눌 것인가? 2. 각 노드의 Rule을 어떻게 만들 것인가? 3. 언제 트리 학습을 멈출 것인가? 4. Leaf 노드를 어느 부류에 할당할 것인가? Root Rule Rule RuleLeaf Leaf Leaf Leaf Leaf branch
  • 15. Classification & Ensemble (15/33) Deeperence · CGLAB 이명규 ↳ 결정 트리의 빌드 순서 Decision Tree2-2 • 결정 트리의 빌드 순서 1. 노드 하나를 생성하고 𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹 노드로 삼음. 𝑹𝑹𝑹𝑹𝑹𝑹𝑹𝑹 𝒏𝒏𝒏𝒏𝒏𝒏𝒏𝒏를 𝒏𝒏𝒏𝒏𝒏𝒏𝒏𝒏 𝑻𝑻에 복사. 2. 루트 노드를 시작점으로 하여 순환 함수('ℝ')를 호출 1. 노드 T에서 후보 질문을 (여러 개) 생성 2. 모든 후보 질문들에 대한 불순도 감소량 측정 3. 불순도 감소량이 최대인 𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸𝑸 𝒒𝒒를 택 1. 4. 멈춤 조건에 대한 조건문 실행 1. 𝑵𝑵𝑵𝑵𝑵𝑵𝑵𝑵 𝑻𝑻가 멈춤 조건을 만족하는가? : 𝑻𝑻에 부류를 할당 (Leaf 노드로 삼고 트리의 성장을 멈춤)하고 반복문을 빠져나간다. 2. 𝑵𝑵𝑵𝑵𝑵𝑵𝑵𝑵 𝑻𝑻가 멈춤 조건을 만족하지 않는가? : 질문 𝒒𝒒로 𝑿𝑿𝒕𝒕를 𝑿𝑿𝒍𝒍𝒍𝒍𝒍𝒍𝒍𝒍와 𝑿𝑿𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓로 나눔. 5. 새로운 노드 𝑻𝑻𝒍𝒍𝒍𝒍𝒍𝒍𝒍𝒍와 𝑻𝑻𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓를 생성 6. 각각의 노드들에서 2번 각주의 순환 함수를 돌린다.
  • 16. Classification & Ensemble (16/33) Deeperence · CGLAB 이명규 ↳ Entropy Decision Tree2-2 • 정보의 단위로, 확률변수가 가진 무질서도의 척도를 의미 • 어떤 𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅 𝒑𝒑(𝒙𝒙)에서 생성되는 𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅𝒅 𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓𝒓 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗 𝒙𝒙*가 있을 때 이 𝒙𝒙가 전달하는 정보량을 계산하기 위한 것 • 분포가 균일할수록 불확실성이 낮아지고 엔트로피는 적어진다. http://sanghyukchun.github.io/62/ https://roshansanthosh.wordpress.com/2017/06/16/entropy-and-information-gain/ *Random Variable: 확률적인 과정에 따라 값이 결정되는 변수로, 같은 확률공간*에 정의된 여러 확률 변수에 대해 이들의 조건부 확률이나 독립 여부를 결정 가능. *Probability Space: 전체 measure가 1인 공간(보통 확률공간의 측도*는 확률을 정의함.) *Measure(측도,測度): 특정 부분 집합에 일종의 크기를 부여해 계산할 수 있게 하는 함수. 𝑯𝑯 𝑿𝑿 = � 𝑥𝑥 𝑝𝑝 𝑥𝑥 ∗ log2( 1 𝑝𝑝(𝑥𝑥) )
  • 17. Classification & Ensemble (17/33) Deeperence · CGLAB 이명규 ↳ Information Gain Decision Tree2-2 https://roshansanthosh.wordpress.com/2017/06/16/entropy-and-information-gain/ • 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 𝑯𝑯 𝑿𝑿 𝒐𝒐𝒐𝒐 𝒂𝒂 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗 𝒙𝒙 = ∑𝒙𝒙 𝒑𝒑 𝒙𝒙 ∗ 𝐥𝐥𝐥𝐥𝐥𝐥𝟐𝟐( 𝟏𝟏 𝒑𝒑(𝒙𝒙) ) • 𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮 𝑰𝑰𝑰𝑰 𝑻𝑻, 𝒂𝒂 = 𝑯𝑯 𝑻𝑻 − 𝑯𝑯(𝑻𝑻|𝒂𝒂) • 어떤 변수가 다른 변수를 조건으로 할 때 정보의 증가 또는 엔트로피의 감소를 설명하는 함수(≒loss function)
  • 18. Classification & Ensemble (18/33) Deeperence · CGLAB 이명규 ↳ Information Gain Decision Tree2-2 • 𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆𝒆 𝑯𝑯 𝑿𝑿 𝒐𝒐𝒐𝒐 𝒂𝒂 𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗𝒗 𝒙𝒙 = � 𝑥𝑥 𝑝𝑝 𝑥𝑥 ∗ log2( 1 𝑝𝑝(𝑥𝑥) ) • 𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰𝑰 𝑮𝑮𝑮𝑮𝑮𝑮𝑮𝑮 𝑰𝑰𝑰𝑰 𝑻𝑻, 𝒂𝒂 = 𝐻𝐻 𝑇𝑇 − 𝐻𝐻(𝑇𝑇|𝑎𝑎) • 𝑰𝑰𝑰𝑰 𝑿𝑿 𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗 − 𝟗𝟗 𝟏𝟏𝟏𝟏 ∗ 𝟎𝟎.𝟕𝟕𝟕𝟕𝟕𝟕𝟕𝟕 + 𝟖𝟖 𝟏𝟏𝟏𝟏 ∗ 𝟎𝟎.𝟖𝟖𝟖𝟖𝟖𝟖𝟖𝟖 = 𝟎𝟎. 𝟐𝟐𝟐𝟐𝟐𝟐𝟐𝟐 bits • 𝑰𝑰𝑰𝑰 𝑿𝑿 𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄𝒄 = 𝟎𝟎. 𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗 − 𝟗𝟗 𝟏𝟏𝟏𝟏 ∗ 𝟎𝟎.𝟗𝟗𝟗𝟗𝟗𝟗𝟗𝟗 + 𝟖𝟖 𝟏𝟏𝟏𝟏 ∗𝟏𝟏.𝟎𝟎 = 𝟎𝟎. 𝟎𝟎𝟎𝟎𝟎𝟎𝟎𝟎 bits • 따라서 𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃𝒃 변수가 𝑰𝑰𝑰𝑰를 높이는 좋은 Rule. • Child 노드의 Impurity(순도)가 높을수록 𝑰𝑰𝑰𝑰 상승. VS. https://roshansanthosh.wordpress.com/2017/06/16/entropy-and-information-gain/
  • 19. Classification & Ensemble (19/33) Deeperence · CGLAB 이명규 ↳ Rules and Impurity Decision Tree2-2 • 많은 Rules가 존재하는 것은 분류 결정 방식이 복잡해진다는 의미로, 과적합 가능성 증가 • Tree의 depth가 깊어질수록 예측 성능 저하 • 최대한 균일하게 데이터셋을 구성해야 함 • DT는 정보 균일도가 높은 데이터 셋을 우선 선택하도록 학습된다. • 노드 균일도 측정에는 대표적으로 Gini Coefficient, Information Gain 등이 활용
  • 20. Classification & Ensemble (20/33) Deeperence · CGLAB 이명규 ↳ 결정 트리의 장/단점 • 장점 • Information Gain등의 균일도를 기반으로 하므로 직관적 • 보통 각 피쳐의 Scaling과 Normalization을 할 필요가 없다. • 단점 • 과적합 가능성이 높다(복잡해질수록 실제 상황에 유연한 대처 불가) • 모든 데이터 상황을 만족하는 완벽한 규칙을 만들 수 없음 Decision Tree2-2
  • 21. Classification & Ensemble (21/33) Deeperence · CGLAB 이명규 ↳ 결정 트리의 파라미터 (1/2) Decision Tree2-2 파라미터명 설명 min_samples_split (default = 2) • 노드를 분할하기 위한 최소한의 샘플 데이터 수 (과적합 제어에 사용) • 작게 설정할수록 노드가 많아져서 과적합 가능성 증가 min_samples_leaf • Leaf(말단 노드)가 되기 위한 최소한의 샘플 데이터 수 • Imbalanced data의 경우 특정 클래스의 데이터가 극도로 작을 수 있으므로 해당 경우는 작게 설정해야 함. max_features (default = None) • 최적의 분할을 위해 고려할 최대 피쳐 개수 (None인 경우 데이터셋의 모든 피쳐 사용) • Int일 경우 대상 피쳐의 개수, float인 경우 전체 중 대상 피쳐의 percentage • Sqrt는 전체 피쳐 중 전체 피쳐 개수개 만큼 선정(auto=sqrt) • Log는 전체 피쳐 중 log2(전체 피쳐 개수)개 선정 「파이썬 머신러닝 완벽 가이드」 Chapter 4
  • 22. Classification & Ensemble (22/33) Deeperence · CGLAB 이명규 ↳ 결정 트리의 파라미터 (1/2) Decision Tree2-2 파라미터명 설명 max_depth (default = None) • 트리의 최대 깊이를 설정 • None인 경우 완벽하게 클래스 결정값이 될 때까지 깊이를 계속 키우거나 노드가 가지 는 데이터 개수가 min_samples_split보다 작아질 때까지 계속 깊이 증가 • 깊이가 깊어지면 min_samples_split에 따라 최대 분할하여 과적합 가능성이 있음. max_leaf_modes • 말단 leaf 노드의 최대 개수를 지정 「파이썬 머신러닝 완벽 가이드」 Chapter 4
  • 23. Classification & Ensemble (23/33) Deeperence · CGLAB 이명규 Ensemble Part 03 1. Overview 2. Ensemble with Resampling Method 「기계학습」 Chapter 12
  • 24. Classification & Ensemble (24/33) Deeperence · CGLAB 이명규 ↳ 1. 웬만한 성능을 쉽게 얻을 수 있다. 2. 성능 향상을 꾀할 수 있다. 3. 데이터 양이 적어도 충분한 학습 효과를 거둘 수 있다. 4. 원하는 시점에서 데이터를 융합할 수 있다. 5. 점진적인 학습이 가능하다. Overview 앙상블을 사용하는 이유 3-1
  • 25. Classification & Ensemble (25/33) Deeperence · CGLAB 이명규 ↳ • 사람들의 의사 결정 방식을 모방 (여러 알고리즘이 협동) • 앙상블 생성 : 여러 전문가를 확보하는 과정 • 앙상블 선택 : 전문가 집단에서 보다 나은 전문가의 선택에 해당 • 앙상블 결합 : 전문가 의견을 합쳐 최종 의견을 만드는 과정에 해당 • 앙상블 생성 방식 : Voting, Bagging(e.g RF), Boosting(XGBoost), Stacking, … 앙상블 생성 앙상블 선택 앙상블 결합 앙상블 생성 Overview3-1
  • 26. Classification & Ensemble (26/33) Deeperence · CGLAB 이명규 ↳ • 앙상블 결합에 참여하는 개별 분류기는 다양해야 함. • 요소 분류기들이 틀리는 샘플이 서로 다를수록 ‘다양하다’ 라고 함. • 분류기를 생성하는 방법 • 훈련 집합을 재샘플링(Resampling method)하는 방법, 특징 공간의 일부를 선택하는 부분 공간 방법(Subspace method)으로 나뉨 • Bagging과 Boosting은 재샘플링, Random Forest는 부분 공간 방법에 해당 앙상블에 사용되는 분류기의 다양성 3-1 Overview
  • 27. Classification & Ensemble (27/33) Deeperence · CGLAB 이명규 ↳ • DB의 질적 및 양적 품질은 인식기의 성능을 좌우 • 훈련 집합 이외에 별도의 검증 집합 필요 • 그러나 현실적인 문제들이 존재 : DB수집에는 많은 시간과 비용이 필요 • 이 경우 Resampling Method을 통해 성능측정의 신뢰도 향상 도모 Ensemble with Resampling Method 재샘플링 기법 3-2
  • 28. Classification & Ensemble (28/33) Deeperence · CGLAB 이명규 ↳ • 모델 선택 문제를 푸는 알고리즘. • Overall Idea 1. 샘플 집합에서 N개 샘플을 임의로 추출 2. 임의로 뽑은 샘플은 다시 넣음. 3. 이렇게 얻은 샘플 집합을 𝑿𝑿𝟏𝟏이라 하고, 이 샘플링 과정을 독립적으로 𝑇𝑇번 수행. 4. 모델 성능을 T번 측정 후 결과를 평균내어 최종 성능으로 취함. Bootstrap Algorithm 3-2 Ensemble with Resampling Method
  • 29. Classification & Ensemble (29/33) Deeperence · CGLAB 이명규 ↳ • 부트스트랩 알고리즘을 앙상블 생성에 적용한 알고리즘 • Overall Idea • T개의 샘플 집합 𝑿𝑿𝟏𝟏, 𝑿𝑿𝟏𝟏, …, 𝑿𝑿𝑻𝑻에서 𝑿𝑿𝒕𝒕를 훈련 집합으로 하여 분류기 𝒄𝒄𝒕𝒕를 만듬. • 이 분류기 학습을 𝟏𝟏 ≤ 𝒕𝒕 ≤ 𝑻𝑻에 대해 독립적으로 수행하여 𝑇𝑇개의 분류기 생성. Bootstrap Aggregating (Bagging) 기법 3-2 Ensemble with Resampling Method
  • 30. Classification & Ensemble (30/33) Deeperence · CGLAB 이명규 ↳ • 배깅보다 정교한 재샘플링 연산 사용 • 𝒕𝒕번째 분류기 𝒄𝒄𝒕𝒕와 𝒄𝒄𝒕𝒕+𝟏𝟏이 연관성을 갖고 만들어짐. • 훈련 샘플은 𝒄𝒄𝒕𝒕가 맞춘 샘플과 틀린 샘플로 구분됨 • 맞춘 샘플은 가중치를 낮추지만 틀린 샘플은 높임. • 𝒄𝒄𝒕𝒕+𝟏𝟏 은 가중치 정보를 고려해 가중치가 높은 샘플을 잘 맞추도록 학습 수행 AdaBoosting 기법 3-2 Ensemble with Resampling Method
  • 31. Classification & Ensemble (31/33) Deeperence · CGLAB 이명규 ↳ 1. 라인 3에서 모든 샘플에 같은 가중치를 부여하고 시작 2. 라인 5는 가중치를 고려하여 분류기 𝒄𝒄𝒕𝒕를 학습시킴. 3. 라인 6~8은 새 분류기의 오류율 계산 (가중치 포함) 4. 라인 10는 오류율을 계산 5. 새 분류기가 만들어질 때마다 11~13에서 가중치 갱신 1. 틀린 샘플은 𝒆𝒆𝒆𝒆𝒆𝒆(𝜶𝜶𝒕𝒕)를 곱해 가중치를 높임 AdaBoosting 기법 3-2 Ensemble with Resampling Method
  • 32. Classification & Ensemble (32/33) Deeperence · CGLAB 이명규 ↳ • Bagging은 분류기가 서로 독립하여 학습을 수행 • AdaBoost는 분류기들이 상호 보완적이므로 현재 분류기의 약점을 다음 분류기가 보완해줌. (따라서 라인 5, 11~13의 가중치 관리가 핵심) 대치 허용 안함 대치 허용함 성능 평가에 쓰임 교차 검증 Bootstrap 앙상블 생성에 쓰임 Boosting Bagging Bagging과 Boosting의 차이 3-2 Ensemble with Resampling Method
  • 33. Classification & Ensemble (33/33) Deeperence · CGLAB 이명규 Thank you for Listening. Email : brstar96@naver.com (or brstar96@soongsil.ac.kr) Mobile : +82-10-8234-3179