Foundations for Machine Learning

Linear Algebra Probability Statistics Calculus Programming Optimization

Curated by: Vizuara (39 videos)


Currently Playing: Foundations for ML | Naive-Bayes classification, ML model evaluation | confusion matrix [Lecture 16]

"Nigerian Prince" emails – a true legend of the internet + Naive-Bayes classifier: What if you receive an email that has the phrases "Nigerian Prince" and "Congratulations"? Is it spam? Let us find out using a Naive Bayes classifier. The Scenario: Total emails: 100 -20 are spam -80 are not spam For "Nigerian Prince": -15 out of 20 spam emails contain "Nigerian Prince" (75%) -5 out of 80 non-spam emails contain "Nigerian Prince" (6.25%) For "Congratulations": -17 out of 20 spam emails contain "Congratulations" (85%) -7 out of 80 non-spam emails contain "Congratulations" (8.75%) Step 1: Probability of Spam and Not-Spam Probability of spam = 20/100 = 0.2 Probability of not-spam = 80/100 = 0.8 Step 2: Apply Naive Bayes To calculate the probability of an email being spam, we multiply: Probability of spam (0.2) Probability of "Nigerian Prince" given spam (0.75) Probability of "Congratulations" given spam (0.85) This gives: 0.2 × 0.75 × 0.85 = 0.1275 For not-spam, we multiply: Probability of not-spam (0.8) Probability of "Nigerian Prince" given not-spam (0.0625) Probability of "Congratulations" given not-spam (0.0875) This gives: 0.8 × 0.0625 × 0.0875 = 0.004375 Step 3: Normalize the Results Now we calculate the final probabilities by normalizing: Spam = 0.1275 / (0.1275 + 0.004375) ≈ 0.967 (or 96.7%) Not-spam = 0.004375 / (0.1275 + 0.004375) ≈ 0.033 (or 3.3%) The result: If an email contains both "Nigerian Prince" and "Congratulations," there is a 96.7% chance it is spam. Turns out the Nigerian Prince is not trustworthy after all (but we already knew that, right?). Spam filters may rely on algorithms, but it is fun to examine the math behind the magic every now and then! In this lecture I published on Vizuara's YouTube channel I talk about the basic math and assumptions behind the Naive-Bayes classifier and also about how to evaluate how good an ML model is. This lecture is part of the "Foundations for Machine Learning" course: https://youtu.be/CQy5bNjUh4k


Tracks in this Playlist