貝氏定理

機率原理介紹

  • 條件機率
  • 交集、聯集
  • Margianl Probability:將指定機率相加起來的結果
  • 獨立定義

貝氏分類器

Decision Theory

剛剛有提到貝氏定律的原理,而ML也是特過部分已知的特徵,來決定最後的label,這和貝氏定理有異曲同工之妙

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Terms of Bayes Theorem

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • X: 證據,如魚的長度為3公分
  • H: 未知的假設,如猜測這條魚是一隻鮭魚
  • P(H): priorb proability,假設成立的可能性
    • 假設先捕捉1000隻魚,觀察是鮭魚的機率
  • P(X): evidence probability,已知的證據成立的可能性,如這條魚真的是3公分
    • 假設先捕捉1000隻魚,觀察是3公分的機率
  • P(X|H): likelihood,已知假設成立,則符合證據的likelihood(似然度)
  • P(H|X): posterior probability,已知證據成立,則假設亦成立的posterior probability(後驗機率)
    • 今天有一條新的魚,只知道他為三公分,則預測他是否為鮭魚

Bayes Formula

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Problem Type

Decision before Observations

Decision after Observations

  • 例子: 假設我們現在已經知道這條魚確切的身長(X),那我們該如何利用X證明H呢
    ![](img from page 38)

Class-conditional Probability Desnity Function

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • 例: 今天要從樣本當中魚的長度判斷說這條魚是哪種魚,則我們應該會有以下條件
    • 樣本魚的長度範圍(可能從20~50cm)
    • 兩種魚出現的機率(A魚有30%,B魚有70%)
    • 這兩種魚的長度分布pdf(可能有20%A魚有30公分之類的)
      從這三種來推斷說當今天抓了一條45公分的魚,則最可能為哪一種魚
  • 公式為P(X|H)
  • Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  • 你也可以將已知的證據與圖之間的關係畫出來
    接著我們就可以根據*X的值,來判斷比較有可能是哪個類別

已知的部分:

  • Prior probability: P(H)
  • Class-conditional pdf: P(X|H)
  • 證據們: *X
    • 自己覺得這邊有點像是Random Variable的概念
      Bayes Formula: 把已知的部分轉換成未知的機率P(H|*X)
      未知的部分:
      P(H|*X)

貝氏分類法

介紹

  • A statistical classifier: predict class的memebership/label的機率
  • Foundation(理論): 基於貝氏定理所推出
  • Performance(效能表現):跟decision tree和選擇性的CNN有的比
  • Standard: 雖然有時候很難靠著貝氏定律直接算出想要的答案結果,但是可以靠著貝氏來判段衡量哪種計算方式比較好

Prediction on Baye's Theorem

![](img from page 58 up)
其實也是上面筆記有提到的部分

Naive Bayes Classifier

那現在要介紹的Naive Bayes Classifier又跟上面所提到的部份差在哪裡呢?
現在我們可以有很多個Feature(x1~xn)及多個事件(C1~Cn)
而Naive Bayes Classifier就是透過條件機率來探討

![](img from page 60 up)
則我們可透過上述公式中知道如果想了解一個特定事件,則需要了解已知該事件的情況下,所有X的發生機率為多少。
而如果想算出P(Xi|C~i),又須了解該事件分布是否為連續

  • 若不連續,就按照發生事情的數量相持即可
  • 若為連續,則透過平均數與標準差計算
    • ![](img from page 60 down)
    • miu為平均數
    • sigma為標準差

Example

現在來分析(age <=30, Income = medium, Student = yes, Credit_rating = Fair)的顧客買與不買哪個機率較高
![](table from page 61)
算法如下
![](whole calculating process from page 62)

分析

  • 優點:
    • 比較好去做計算(至少還勉強算得出來)
    • 在大多數的情況下都可以有不錯的結果
  • 缺點:
    • 該分類法假設所有事件都是完全獨立的,但有時候有些class/label是有關連性的
    • 例如:假設今天有人有高血壓的問題,則它同時也有心臟病的問題可能也會高一些

Avoiding the Zero-Probability

今天公式如下:
![](img from page 64 up)
如果今天有一個子事件是沒有發生過的,則很有可能會有分母為0的不好狀況,因此我們會透過laplacian correction來從其他子事件當中移一些過去

模型評估與選擇

Confusion Matrix

![](img from page 67 up)
下面是實際計算的例子
![](img from page 67 down)