naïve bayes theorem · naïve bayes theorem kanokwatt shiangjen computer science school of...

Post on 05-Oct-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Naïve Bayes Theorem

KANOKWATT SHIANGJENCOMPUTER SCIENCE

SCHOOL OF INFORMATION AND COMMUNICATION TECHNOLOGY

UNIVERSITY OF PHAYAO

Contents

• What is Naïve Bayes Theorem?

• Probabilistic model

• Applications of Naïve Bayes Algorithms

• Q & A

• Reference

2

What is Naïve Bayes Theorem?

• เทคนิคทีไ่ดร้บัความนิยมอยา่งสงู ส าหรบัการจ าแนก (Classification) ในงานดา้น Data Mining ดว้ยใชก้ารค านวณความน่าจะเป็น

3

𝑃 𝐵 𝐴) =𝑃 𝐴 𝐵) × 𝑃(𝐵)

𝑃(𝐴)

P (B | A) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ B เมือ่เกดิเหตุการณ์ A ขึน้ก่อนP (A | B) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ A เมือ่เกดิเหตุการณ์ B ขึน้ก่อนP (A) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ A

P (B) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ B

The Conditional Probability (1)

4

𝑃 𝐴 𝐵) =𝑃(𝐴 ∩ 𝐵)

𝑃(𝐵)

P (A | B) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ A เมือ่เกดิเหตุการณ์ B ขึน้ก่อน

P (B) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ B

P (A B) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ A และ B รว่มกนั (Joint)

(1)

The Conditional Probability (2)

5

𝑃 𝐴 𝐵) =𝑃(𝐴 ∩ 𝐵)

𝑃(𝐵)(1)

BA BA BA

The Conditional Probability (3)

6

𝑃 𝐵 𝐴) =𝑃(𝐴 ∩ 𝐵)

𝑃(𝐴)

P (B | A) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ B เมือ่เกดิเหตุการณ์ A ขึน้ก่อน

P (A) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ A

P (A B) : ความน่าจะเป็นทีจ่ะเกดิเหตุการณ์ A และ B รว่มกนั (Joint)

(2)

The Conditional Probability (4)

7

𝑃 𝐵 𝐴) =𝑃(𝐴 ∩ 𝐵)

𝑃(𝐴)(2)

BA BA BA

P (A B)

• จากสมการ (1) และ (2) นิสติจะพบวา่มคีา่ P (A B) เหมอืนกนัทัง้ 2

สมการ ดงันัน้เราสามารถเขยีนสมการของ P (A B) ไดด้งัแสดงใน (3)

8

𝑃 𝐴 𝐵) =𝑃(𝐴 ∩ 𝐵)

𝑃(𝐵)𝑃 𝐵 𝐴) =

𝑃(𝐴 ∩ 𝐵)

𝑃(𝐴)(1) (2)

𝑃(𝐴 ∩ 𝐵) = 𝑃 𝐴 𝐵 × 𝑃(𝐵) = 𝑃 𝐵 𝐴 × 𝑃(𝐴) (3)

Bayes Theorem

• แกส้มการที่ (3)

9

𝑃(𝐴 ∩ 𝐵) = 𝑃 𝐴 𝐵 × 𝑃(𝐵) = 𝑃 𝐵 𝐴 × 𝑃(𝐴) (3)

𝑃 𝐵 𝐴) =𝑃 𝐴 𝐵) × 𝑃(𝐵)

𝑃(𝐴)(4)

Bayes Theorem

• Posterior Probability: ความน่าจะเป็นของขอ้มลูทีม่ ีAttribute เป็น A จะอยูใ่น Class B

• Likelihood: ความน่าจะเป็นของ Training Data ทีอ่ยูใ่น Class B และมี Attribute เป็น A

• Prior Probability: P(A) ความน่าจะเป็นของ Class A,

• P(B) ความน่าจะเป็นของ Class B10

𝑃 𝐵 𝐴) =𝑃 𝐴 𝐵) × 𝑃(𝐵)

𝑃(𝐴)

Posterior Probability

Likelihood Prior Probability

Weather & PlayWeather Play

Sunny No

