Top Banner
Naive ML Overview 홍철주
54

Naive ML Overview

Aug 08, 2015

Download

Technology

Chul Ju Hong
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Naive ML Overview

Naive ML Overview

홍철주

Page 2: Naive ML Overview

발표자 소개

홍철주

• http://blog.fegs.kr

• https://github.com/FeGs

• Machine Learning Newbie

• SW Maestro 5th

2

Page 3: Naive ML Overview

목차

•기계 학습

•지도 학습

•분류

•회귀

•비지도 학습

•사례

3

Page 4: Naive ML Overview

머신러닝 개발 순서 中

•데이터 수집

•데이터 준비 (Data cleaning)

• 데이터 분석 (Data analysis, Feature engineering)

• 데이터 학습 (Modeling)

• 모델 성능 평가 (Evaluation)

오늘은 이 부분을 다룹니다

4

Page 5: Naive ML Overview

용어 정의

•Machine Learning

• Feature / Attribute

• Target variable / Label

• Training set / Testing set

5

Page 6: Naive ML Overview

기계 학습

• Supervised Learning (지도 학습)

•데이터 X에 대해 Y를 예측하는 것

•답이 있는 문제에서 답을 예측하는 것

• Unsupervised Learning (비지도 학습)

•데이터 X는 어떻게 설명될 수 있는가

•해석은 알아서

http://en.wikipedia.org/wiki/List_of_machine_learning_concepts

6

Page 7: Naive ML Overview

기계 학습

7

Page 8: Naive ML Overview

기계 학습

8

Page 9: Naive ML Overview

지도 학습 학습 단계

MachineFeatures Target variable

Modeling

9

Page 10: Naive ML Overview

지도 학습 테스트 단계

MachineFeatures Predicted target variable

predicted = model(features)

10

Page 11: Naive ML Overview

지도 학습 성능 평가 단계

MachineTraining Data Features (w/o target variable)

Predicted Target Variables

Accuracy = Correctly Predicted Target Variables / Total Predicted Target Variables

11

Page 12: Naive ML Overview

지도 학습 성능 평가 단계

Cross Validation 교차검증

Training Data Set 1/5

Training Data Set 2/5

Training Data Set 3/5

Training Data Set 4/5

Training Data Set 5/5

Training Data Set 2/5

Training Data Set 1/5

Training Data Set 3/5

Training Data Set 4/5

Training Data Set 5/5

Training Data Set 5/5

Training Data Set 1/5

Training Data Set 2/5

Training Data Set 4/5

Training Data Set 5/5

accuracy0 accuracy1 accuracy4

Final Accuracy = mean(accuracy0, accuracy1, …, accuracy4)

Test Data로 사용

Overfitting 판단에도 도움을 준다! Why?

12

Page 13: Naive ML Overview

Over/Underfitting

13

Further reading - Bias-Variance Tradeoff

High VarianceHigh bias

Page 14: Naive ML Overview

지도 학습

• Classification 분류

• Target variable: Discrete value

• Regression 회귀

• Target variable: Continuous value

14

Page 15: Naive ML Overview

분류 문제 예시• 스팸 메일 분류

• 필기체 인식

• 얼굴 인식

• 문서 분류

• 음성 인식 등..

15

Page 16: Naive ML Overview

분류 문제• Decision Trees

• Support Vector Machine

• k-NN

• Naive Bayes

• Neural Networks

16

Page 17: Naive ML Overview

Decision Trees

17

Page 18: Naive ML Overview

Ensemble of classifier

18

• Random Forest (Ensemble learning)

• ex) SVM + Logistic Regression + Random Forest

여러 분류기를 사용하는데

더 많은 분류기가 예측한 값을 최종 분류값으로 내놓음.

Overfitting도 피하고 정확도도 높여보고!

Page 19: Naive ML Overview

SVM

19

Page 20: Naive ML Overview

SVM

20

Page 21: Naive ML Overview

k-NN

21

Page 22: Naive ML Overview

Naive Bayes

22

Page 23: Naive ML Overview

Neural Networks

23

이건 다음에

Page 24: Naive ML Overview

Example: MNIST (kaggle)

Data : Handwritten digits image (28px * 28px, grayscale)

Target variable : digit number

0 1 2 3 4 5

24

Page 25: Naive ML Overview

Example: MNIST (kaggle)

Features : pixel0, pixel1, …, pixel783 (28 * 28)

[…, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 210, 254, 253, 159, 0, 0, 0, 0, 0, 0, 0, 0,

0, 0, …]

Target Variable : 0

접근 1 - 픽셀 하나하나를 Feature로 간주

25

Page 26: Naive ML Overview

Example: MNIST (kaggle)

[…, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 210, 254, 253, 159, 0, 0, 0, 0, 0, 0, 0, 0,

0, 0, …]

784차원 공간을 생각해보자 :

Method 1: k-NN

Method 2: SVM

Method 3: Random Forest, etc..

784차원 공간에서 가까이 있는 좌표의 label은?

784차원 공간을 783차원 초평면으로 갈라서 분류해보면?

이 위치에 하얀 픽셀이 있고 저기엔 없으면?

어떤 방법이 가장 좋은가?

26

Page 27: Naive ML Overview

Example: MNIST (kaggle)접근 2 - 이미지 프로세싱으로 Feature를 만들어내기

End point and junctions distribution

