[지능시스템/Intelligent System] 6장. Probability-based learning, Continuous Features

2019. 11. 30. 18:35학교공부/지능시스템

1. Continuous Features

Probability density function(PDF)는 continuous feature에 대한 확률 분포를 normal distribution과 같은 수학적 함수를 통해 나타낸다. 

모든 표준 PDF는 shape of the density curve defining that distribution을 alter하는 parameters들을 가지고 있다. 그 paremeter들은 아래 테이블과 같다.

PDF를 probability of continous feature로 나타내기 위해서, 우리는 data의 특성에 맞는 parameters들을 선택해야 한다.

아래 그림처럼 student-t distribution은 single peak에 대칭인 형태이다. 

normal distribution과 비슷해 보인다. 이 student-t probability density funciton은 gamma function을 이용한다. 이 function은 두 parameters를 갖는데, peak density의 위치를 specify하는 location parameter, distribution이 얼마나 멀리 퍼져있는가를 나타내는 non-negative scale parameter가 있다. 

위 그림에서 degree of freedom k는 항상 sample size -1 로 고정된다.

다음은 exponential이다.

위 그림에서 lambda가 커질수록, peak of distribution(왼쪽의 density절편)이 커지고, density의 drop-off가 가팔라진다.

exponential distribution을 fit하기 위해서, lambda = 1 / mean of the feature로 세팅한다.

 

다음은 Mixture of n Gaussians이다.

 

parameter들은 guided search techniques를 통해 fit된다.

distribution의 관점에서, normal과 student-t의 차이는 normal distribution에는 light tails라는게 있고, student-t에는 fat tails라는게 있다는 점이다. 위 그림에서 fat tails와 light tails의 차이를 보여주는데, 왼쪽의 (a)가 light tail distribution이고, (b)가 fat-tail distribution이다. fat tail과 light tail distribution은 상당히 중요한데, 우리가 normal distribution을 이용할 때, 우리는 암시적으로 distribution의 평균값에서 값들이 dramatical하게 떨어질것이라고 가정하고있기 때문이다. data analysts의 가장 흔한 실수는 unimodally distributed data를 normal distribution으로 modeling하는 것이다. 통계적인 방법으로(예를 들어 Kolmogorov-Smirnov test)를 통해서 이 feature이 normally distributed인지 아닌지를 확인할 수 있다.

light-tail을 가진 normal distribution은 데이터 내의 outlier에 민감하다. 위 그림은 outlier가 어떻게 normal과 student-t 분포에 영향을 미치는지 보여준다. 만약 outlier가 없으면 (a)처럼 둘다 잘 fitting된다. 하지만 (b)처럼 outlier가 발생할 경우, student-t에 비해서 훨씬 더 많은 영향을 받은것을 볼 수 있다. 따라서 상대적으로 적은 data를 다루거나, noisy datasets일 경우에는 unimodal 방법으로 modeling해야 한다.

 

그렇다면 어떻게 PDF를 정의할 수 있을까?

PDF를 정의하기 위해서는,

1) 어떤 확률 분포의 모델을 사용할지 정한다.

:이를 위해서, feature의 density historgram을 만들어서 histogram의 모양과 standard distribution의 모양을 비교한다.

2) parameter들을 feature values in the dataset에 fitting한다.

: 대부분의 데이터 분석 packages와 programming APIs들은 specific distribution to a given dataset에 fitting할 수 있도록 function과 implement methods를 제공한다.

 

예제와 함께 살펴보자. 

continuous target feature에 대해서 naive bayes를 이용하고 싶다. 

우린 new Account Balance(AB) feature에 대해서 두개의 PDF를 만들것이다.

두개의 PDF는 반드시 동일한 statistical distribution을 이용할 필요는 없다.

(a)는 fraudulent = true일 때, (b)는 false일 때를 나타낸 것이다.

위 모양으로 미루어보아, true일 때는 exponential distribution, falase일 때는 normal distribution을 이용한다.

이제 distribution을 선택했으므로 data를 distribution에 fit 시키기 위해 다음 단계로 넘어간다.

 

먼저 exponential distribution에 fitting시키기 위해서 Fraudulent = True일 때 sample의 AB feature의 평균값(bar(x)을 계산한다. 그 후 lambda parameter를 1/bar(x)로 설정한다.

 

normal distribution에 fitting하기 위해서는, fraudulent = false일 때의 sample의 AB feature의 평균과 표준편차를 구한다. 그후 parameter들을 normal distribution에 fitting한다.

계산 결과는 다음과 같다

k=3으로 Laplace smoothed probabilities를 만든다. 

그렇다면 CH = paid, GC = guarantor, ACC = free, Account Balance = 759.07일때 Fraudulent는 어떻게 될까?

0.2222*0.2667*0.2*0.00039*0.3 = 0.000001386이 되고,

0.2692*0.1304*0.1739*0.00077*0.7 = 0.00000329가 된다.

따라서 ~fr이 더 크므로, fraudulent = false를 출력할 것이다.

 

그 외에도 우리는 Binning이라는 technique을 여기 적용할 수 있다.

일반적으로 equal-frequency binning을 이용할 것을 권장한다. 왜냐하면 equal-width binning은 uneven distribution of instances를 초래할 수 있고, uneven distribution은 probability based models에서 dramatic and unanted consequences를 나타낼 수 있다. 

예를 들어 Loan Amount라는 새로운 descritive feature가 추가되었다고 하자. 이 feature을 4개의 bin으로 equal-frequency binning을 수행할 것이다.

다음과 같이 binning을 수행한다. 그러면 Bin Threshold는 

다음과 같이 정해진다. 그럼 Laplace smooth k=3으로 수행한 결과는 다음과 같아진다.

이제 CH = paid, GC = guarantor, ACC = free, AB = 759.07, Loan Amount=8000의 data를 예측해보자.

 

0.3*0.2222*0.2667*0.2*0.00039*0.3333 = 0.0000004621

0.7*0.2692*0.1304*0.1739*0.00077*0.1923 = 0.0000006327이 된다.

 

이렇게 Probability Based Learning은 마무리짓는다.