Multinomial Naive Bayes

김재욱·2023년 8월 30일

Naive Bayes Classifier

목록 보기
2/2

Naive Bayes Classifier

P(YcX1,...,Xn)=P(Yc)i=1nP(XiYc)i=1nP(Xi)P(Y_c|X_1,...,X_n)={P(Y_c) \prod_{i=1}^n P(X_i|Y_c) \over \prod_{i=1}^n P(X_i)}

Yc\mathrm{Y}_{c} is a label

Likelihood 계산 방법

i=1nP(XiYc)\prod_{i=1}^n P(X_i|Y_c)

P(XiYc)=tf(xi,dYc)+αNdYc+αVP(X_i|Y_c)={\sum tf(x_i,d\in Y_c) + \alpha \over \sum \mathrm{N}_{d\in Y_c}+\alpha\cdot V}

  • XiX_i : A word from the feature vector X of particilar sample.
  • tf(xi,dYc)\sum tf(x_i,d\in Y_c) : The sum of raw term frequencies of word XiX_i belong to class YcY_c in document
  • NdYc\sum \mathrm{N}_{d\in Y_c} : The sum of all term frequencies in the training dataset for class YcY_c
  • α\alpha : An additive smoothing parameter (α=1\alpha = 1 for Laplace smoothing)
  • VV : The size of the vocabulary (number of different words in the training set)

Multinomial Naive Bayes(다항 분포 나이브 베이즈)

  • 주로 텍스트 분류와 같은 다중 클래스 문제에 사용

  • 단어의 존재 유무가 아닌 단어의 출현횟수를 Feature로 사용

  • 아래의 가정을 기반으로 한다.

    • 각 특성(단어 등)은 독립적으로 기여한다.
    • 각 특성의 값은 다항 분포를 따른다.

Bag of words

  • 모든 샘플 텍스트를 하나의 Vector로 표현
  • 단어별로 인덱스를 부여해서 한 문장(또는 문서)의 단어의 개수를 Vectore로 표현(Corpus(말뭉치)라고도 함)

Example

Data

DocWordsClass
Training1Chinese Beijing Chinesec
2Chinese Chinese Shanghaic
3Chinese Macaoc
4Tokyo Japan Chinesej
Test5Chinese Chinese Chinese Tokyo Japan?

Bag of words

ChineseBeijingShanghaiMacaoTokyoJapanclass
Training1210000c
2201000c
3100100c
4100011j
Test5300011?

prior * Likelihood

Test의 class가 'c'로 구분될 확률

  • P(cd5)P(c)P(Chinesec)3P(Tokyoc)P(Janpanc)P(c|d5)\cdot P(c)P(Chinese|c)^3 P(Tokyo|c)P(Janpan|c)
    =34(5+18+6)3(0+18+6)(0+18+6)={3 \over 4}\ast \left( \frac{5+1}{8+6} \right)^3 \ast \left( \frac{0+1}{8+6} \right) \ast \left( \frac{0+1}{8+6} \right)

Test의 class가 'j'로 구분될 확률

  • P(j)P(Chinesej)3P(Tokyoj)P(Janpanj)P(j)\cdot P(Chinese|j)^3 P(Tokyo|j)P(Janpan|j)
    =14(1+13+6)3(1+13+6)(1+13+6)={1 \over 4}\ast \left( \frac{1+1}{3+6} \right)^3 \ast \left( \frac{1+1}{3+6} \right) \ast \left( \frac{1+1}{3+6} \right)

0개의 댓글