← Data Science / ML
Day 1 · Probability and Statistics for ML: Distributions, Bayes, Hypothesis Tests and Metrics
Data Science / ML · Crash Course
Day 1

Probability and Statistics for ML: Distributions, Bayes, Hypothesis Tests and Metrics

⏱ About 90 minutes · 21 pages
By the end of today you will be able to
  • ✔ 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
  1. Why an ML fresher needs probability and statistics
  2. Probability basics: sample space, events and the rules
  3. Conditional probability and independence

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.

Data Science / ML · Day 12 / 5

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.

S = 60 students Cricket 30 Football 20 only 20 both 10 only 10 neither 20
✍️ Example 1 — Addition rule with a Venn diagram
  1. In a class of 60, 30 like cricket, 20 like football and 10 like both.

  2. Students who like at least one = 30 + 20 − 10 = 40.

  3. P(cricket or football) = 40 / 60.

  4. Answer: 2/3 (about 0.667). The 20 who like neither are outside both circles.

✍️ Example 2 — "At least one" using the complement
  1. Roll a fair die twice. Find P(at least one six).

  2. 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.

  3. P(at least one six) = 1 − 25/36 = 11/36.

  4. Answer: 11/36 ≈ 0.306.

🙋 Try it now

Two fair coins are tossed. What is the probability of getting at least one head?

Data Science / ML · Day 13 / 5

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
✍️ Example 3 — Reading a conditional probability from a table
  1. P(bought | app user): look only at the 120 app users. 48 of them bought.

  2. P(bought | app user) = 48 / 120 = 0.4.

  3. P(bought | website user) = 16 / 80 = 0.2.

  4. Answer: app users are twice as likely to buy (0.4 vs 0.2).

✍️ Example 4 — Turning the condition around
  1. Now find P(app user | bought). Look only at the 64 buyers.

  2. 48 of the 64 buyers used the app.

  3. P(app user | bought) = 48 / 64 = 0.75.

  4. 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).

✍️ Example 5 — Testing independence
  1. P(app user) = 120 / 200 = 0.6 and P(bought) = 64 / 200 = 0.32.

  2. If they were independent, P(app and bought) would be 0.6 × 0.32 = 0.192.

  3. The real value is 48 / 200 = 0.24, which is not 0.192.

  4. Answer: not independent. Using the app is linked with buying.

Data Science / ML · Day 14 / 5
Free preview ends here

Keep going with the full course

Day 1 has 21 pages. You have read the first 3.

See what's inside →