🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #31

Probability for Machine Learning

Machine learning rarely deals in certainties — a classifier doesn't just say "spam," it estimates how likely an email is spam. Probability is the language for reasoning about that uncertainty precisely.

Core Definitions

TermMeaningML Example
Sample spaceThe set of all possible outcomes{spam, not spam}
EventA subset of outcomes you care about"email is spam"
Random variableA variable whose value is an outcome of a random processThe predicted class for a given email
P(A)Probability of event A, a number between 0 and 1P(spam) = 0.3

Formula — Basic Probability

\[ P(A) = \frac{\text{number of outcomes favoring } A}{\text{total number of possible outcomes}} \]

For independent events (one doesn't affect the other's probability):

\[ P(A \cap B) = P(A)\,P(B) \]

Numerical Example

Out of 200 historical emails, 60 were spam. \(P(\text{spam}) = \frac{60}{200} = 0.3\). If word choice and sender domain were independent spam signals with \(P(\text{suspicious word})=0.4\) and \(P(\text{spam})=0.3\), then \(P(\text{both}) = 0.4 \times 0.3 = 0.12\) — if they're truly independent, which in real email data they usually aren't (this is exactly the simplifying assumption Naive Bayes makes).

total_emails = 200
spam_emails = 60

p_spam = spam_emails / total_emails
print(p_spam)   # 0.3

Why Probability Matters Throughout ML

  • Classification outputs: model.predict_proba() in scikit-learn returns a probability per class, not just a hard label
  • Naive Bayes: built entirely on conditional probability and Bayes' theorem
  • Uncertainty and thresholds: deciding "predict positive if probability > 0.5" (or a different threshold) is a probability-based business decision — see Logistic Regression
  • Statistical evaluation: deciding whether one model is genuinely better than another, not just luckier on one test set

Common Mistakes

  • Treating a model's predicted probability as a guaranteed frequency — a well-calibrated model's "70% confident" predictions should be correct about 70% of the time on average, but any single prediction can still be wrong.
  • Assuming independence when events aren't actually independent — this is a simplifying assumption, not a law, and gets it wrong when features are correlated.

Interview Relevance

Q: "What's the difference between a model's predicted class and its predicted probability?" The predicted class is the probability thresholded into a hard decision (e.g. probability > 0.5 → class 1); the probability itself carries more information — two predictions both classified "positive" can have very different confidence (0.51 vs 0.99).

Practice Question

A dataset has 1000 transactions, 40 of which are fraudulent. What is \(P(\text{fraud})\)? If a second, independent signal has a 10% chance of triggering regardless of fraud status, what's the probability both the fraud event and the signal occur together?

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Probability for Machine Learning – FAQs

Quick answers about learning Probability for Machine Learning in Machine Learning.

This free note from CodingNow 2.0 explains Probability for Machine Learning in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Probability for Machine Learning, is 100% free with no signup required.
With focused practice, most students grasp Probability for Machine Learning in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now