S30 Logo
S30 AI Labwww.thes30.com
Back
#6

Probability Essentials

Easy📐 Math for MLW2 D3

Probability Essentials

Build ML-relevant probability intuition: random variables, expectations, variance, Bayes’ rule, common distributions, and sampling.

Students can compute probabilities/expectations, implement small simulations, and explain how probability maps to ML (calibration, Naive Bayes, uncertainty).

Progress — 0/6 tasks

1Tasks
2Discrete Random Variables
3Conditional Probability & Bayes
4Continuous Distributions (Normal)
5Naive Bayes Thinking (Optional Mini)

Interview Angles

  • Why can a “99% accurate test” still have low P(D|+)?

FAANG Gotchas

  • Underflow from multiplying tiny probabilities; use logs.

Asked At

GoogleGitHub
Python 3 — Notebook
0/6 solvedSubstack Notes
1
Dataset & Setup

Probability Essentials — FAANG-Level Lab

Goal: ML-relevant probability: expectation, variance, Bayes, and simulation checks.

Outcome: You can reason about uncertainty, distributions, and Bayes updates (interview-ready).

Loading editor...
Solution
1

Discrete Random Variables

2
Expectation & variance from a PMF
2

Section 1 — Discrete Random Variables

Task 1.1: Expectation & variance from a PMF

Given values x and probabilities p (sum to 1):

  • implement E[X] and Var(X)

  • E[X] = sum p_i x_i

  • Var(X) = E[X^2] - (E[X])^2

Explain: Why is variance not linear, but expectation is?

Explain: Why is variance not linear, but expectation is?
Loading editor...
Solution
2

Conditional Probability & Bayes

3
Bayes theorem (classic interview)
1

Section 2 — Conditional Probability & Bayes

Task 2.1: Bayes theorem (classic interview)

Disease test example:

  • prevalence P(D)=0.01
  • sensitivity P(+|D)=0.99
  • false positive rate P(+|~D)=0.05 Compute P(D|+)

P(D|+) = P(+|D)P(D) / (P(+|D)P(D) + P(+|~D)P(~D))

FAANG gotcha: base-rate fallacy.

Loading editor...
Solution
4
Simulation check (sanity)
1

Task 2.2: Simulation check (sanity)

Simulate N people and estimate P(D|+) empirically.

  • sample disease ~ Bernoulli(P_D)
  • sample test result conditional on disease

Explain: Why does simulation converge to the analytic value?

Explain: Why does simulation converge to the analytic value?
Loading editor...
Solution
3

Continuous Distributions (Normal)

5
Standardization (z-score)
2

Section 3 — Continuous Distributions (Normal)

Task 3.1: Standardization (z-score)

Given X ~ Normal(mu, sigma^2). Compute standardized Z=(X-mu)/sigma.

  • simulate X and check Z mean ~0, std ~1

ML link: standardization shows up in preprocessing and SGD stability.

Loading editor...
Solution
4

Naive Bayes Thinking (Optional Mini)

6
Compute log-odds for a toy Naive Bayes
1

Section 4 — Naive Bayes Thinking (Optional Mini)

Task 4.1: Compute log-odds for a toy Naive Bayes

Given word likelihoods for spam vs ham, compute posterior odds for a message.

  • work in log space (sum logs)

FAANG gotcha: multiplying small probabilities underflows; use logs.

Loading editor...
Solution

Need help? Share feedback