Overcast Yes

Rainy Yes

Sunny Yes

Sunny Yes

Overcast Yes

Rainy No

11

Weather Play

Rainy No

Sunny Yes

Rainy Yes

Sunny No

Overcast Yes

Overcast Yes

Rainy No

Frequency Table

Weather Yes No

Overcast 4 0

Rainy 2 3

Sunny 3 2

Total 9 5

Likelihood Table

Weather Yes No

Overcast 4 0 =4/14 0.29

Rainy 2 3 =5/14 0.36

Sunny 3 2 =5/14 0.36

Total 9 5

=9/14 =5/14

0.64 0.36

The Problem: The Players will play if weather is sunny. Is this statement is correct?

Source: https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

Samples = 14

The Players will play if weather is sunny

• P(Yes | Sunny) = P(Sunny | Yes) * P(Yes) / P(Sunny)• P(Sunny | Yes) = 3 / 9 = 0.33

• P(Sunny) = 5 / 14 = 0.36

• P(Yes) = 9 / 14 = 0.64

• P(Yes | Sunny) = 0.33 * 0.64 / 0.36

= 0.59

12Source: https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

The Players will not play if weather is sunny

• P(No | Sunny) = P(Sunny | No) * P(No) / P(Sunny)• P(Sunny | No) = 2 / 5 = 0.4

• P(Sunny) = 5 / 14 = 0.36

• P(No) = 5 / 14 = 0.36

• P(No | Sunny) = 0.4 * 0.36 / 0.36

= 0.4

13Source: https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

The Players will play if weather is overcast

• P(Yes | Overcast) = P(Overcast | Yes) * P(Yes) / P(Overcast)• P(Overcast | Yes) = 4 / 9 = 0.45

• P(Overcast) = 4 / 14 = 0.29

• P(Yes) = 9 / 14 = 0.64

• P(Yes | Overcast) = 0.45 * 0.64 / 0.29

= 0.99

14Source: https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

The Players will not play if weather is overcast

• P(No | Overcast) = P(Overcast | No) * P(No) / P(Overcast)• P(Overcast | No) = 0 / 5 = 0.00

• P(Overcast) = 4 / 14 = 0.29

• P(No) = 5 / 14 = 0.36

• P(Yes | Overcast) = 0.00 * 0.36 / 0.29

= 0.00

15Source: https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

Pros and Cons of Naïve Bayes Theorm

• Pros

• มคีวามสะดวกและรวดเรว็ในการจ าแนก Class ของ Dataset โดยเฉพาะ Multiple Class

• ใช้ Training Dataset จ านวนไมม่าก• ท างานไดด้กีบัขอ้มลูทีม่กีารกระจายแบบปกติ (Normal Distribution)

• Cons

• ถา้ขอ้มลูทีใ่ชใ้นการทดสอบ (Testing Dataset) ไมป่รากฏอยูใ่น Training Dataset จะท าใหไ้มส่ามารถ Prediction ได้

• ในชวีติจรงิ มนัแทบทีจ่ะเป็นไปไมไ่ดท้ีเ่ราจะมี Set of Predictors ทีเ่ป็นอสิระต่อกนัอยา่งแทจ้รงิ (Completely independent)

16Source: https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

Applications of Naïve Bayes Algorithms

• Real time Prediction: การใชเ้พือ่ท านาย และจ าแนกแบบ Real time

เนื่องจากความสามารถในการ Classify ทีม่คีวามเรว็สงู• Text classification: การจ าแนกขอ้ความ เชน่รปูแบบของค าทีม่กัเกดิขึน้บ่อย เชน่ เดนิตาก ลม / กนิแลว้แขง็ แรงไมม่ี หมด

• Sentiment Analysis: การใชเ้พือ่ท านายความรูส้กึในระบบ Social

Network เพือ่ทราบความรูส้กึเชงิบวก หรอื ลบของลกูคา้• Spam Filtering: การคดักรอง E-mail

17Source: https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

Q & A

18

Reference• http://dataminingtrend.com/2014/naive-bayes/

• https://www.analyticsvidhya.com/blog/2017/09/naive-bayes-explained/

19

top related