교차점, 끝점 갯수 등을

Feature로 이용함.

ex) 8은 교차점이 1개,

끝점은 0개

Feature Extraction

27

Page 28: Naive ML Overview

Example: MNIST (kaggle)높은 정확도와 Insight를 얻기 위한 시각화

Averaging Images

Visualizing Random Forest28

Page 29: Naive ML Overview

Example: MNIST• http://yann.lecun.com/exdb/mnist/

29

Page 30: Naive ML Overview

최적화

• 한 알고리즘에서 조건을 바꿔가며 성능 평가를 시행하

여 최적의 Parameter를 찾는 것

• Grid Search 등을 이용해서 찾을 수 있다.

30

Page 31: Naive ML Overview

회귀 문제• 1, 2, 3, 다음에 올 숫자는?

• 4? (d=1, 등차수열)

• 5? (피보나치)

• …

31

Page 32: Naive ML Overview

회귀 문제 예시• 가격 예측

• ?

32

Page 33: Naive ML Overview

회귀 문제• Linear Regression

• (+ Ridge, Lasso)

• Neural Networks

• Logistic Regression

33

Page 34: Naive ML Overview

Linear Regression

34

Page 35: Naive ML Overview

Neural Networks

35

이건 다음에

Page 36: Naive ML Overview

비지도 학습• Clustering 군집화

• Association Rule Learning 연관 규칙 학습

36

Page 37: Naive ML Overview

군집화 문제 예시

37

• 비슷한 문서 찾기

• Collaborative Filitering (추천 시스템)

Page 38: Naive ML Overview

군집화 문제

38

• k-Means clustering

• EM algorithm

Page 39: Naive ML Overview

k-Means Clustering

39

Page 40: Naive ML Overview

EM Algorithm

40

Page 41: Naive ML Overview

연관 규칙 학습 문제 예시

41

• 연관 상품 추천 (Continuous Production)

• 연관 웹페이지 추천 (Web Usage Mining)

• 등등

Page 42: Naive ML Overview

연관 규칙 학습

42

• Support

• Confidence

• A -> B?

Page 43: Naive ML Overview

사례 분석• 스팸 메일 분류

• 필기체 인식

• 음성 인식

• 얼굴 인식

• 상품 추천

43

Page 44: Naive ML Overview

스팸 메일 분류접근 : Bayesian filtering

간단히 Spam / Not spam (Ham) 을 구분하는 문제

내용만으로 분류를 하는 접근

Pr(S|W) = 단어 W가 들어있을 때 스팸일 확률

Pr(W|S) = 스팸에 단어 W가 있을 확률

Pr(S) = 스팸 확률

Pr(W|H) = 햄에 단어 W가 있을 확률

Pr(H) = 햄 확률

스팸에서 W가 등장하는 횟수 / 스팸 총 단어 수

통계적으로 0.2

햄에서 W가 등장하는 횟수 / 햄 총 단어 수

통계적으로 0.8

44

Page 45: Naive ML Overview

필기체 인식 (MNIST 문제를 어떻게 풀어봤나)접근 1: PCA + k-NN

단순히 k-NN을 쓰면 시간이 많이 소요된다.

그렇다면 차원을 낮추자! - PCA

10차원으로 낮췄을 때 : 92.6%

33차원으로 낮췄을 때 : 97.3%

5 3 8 9

56차원으로 낮췄을 때 : 97.2%

45

Page 46: Naive ML Overview

필기체 인식 (MNIST 문제를 어떻게 풀어봤나)접근 2: CNN (Convolutional Neural Networks)

이건 다음에

46

Page 47: Naive ML Overview

음성 인식접근 : Neural Networks

47

MFCCs

Zero Crossing Rate

Spectral Centroid

등을 feature로 사용이미지 픽셀을 쓰는거랑 비슷함

Page 48: Naive ML Overview

얼굴 인식접근 : SVM + Sliding Window

48

얼굴 데이터로만 학습

Window

이 영역이 얼굴인가? (분류)

Page 49: Naive ML Overview

상품 추천접근 1 : k-Means clustering

49

다른 사람도 봤던 상품이 무엇인지 알려주기

Features : product1, product2, …, productN (seen)

[…, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,

0, 0, …]

Product Vector

Page 50: Naive ML Overview

상품 추천접근 2 : EM algorithm Clustering

50

Pr(P2|P1) = 상품 P1을 봤던 사람이 상품 P2를 볼 확률

Pr(P1|P2) = 상품 P2를 봤던 사람이 상품 P1을 볼 확률

Pr(P2) = P2를 볼 확률

Pr(P1) = P1을 볼 확률

Pr(P2|P1) = Pr(P1|P2) * Pr(P2) / Pr(P1)

있을 법한 상품 조합 찾아내기

Page 51: Naive ML Overview

상품 추천접근 3 : Apriori algorithm (Associative Rule Learning)

51

상품간 연관 규칙 발견하기

접근 4 : TF-IDF (Content-based filtering)

상품간 유사성 발견하기

Page 52: Naive ML Overview

Tools• ipython

• numpy, scipy (scientific computing)

• matplotlib (ploting library)

• scikit-learn (general machine learning algorithm set)

• theano (for fast deep learning)

• gensim (topic modeling library)

52

Page 53: Naive ML Overview

실습합시다

Page 54: Naive ML Overview

EOF