Swipe left or tap Next ▶ to turn the page.
Select any text to highlight it or add a note. Tap a diagram to enlarge it.
Probability and Statistics for ML: Distributions, Bayes, Hypothesis Tests and Metrics
- ✔ Solve probability, conditional probability and Bayes' theorem questions quickly and correctly
- ✔ Recognise the binomial, Poisson and normal distributions and use z-scores
- ✔ Run a hypothesis test step by step and explain p-values, Type I and Type II errors
- ✔ Compute accuracy, precision, recall, F1, MAE, RMSE and R² from raw numbers
Why an ML fresher needs probability and statistics
Every model you train is a guess under uncertainty, and statistics is the language interviewers use to check whether you understand that guess.
A machine learning model never "knows" the answer. It looks at past data, finds patterns, and then makes a guess about new data. Probability tells us how likely each guess is. Statistics tells us how to learn from data, how to summarise it, and how to judge whether a result is real or just luck.
In a data science technical round for freshers, the questions on this topic usually fall into five groups:
| Group | What they check |
|---|---|
| Probability | Basic rules, conditional probability, Bayes' theorem |
| Distributions | Binomial, Poisson, normal, z-scores |
| Descriptive stats | Mean, median, mode, variance, outliers |
| Inference | Sampling, hypothesis tests, p-values, confidence intervals |
| Metrics | Confusion matrix, precision, recall, F1, RMSE, R² |
Here is where each idea fits inside a normal ML project. Notice that statistics appears at almost every stage, not just at the start.
flowchart LR A[Collect data] --> B[Describe data<br/>mean, spread, outliers] B --> C[Model the data<br/>distributions, Bayes] C --> D[Train model] D --> E[Evaluate<br/>metrics] E --> F[Is the gain real?<br/>hypothesis test] F --> G[Ship or improve]
Today we will cover the theory with small numbers you can work out on paper. Tomorrow you will meet NumPy and pandas, which do the same calculations on large data.
Probability basics: sample space, events and the rules
Almost every probability question in an interview can be solved with three rules: the complement, addition and multiplication rules.
An experiment is any action with an uncertain result, like rolling a die. The sample space S is the set of all possible results. For a die, S = {1, 2, 3, 4, 5, 6}. An event is any subset of S, for example "an even number" = {2, 4, 6}.
When all results are equally likely:
P(event) = (number of favourable results) / (total number of results)
Every probability lies between 0 (impossible) and 1 (certain).
The three core rules
| Rule | Formula | Use it when |
|---|---|---|
| Complement | P(not A) = 1 − P(A) | The question says "at least one" |
| Addition | P(A or B) = P(A) + P(B) − P(A and B) | You want either event |
| Multiplication (independent) | P(A and B) = P(A) × P(B) | Both events must happen |
| Multiplication (general) | P(A and B) = P(A) × P(B | A) | Draws without replacement, linked events |
The addition rule subtracts the overlap because the overlap is counted twice. A Venn diagram shows why.
In a class of 60, 30 like cricket, 20 like football and 10 like both.
Students who like at least one = 30 + 20 − 10 = 40.
P(cricket or football) = 40 / 60.
Answer: 2/3 (about 0.667). The 20 who like neither are outside both circles.
Roll a fair die twice. Find P(at least one six).
P(no six in one roll) = 5/6. The rolls are independent, so P(no six in two rolls) = 5/6 × 5/6 = 25/36.
P(at least one six) = 1 − 25/36 = 11/36.
Answer: 11/36 ≈ 0.306.
Two fair coins are tossed. What is the probability of getting at least one head?
P(no head) = 1/2 × 1/2 = 1/4, so P(at least one head) = 1 − 1/4 = 3/4.
Conditional probability and independence
Most ML models output a conditional probability, such as "the chance this mail is spam, given its words", so this idea is the heart of the subject.
Conditional probability is the probability of A when we already know B has happened. We write it P(A | B), read "A given B".
P(A | B) = P(A and B) / P(B)
Knowing B shrinks the sample space to only the cases inside B. That is all the formula says.
A worked table
An online store in Jaipur looked at 200 customers last week.
| Bought | Did not buy | Total | |
|---|---|---|---|
| App user | 48 | 72 | 120 |
| Website user | 16 | 64 | 80 |
| Total | 64 | 136 | 200 |
P(bought | app user): look only at the 120 app users. 48 of them bought.
P(bought | app user) = 48 / 120 = 0.4.
P(bought | website user) = 16 / 80 = 0.2.
Answer: app users are twice as likely to buy (0.4 vs 0.2).
Now find P(app user | bought). Look only at the 64 buyers.
48 of the 64 buyers used the app.
P(app user | bought) = 48 / 64 = 0.75.
Answer: 0.75. Notice that P(A | B) and P(B | A) are different numbers (0.4 and 0.75 here).
Independence
Two events are independent when knowing one does not change the chance of the other. The test is:
P(A and B) = P(A) × P(B), or equally P(A | B) = P(A).
P(app user) = 120 / 200 = 0.6 and P(bought) = 64 / 200 = 0.32.
If they were independent, P(app and bought) would be 0.6 × 0.32 = 0.192.
The real value is 48 / 200 = 0.24, which is not 0.192.
Answer: not independent. Using the app is linked with buying.
Keep going with the full course
Day 1 has 21 pages. You have read the first 3.
See what's inside →