-
[๊ธฐ๊ณํ์ต] 13. Class Imbalanced Problems๐ณDev/Machine Learning 2021. 12. 9. 17:09
์ค๋์ ๋ฐ์ดํฐ ๋ถ๊ท ํ์ ๋ฌธ์ ์ ํด๊ฒฐ๋ฐฉ๋ฒ์ ๋ํด ์ด์ผ๊ธฐ ํด๋ณด๋ ค๊ณ ํ๋ค.
์๊ณ ๋ฆฌ์ฆ์ ๊ณต๋ถํ ๋๋ ์ฐ๋ฆฌ๊ฐ ์ถ์ถํ๋ ค๋ ๋ฐ์ดํฐ์ ์ผ๋ฐ์ ์ธ ๋ฐ์ดํฐ๊ฐ ๋๋ต 1 : 1์ ๋น๋ฅผ ๊ฐ์ง๋ค๊ณ ๊ฐ์ ํ๋ค.
ํ์ง๋ง ์ค์ ์ํฉ์์๋ ์ด ๋ ๋ฐ์ดํฐ๊ฐ์ ๋น์ ์ฐจ์ด๊ฐ ๋น์ทํ ๊ฒฝ์ฐ๋ ๊ฑฐ์ ์๋ค.
1. Class-Imbalanced Problems
๋ถ๋ฅํ๋ ์ํฉ์์, ์ฐ๋ฆฌ๊ฐ ์ถ์ถํ๋ ค๋ ๋ฐ์ดํฐ๋ positive, ์ผ๋ฐ์ ์ธ ๋ฐ์ดํฐ๋ negative์ด๋ผ๊ณ ๋ถ๋ฅธ๋ค.
In classification problems,
- The total number of a class of data (positive) is far less than the total number of another class of data (negative)
- The minority class is a rare event or the data in minority class is hard to collect
- Example – Majority class : Minority class = 9:1
- Problem – A classifier tends to classify all data to the majority class
๊ทธ๋ฆฌ๊ณ ์ผ๋ฐ์ ์ผ๋ก ์ถ์ถํ๋ ค๋ ๋ฐ์ดํฐ๋ ์์ด ๋งค์ฐ ์ ๋ค. ์๋ฅผ ๋ค์ด Fault Detection, Cancer detection ๋ฑ์ ์๊ฐํ๋ฉด, ์ฐ๋ฆฌ๊ฐ ์ฐพ๊ณ ์ํ๋ ๋ฐ์ดํฐ๋ ์ผ๋ฐ์ ์ด์ง ์๊ณ ํน์ํ๋ค.
- What may cause the class-imbalanced problems
- It is hard to collect the minority data
- Minority data are collected from rare events
- Minority class is often what we are interested in
- Minority class: positive
- Majority class: negative
- We are interested in prediction of the minority class
- In real-world cases, we barely deal with problems at 50:50
1) Class-Imbalanced Problems
- Two perspectives on class-imbalanced problems
minority class๋ฅผ ์ผ๋ฐ์ ์ผ๋ก ๋๊ฐ์ง ๋ถํฌ๋ก ๋๋ ์ ์๋ค
์ผ์ชฝ์ minority๊ฐ ์์ญ์ ์ด๋ฃจ๊ณ , ์ ์๊ฐ ๊ฐ๋ฅํ๋ค
์ค๋ฅธ์ชฝ์ ์์ญ์ ์ด๋ฃจ์ง ์๊ณ , major๊ฐ ์๋ ๊ฒฝ์ฐ minor๋ก ์ทจ๊ธํ๋ค
- Possible classification results from the conventional 2-class classifiers
์ด๋ฌํ ์ํฉ์์ decision boundary๋ฅผ ์ค์ ํ๋ฉด ๋ค์๊ณผ ๊ฐ๋ค
- Desired classification results
ํ์ง๋ง iid์ ์ํด ์ฌ๋ฌ ๋ฐ์ดํฐ๊ฐ ์กด์ฌํ ์ ์์ผ๋ฏ๋ก,
์ฐ๋ฆฌ๋ ๊ฑฐ๋ฆฌ๊ฐ ์ ์ง๋๋, ์ ์ ํ decision boundary๋ฅผ ํ์๋ก ํ๋ค
์๋ ์์๋ majority์ minority์ ๋น์ ๋ฐ๋ฅธ decision boundary์ด๋ค.
๋น์ ์ฐจ์ด๊ฐ ์ปค์ง ์๋ก minoiry๊ฐ ๋ฌด์๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
2. Sampling Method
๋ฐ๋ผ์ sampling technique๋ฅผ ํตํด ๋ ํด๋์ค๊ฐ์ ๊ท ํ์ ๋ง์ถ๊ธฐ๋ก ํ๋ค.
๊ฐ์ฅ ๊ฐ๋จํ๊ณ ์ฌ์ด ๋ฐฉ๋ฒ์ sampling์ด๋ค.
- Oversampling, minority๋ฅผ ๋๋ฆฌ๊ธฐ
- UnderSampling, majority๋ฅผ ์ค์ด๊ธฐ
1) Oversampling
Oversample from the minority class
- Make duplicates, ๊ฐ์ ๊ฐ์ ๋ณต์ ํ๊ฑฐ๋
- Add random noises, ๋๋ค ๋ ธ์ด์ฆ๋ฅผ ์ฒจ๊ฐํ ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐ
minority๋ฅผ ๋๋ฆฌ๊ธฐ ์ํด ์์ ๊ฐ์ ๋ฐฉ์์ ์ฌ์ฉํ ์๋ ์์ผ๋ฉฐ,
์ฃผ๋ก ์ฌ์ฉ๋๋ Oversampling ๋ฐฉ๋ฒ์ผ๋ก๋ SMOTE(Synthetic Minority Oversampling Technique)๊ฐ ์๋ค.
๊ฝค ์ค๋๋ ๋ฐฉ๋ฒ์ด๋ฉฐ, ๋จ์ ๋ ์กด์ฌํ์ง๋ง ์ฌ์ ํ ๋ง์ด ์ฐ์ด๋ ๋ฐฉ๋ฒ์ด๋ค.
SMOTE
SMOTE๋ ํน์ minority sample k์ k ์ฃผ๋ณ minoirty data์ ์ ๋ถ์ ํ์ฑํ๊ณ , ๋๋ค ๋น์จ๋ก ์ ๋ถ ์์ ํ ์ง์ ์ data๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ด๋ค. ๋ฐ์ดํฐ๋ค์ ๋ด๋ถ์๋ง ํ์ฑ๋์ด ๋๊ณ ํ์ฑํ ๋ฐ์ดํฐ๋ ์์ฑํ๊ธฐ ์ด๋ ค์ฐ๋ฉฐ, ๋ง์ฝ majority๊ฐ ์ค์ฌ์ ์๊ณ minority๊ฐ ์ธ๊ฐ์ ์๋ ๋ชจ๋ธ์์๋ ์๋ฏธ๊ฐ ์๋ data๊ฐ ์์ฑ๋ ์ ์๋ค๋ ๋จ์ ์ด ์๋ค.
2) Undersampling
Undersample from the majority class
- Random removal, ๋๋ค์ผ๋ก ์ ๊ฑฐ
- Clustering-based removal, ํด๋ฌ์คํฐ์์ ํต์ฌ data๋ง ๋จ๊ธฐ๊ณ ์ ๊ฑฐ
๋๋ค์ผ๋ก ์ ๊ฑฐํ๋ ๊ฒฝ์ฐ, majority์ ํน์ ์์ญ data๋ค์ ์ ๋ถ ์ง์ majority๋ฅผ ์นจ๋ฒํ๋ ์ด์ํ decision boundsasry๋ฅผ ์์ฑํ ์ ์๋ค. ๋ฐ๋ผ์ ํด๋ฌ์คํฐ ๊ธฐ๋ฐ์ ์ ๊ฑฐ๋ฅผ ์ถ์ฒํ๋ค.
3. Cost-Sensitive Learning
1) Cost-sensitive learning
Set the cost of misclassification to calibrate ratio between classes
minority data์ ๋ํ ์ค๋ถ๋ฅ์ ๋ ํฐ panelty์ ๋ถ์ฌํ๋ ๋ฐฉ์์ด๋ค- If Positive : Negative = 1:9
- Cost of misclassification –Positive : Negative = 9:1
- Same results from the oversampling without additional noises
์์ ๊ฐ๋จํ Losss function์ ํด๋์ค์ ๋ฐ๋ผ ๋ค๋ฅธ ๊ฐ์ค์น๋ฅผ ๋ถ์ฌํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋ค.
Cost-Sensitive Learning์ ํตํด ์ผ์ชฝ ์ํฉ์์๋ ๋นจ๊ฐ์ด๋ฅผ ํ๋ ์นจ๋ฒํ๊ณ 9์ ์ ํจ๋ํฐ๋ฅผ ์ป์์ง๋ง, ์ค๋ฅธ์ชฝ ์ํฉ์์๋ ํ๋์ด๋ฅผ ๋ ๊ฐ ๋๊ณ ๋ 2์ ์ ํจ๋ํฐ๋ฅผ ์ป์ ๊ฒ์ ๋ณผ ์ ์๋ค. ๊ทธ๋ ๋ค๋ฉด ๋ชจ๋ธ์ ํ๋์ด๋ณด๋ค ๋นจ๊ฐ์ด๋ฅผ ๋ ์กฐ์ฌํ ๊ฒ์ด๋ค.
4. Ensemble
- To reduce the variance of sampling methods
์์๋ธ์ majority๋ฅผ minority์ ๋น์ทํ ํฌ๊ธฐ๋ก ๋๋์ด ์ฌ๋ฌ๋ฒ ํ์ต์ํค๋ ๋ฐฉ๋ฒ์ด๋ค.
5. Novelty Detection
์ด ์ธ์ ๋ฐฉ๋ฒ์๋ Novelty Detection, ์ด์์น ์ฐธ์ง๊ฐ ์๋๋ฐ, ๊ฐ์ ๋ง๋ก๋ 1-Class Classification, Outlier Detection, Anormaly Detection, Abnormality Detection๊ฐ ์๋ค.
1) 1 - Class Classification
minority๊ฐ ์๋ค๊ณ ์๊ฐํ๊ณ , majority ํ๋์ ํด๋์ค๋ก ํ์ตํ๊ณ boundary(์ ์ ๋ฒ์)๋ฅผ ๊ฒฐ์ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์ด์ ํด๋นํ์ง ์๋ data๋ ๋ค๋ฅธ ํด๋์ค(์ด์)๋ผ๊ณ ํ๋จํ๋ค.
๋งจ ์ฒ์์ minority๋ฅผ ๋ ๊ฐ์ง ๊ฒฝ์ฐ๋ก ๋ถ๋ฅํ์ ๋์ ๋ ๋ฒ์งธ ๊ฒฝ์ฐ์ ๊ฐ๋ค.
- Train a model with only data of the majority class
- Define a region of majority class
- Outside the defined region -> minority class
- Like unsupervised method
- Highly imbalanced problems, ๋งค์ฐ ๋ถ๊ท ํํ ๋ ์ฌ์ฉ
- Positive : Negative = 1 : 999
Binary Classification๊ณผ ๋น์ทํ๋ค๊ณ ์๊ฐํ ์ ๋ ์์ง๋ง, ์ด ๋์ ์ฒ ํ์ ํน์ง์ด ์์ ๋ค๋ฅด๋ค.
- The number of data belonging to the minority class is too small
- The definition of minority class is just NOT-majority class
Binary์์๋ A์ B๊ฐ Major์ด์ง๋ง, Novelty์์๋ ์๋๋ค. ์ด ๋์ด ์ด๋ป๊ฒ ๋ถ๋ฅ๋๋๊ฐ๊ฐ ํฐ ์ฒ ํ์ ํน์ง์ ์ฐจ์ด - Generalization vs. specialization
binary๋ minorty๋ฅผ ํตํด boundary๋ฅผ ์กฐ์ ํ ์ ์๋ค. ํ์ง๋ง Novelty๋ ์ธ๋ถ๋ก๋ถํฐ์ ์ํฅ์ ์ ํ ๋ฐ์ง ์์ผ๋ฏ๋ก ํ์ฌ์ boundary๋ณด๋ค ๋ ์ปค์ง๋๊ฒ ์ข์์ง, data์ ๋ฑ๋ง๊ฒ ์ค์ ํ๋ ๊ฒ์ด ์ข์์ง ๊ฒฐ์ ํ ์ ์๋ค. ๋ฌผ๋ก ์์๋ ํ์ด๋ธ๋ฆฌ๋๋ก ์ ์ ํ ํฌ๊ธฐ์ boundary๋ฅผ ์ฐพ์ ์ ์๋ค.
2) Clustering-based method
ํด๋ฌ์คํฐ ๋ฐ์ผ๋ก ๋ฒ์ด๋๋ฉด ์ด์์น, ์์ ์๋ค๋ฉด ์ ์์ ์๋ฏธํ๋ค
- Clustering with only data belonging to the majority class
- Set a threshold that decides the novelty
- Eg. Distance from each center, bottom p% of training data
๋ ธ์ด์ฆ๊ฐ ์์ ์ ์์ผ๋ ํด๋ฌ์คํฐ์ margin์ ์กฐ๊ธ ๋์!
- Eg. Distance from each center, bottom p% of training data
3) Density estimation-based method
์ด ๋ํ ๋ฒ์ ๋ด์ ์์ผ๋ฉด ์ ์์น, ๋ฐ์ ์๋ค๋ฉด ์ด์์น๋ฅผ ์๋ฏธํ๋ค
- Density estimation with only data belonging to the majority class (eg. GMM ๊ฐ์ฐ์์ ํผํฉ ๋ชจ๋ธ)
- Set a threshold that decides the novelty
- Eg. Probability value, bottom p% of training dat
4) Reconstruction-based method
NN์ ์ด์ฉํ์ฌ Novelty Detection๋ ๊ฐ๋ฅํ๋ค
์ฐจ์์ ์ถ์ํ๋ ๊ณผ์ ์ Encode, ๋ค์ ํ์ฅํ๋ ๊ณผ์ ์ Decode๋ผ๊ณ ํ๋๋ฐ ์ด๋ ํ์ฅ์ ์ฌ๊ตฌ์ถ์ ์๋ฏธ๋ก Reconstruction์ด๋ผ๊ณ ๋ ํ๋ค. ์๋ณธ๊ณผ ์๋ก์ด ๊ฐ์ ์ฐจ์ด๋ฅผ ์ค์ด๊ธฐ ์ํด loss๋ฅผ ์ต์ํ ํ๋๋ฐ, ์ต๋ํ ์๋ฏธ์๋ ๋ณ์๋ง์ Encodeํ๊ธฐ์ ๋ณ์ ์ถ์ถ๊ณผ๋ ํฐ ์ฐ๊ด์ด ์๋ค.
๋ค์ ๋์์, ์๋ณธ์ ๋ณต์ํด์ผํ๋ ์ด ๋ชจ๋ธ์ ์๋ณธ์ ์ง์คํ์ฌ ํ์ต์ ํ๊ฒ ๋๋ค. ์๋์ ์์์ ๋ฐ๋ฅด๋ฉด ์ ๋ชจ๋ธ์ ๋ฒ์ฏ์ ์ง์คํ์ฌ ํ์ต์ ํ๊ธฐ์, ๋ฒ์ฏ์ด ์๋ ๋ง๋ฆฌ์ค๊ฐ input์ผ๋ก ๋ค์ด์ค๋ฉด reconsturction error๊ฐ ๋งค์ฐ ์ปค์ง๊ฒ ๋๋ค.
๋ฌผ๋ก ๋ฒ์ฏ๋ค๋ก ๋ชจ๋ธ๋ง์ ํด๋ ์ค์ฐจ๋ ๋ถ๋ช ํ ์กด์ฌํ๋ค. ๋ฐ๋ผ์ ํน์ threshold๋ฅผ ๋์ผ๋ฉด ์ด์์น๋ผ๊ณ ํ๋จํ๋ค.
- Replicator neural networks (autoencoder)
- Train a neural network to minimize the reconstruction error
5) Support vector machine-based method
- 1-class SVM (1-SVM) vs. Support vector domain (data) description (SVDD)
6. Summary
- ๋ฒ์ฃผ ๋ถ๊ท ํ ๋ฌธ์ ๋ ์ผ๋ฐ์ ์ธ 2-class ๋ถ๋ฅ๊ธฐ๋ก๋ ํด๊ฒฐํ๊ธฐ ์ด๋ ค์
- ํด๊ฒฐ์ฑ
- Sampling, cost-sensitive ๋ฑ์ ๋ณด์ ์ ํ๊ณ 2-class ๋ถ๋ฅ๊ธฐ๋ก ํด๊ฒฐ
- Novelty detection method ์ฌ์ฉ, ์ด์์นํ์ง
๋ง์ง๋ง์ผ๋ก ML์ ๋ ๊ฐ์ง ๋ช ์ธ์ ์์๋ณด์
Occam's Razor, “If there are various logical ways to explain a certain phenomenon, the simplest is the best”
Wolpert, "No Free Lunch Theorem" : ํน์ ๋ฌธ์ ์ ์ต์ ํ๋ ์๊ณ ๋ฆฌ์ฆ์ ๋ค๋ฅธ ๋ฌธ์ ์๋ ๊ทธ๋ ์ง ์๋ค
์ด์์ผ๋ก ๋จธ์ ๋ฌ๋ ์์ ๋!
'๐ณDev > Machine Learning' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๊ธฐ๊ณํ์ต] 5. Nearest Neighbor Method (0) 2021.12.20 [๊ธฐ๊ณํ์ต] 4. Logistic Regression (0) 2021.12.15 [๊ธฐ๊ณํ์ต] 3. Regression (0) 2021.12.14 [๊ธฐ๊ณํ์ต] 2. Bayesian Classifier (0) 2021.12.13 [๊ธฐ๊ณํ์ต] 1. Introduction to Machine Learning (0) 2021.12.12