ナイーブベイズ NaiveBayes のまとめ
What is ナイーブベイズ ?
ナイーブベイズは、ベイズ定理を元に作られ、事前確率(Prior probability) とその尤度(likelihood)(尤度の説明)から、事後確率(Posterior probability) を割り出し、その事後確率がもっとも高いカテゴリへ分類するというものです。スパムメールの判断などに使われているで有名です。
Extracted from 'Introduction to Machine Learning', Udacity
上記は、'LIFE DEAL' というメールの文面から、Sara と Chris どちらが送ったのかをナイーブベイズで予想している。
Chris と Sara のそれぞれのメールの送る確率は、50% ずつで、(事前確率)
Chris は LOVE 10%, DEAL 80%, LIFE 10% の割合で単語を使うのに対し、
Sara は LOVE 30%, DEAL 20%, LIFE 30% の割合で単語を使う。(尤度)
つまり事後確率は、
事前確率 × 尤度 = 事後確率
Chris 10% × 80% × 50% = 0.04
Sara 30% × 20% × 50% = 0.03
これを直すと、
0.04 + 0.03 = 0.07 (これが100% の状態)
Chris 0.04 / 0.07 = 0.57 → 57%
Sara 0.03 / 0.07 = 0.43 → 43%
つまり、57%の確率で Chris な訳なので、結果この LIFE DEAL と書かれたメールは
Chris に分類されるわけです。
default のコード
from sklearn.naive_bayes import GaussianNB
GaussianNB(priors=None)
#以上が default のコードです、シンプルですね。
NaiveBayes の 良い点悪い点。
- 良い点
ひとつひとつの特徴量を独立して考え、それぞれ一次元上に表すので、次元の呪い(curse of dimentionality) を緩和することができる。
- 悪い点
例えば、最初の Chris と Sara のメール判断からもわかるように、Naive Bayes は、単語の頻度だけを見ているので、その文章の順序だったり、組み合わせだったりを判断することはできない。例えば、英語であれば動詞の直前に not がつくだけで、意味が180度変わったりしてしまう。つまり、特徴量を一つの独立したものとして捉え、特徴量同士の相関は考慮されていない。
まとめ
以上が現在筆者のわかる範囲での NaiveBayes の概要です。
日々更新していきますので、追加すべきところ、直すべきところありましたら、コメントいただけると幸いです。