Task: Classification
빠르고 정확하다
Machine Learning
Machine Learning: Data 기반 Function Approximation
Problem Setting
- Learning Type: Supervised Learning
- Instances: x, Labels: y
- Unknown target function: f:x→y
- Function Hypothesis: H={h∣h:x→y}
- Output: f에 가장 근사한 가설 h∈H
Sample Dataset
Outlook, Temperature, Humidity, Wind에 따른 Class 여부
Decision Tree
Neural Network와 다른 점
- Parameter 연산 없이 Feature만으로 출력을 결정한다.
- Neural Network는 Feature에 내제된 것을 계산하므로 표현력이 더 좋다.
Decision Tree
if-else
형태 - 지나치게 많아지면 Tree 사용이 어렵다.
- 이미지의 경우 256*256 pixel에 대해 가지가 생성된다.
![](https://velog.velcdn.com/images/hyeon-ii/post/f2022b0d-21f8-4023-9dfb-7a542a9217d4/image.png)
- Internal Node: test one attribute Xi
- Branch from a node: Xi 선택
- Leaf node: predict Y
- 위의 예에서 Temperature node는 없다. Attribute가 Node로 사용되지 않을 수 있다.
- Prediction Sample
- Data:
<outlook=sunny, temperature=hot, humidity=high, wind=weak>
- Prediction:
No
연속적인 속성에 대한 Decision Tree
- Internal node는 threshold에 대해 feature의 값을 test할 수 있다.
Decision Tree Learning
- Problem Setting
- Instances: x, Labels: y
- 각 instance x는 feature vectore X에 해당한다.
- x는 low, high 등 instance
- Unknown target function: f:x→y
- Function Hypothesis: H={h∣h:x→y}
- 각 가설 h는 decision tree
- tree는 x를 y로 할당되는 leaf로 분류한다.
- Output: f에 가장 근사한 가설 h∈H
Decision Tree Machine Learning
![](https://velog.velcdn.com/images/hyeon-ii/post/01f971f6-7498-4500-948d-9f776f5c4a47/image.png)
다른 머신러닝 알고리즘과 동일하게 학습한다.
- Given: labeled training data X,Y
- Train: model←classifier.train(X,Y)
- Apply to new data
- Given: unlabled instance
- yprediction←model.predict(X)
Decision Boundary
- Decision Tree는 feature space를 축에 평행하게 분할한다.
- 각 직사각형 영역은 하나의 label이거나 label에 대한 확률 분포이다.
Expressiveness
- Decision tree는 모든 binary 문제를 풀 수 있다.
- 최악의 경우, tree는 exponentially 많은 node를 필요로 한다.
- Decision tree는 변수만큼의 hypothesis space를 가진다.
- Node의 개수가 늘어날수록 hypothesis 공간이 커진다.
![](https://velog.velcdn.com/images/hyeon-ii/post/1ef51743-37e1-48cd-8992-bfb18c22706c/image.png)
- Depth 1(decision stump): feature의 모든 boolean function을 나타낼 수 있다.
- Depth 2: 두개의 feature를 가진 boolean function
문제점: 심각한 Overffiting. Test Data를 보장할 수 없다.
Preference bias: Ockham's Razor
Tree 역시 가장 간단할수록 좋다.
- 모든 training data를 정확하게 분류하는 가장 작은 decision tree가 가장 최선이다.
Basic Algorithm for Top-Down Induction of Decision Trees
- node = Decision tree의 root
- Main Loop
- A ← 최선의 decision attribute
- Node에 대한 decision attribute로 A 할당
- A 각각에 대해 새로운 자식 node를 만든다.
- Training examples를 leaf node로 배정한다.
- Training examples가 완벽히 분류되었다면 그만한다.
그렇지 않으면 새로운 leaf node에 대해 반복한다.
최선의 Attribute를 선택하는 방법
- 어느 attribute가 examples를 가장 잘 나누는지 알아야 한다.
- Possibilities
- Random: Attribute를 무작위로 선택한다.
- Least-Values: 가장 적은 가지를 만드는 Attribute를 선택한다.
- Most-Values: 가장 많은 경우를 만들어내는 Attribute를 선택한다.
- Max-Gain: Information gain이 가장 큰 Attribute를 선택한다.
ID# algorithm은 Max-Gain method를 사용한다.
- Idea: 가장 좋은 Attribute는 examples를 "all positive" 또는 "all negative"로 분류한다.
![](https://velog.velcdn.com/images/hyeon-ii/post/1a37a6cf-7300-4ebe-bf2e-8cc507e24eba/image.png)
Patron으로 구분한 경우 examples가 완벽하게 갈린다.
- Compare Example
![](https://velog.velcdn.com/images/hyeon-ii/post/e3640b94-acfa-43f6-8f20-d4f60072259c/image.png)
- Examples가 완벽하게 갈릴수록 정보적 이득이 크다.
2-Class Cases
![](https://velog.velcdn.com/images/hyeon-ii/post/2b5a5f1c-d495-4700-b2cc-8ecb2aba2f69/image.png) | ![](https://velog.velcdn.com/images/hyeon-ii/post/ef77d9de-fac6-46ef-ad06-1c33a4a198f8/image.png) |
---|
모든 샘플이 하나의 클래스에 속하는 경우 | 샘플이 50% 비율로 섞여있는 경우 |
P(X=i)=1 | P(X=i)=0.5,P(X=j)=0.5 |
정보량: log2P(X=i)=0 | 정보량: −1,−1 |
H(X)=0 | H(X)=1 |
Sample Entropy
![](https://velog.velcdn.com/images/hyeon-ii/post/e2b25e19-c4ba-4e1a-bbc0-382858fcdd17/image.png)
- S: Training examples 샘플
- S의 impurity를 나타내는 Entropy
H(S)=−p⊕log2p⊕−p⊖log2p⊖
- Entropy가 가장 클 때
- p⊕와 p⊖는 각각 50%로 섞여있다.
- 불확실성이 크다.
- 정보량이 낮다. 얻을 수 있는 정보가 없다.
- 데이터가 pure 할수록 entropy가 낮다.
- Training feature vector에서 어떤 속성이 분류하기에 가장 효율적인지(impurity가 작은지) 결정해야 한다.
- Information Gain은 주어진 feature vector의 속성이 얼마나 중요한지 나타낸다.
- Decision tree의 node에서 attribute의 속성을 결정하는 데 사용된다.
From Entropy to Infromation Gain
- 조건부 entropy (given Y=v)
H(X∣Y=v)=−i=1∑nP(X=i∣Y=v)log2(X=i∣Y=v)
- Y=v: Attribute가 v로 고정된 것을 의미한다.
- v가 여러개이면 각 v에 대해 계산 후 마지막에 합한다.
- H(X∣Y)=∑v∈values(Y)P(Y=v)H(X∣Y=v)
- Mututal(상호) information = Information Gain
I(X,Y)=H(X)−H(X∣Y)=H(Y)−H(Y∣X)
- H(X)는 클수록 불확실성이 높다.
- H(X): 확률 변수 X의 엔트로피, 즉 X의 불확실성을 나타낸다.
- H(X∣Y): Y가 주어졌을 때의 X의 조건부 엔트로피, 즉 Y를 알고 있을 때 남아 있는 X의 불확실성을 나타낸다.
- Y가 주어졌을 때 X의 불확실성이 얼마나 낮아지는지 설명한다.
- 만약 두 변수가 독립이라면 Y를 알아도 X의 불확실성은 낮아지지 않으므로 H(X∣Y)=H(X)이 되어 I(X,Y)=0이 된다.
- Y가 X를 완전히 결정한다면 I(X,Y)=1이 된다.
I(X,Y)는 클수록 좋다.
- I(X,Y)는 두 변수가 서로 얼마나 많은 정보를 공유하는지 나타낸다.
- Information Gain 계산
Information Gain = Entropy(parent) - Average Entropy(Children)
![](https://velog.velcdn.com/images/hyeon-ii/post/d9202375-9f8d-40d2-b7ac-c3c7eac2e99a/image.jpg)
- Child Entropy
- 17 Instances: −174⋅log2174−1713⋅log21713=0.787
- 13 Instances: −1312⋅log21312−131⋅log2131=0.391
- Weighted Average Entropy of Children
3017⋅0.787+3013⋅0.391=0.615
- Information Gain
0.996−0.615=0.38
- 모든 Attribute에 대해 계산한 후 최종 선택한다.
- Disadvantage of Information Gain
- 데이터를 작은 pure 집합으로 분할하는 많은 값을 가진 속성을 선택하게 된다.
- 다중값 속성에 대한 편향으로 이어질 수 있다.
- 이를 개선하기 위해 Quinlan's gain ratio를 사용하여 정규화를 도입한다.