ML Study Hub

Home / MLF / Week 10

Week 10 · Probability for machine learning

Official syllabus line: Examples of probabilistic models in machine learning problems
About 100 minEnd Term material (see exam radar)BSCS2004 · Harish Guruprasad Ramaswamy, Arun Rajkumar, Prashanth LA
Before you start: Week 1 (just the idea of data points). Fractions and basic counting. We build all the probability from scratch.
Watch first: the animated story of this weekAbout 1-2 minutes of real 3D animation with a friendly voice. Pause any time.
Read the words of the video
  1. When you toss a coin many times, you expect about half heads and half tails. But the exact sequence is always a surprise! Our world is full of such uncertainty. Probability is like a special language that helps us understand and talk precisely about these uncertain events. It lets us make smart guesses about what might happen next.
  2. This week, we learn key tools. Probability rules help us combine events. Random variables are numbers decided by chance, with averages and how spread out they are. We'll explore common patterns called distributions and see why averaging data helps us understand the world better with powerful mathematical guarantees.
  3. Imagine a rare disease, affecting only one in a hundred people. A test is usually right for sick people, but sometimes gives false alarms for healthy ones. If your test is positive, Bayes' rule helps us calculate that your actual chance of being sick is still quite low, around 15%, because the disease itself is so uncommon.
  4. For your exams, remember key questions like the Chebyshev mark problem and the bulb lifetime example. Practice binomial variance and conditional probability with Bayes' rule. You've now built a strong toolkit to tackle uncertainty, understand data, and make informed predictions. Keep exploring these exciting ideas!

The one-minute story

Think of it like this

Toss a coin 100 times and you will see about 50 heads, but never exactly "head, tail, head, tail". The world is uncertain, and data is a messy, noisy sample of it. Probability is the language for talking about that uncertainty precisely, and machine learning is full of it: "the model says 83% spam", "the average error is about 2 give or take 0.3", "with 95% confidence the true value is in this range".

This week is a tool kit:

  1. the rules of probability (and Bayes' rule, which lets you flip "what I saw" into "what is probably true");
  2. random variables, their average (expectation) and spread (variance);
  3. the handful of distributions you will meet again and again;
  4. four big results that say why averaging data works: Markov, Chebyshev, the law of large numbers, the central limit theorem.

By the end of this week you can:

  • use probability rules, conditional probability, independence and Bayes' rule;
  • compute expectation and variance, and use joint and marginal densities;
  • work with Bernoulli, binomial, uniform, exponential and normal distributions;
  • bound probabilities with Markov and Chebyshev, and explain the law of large numbers and central limit theorem.

Words you need

Words you need
  • Event - something that might happen ("the die shows an even number").
  • Probability P(A)P(A) - a number from 0 (impossible) to 1 (certain).
  • Random variable XX - a number whose value is decided by chance.
  • Expectation E[X]E[X] - the long-run average value.
  • Variance Var⁡(X)\operatorname{Var}(X) - how spread out XX is around its average. Standard deviation σ=Var⁡\sigma=\sqrt{\operatorname{Var}}.
  • Density f(x)f(x) - for a continuous variable, the height of the curve whose area gives probability.
  • Independent - knowing one tells you nothing about the other.
  • i.i.d. - "independent and identically distributed": repeated trials of the same experiment.

Idea 1: The rules of probability

The idea
  • 0≤P(A)≤10\le P(A)\le1, and P(everything)=1P(\text{everything})=1.
  • Complement: P(not A)=1−P(A)P(\text{not }A)=1-P(A).
  • Either-or: P(A∪B)=P(A)+P(B)−P(A∩B)P(A\cup B)=P(A)+P(B)-P(A\cap B).
  • Conditional: P(A∣B)=P(A∩B)P(B)P(A\mid B)=\dfrac{P(A\cap B)}{P(B)}, "the chance of AA once we know BB happened".
  • Independent events: P(A∩B)=P(A)P(B)P(A\cap B)=P(A)P(B).
  • Bayes' rule: P(A∣B)=P(B∣A) P(A)P(B)P(A\mid B)=\dfrac{P(B\mid A)\,P(A)}{P(B)}.
Think of it like this

Bayes' rule flips a question around. A doctor knows "if a person has the disease, the test is positive 90% of the time". But you want to know the opposite: "my test is positive, so how likely is it that I really have the disease?" Bayes' rule converts one into the other, using how common the disease is to begin with.

Solved example: 1. Bayes' rule on a medical test

Question. 1% of people have a disease. A test is positive for 90% of sick people but also for 5% of healthy people. You test positive. What is the chance you are sick?

Solution.

  1. P(D)=0.01P(D)=0.01, P(+∣D)=0.9P(+\mid D)=0.9, P(+∣not D)=0.05P(+\mid\text{not }D)=0.05.
  2. P(+)=P(+∣D)P(D)+P(+∣not D)P(not D)=0.9(0.01)+0.05(0.99)=0.009+0.0495=0.0585P(+)=P(+\mid D)P(D)+P(+\mid\text{not }D)P(\text{not }D)=0.9(0.01)+0.05(0.99)=0.009+0.0495=0.0585.
  3. P(D∣+)=0.9×0.010.0585≈0.154P(D\mid+)=\dfrac{0.9\times0.01}{0.0585}\approx\mathbf{0.154}.

Only about 15%, because the disease is rare, so most positives are false alarms from the huge healthy group. This idea (a prior belief updated by evidence) returns in MLT's Bayesian estimation and Naive Bayes.

Solved example: 2. Pairwise independent is not the same as independent

Question. A fair coin is tossed twice. AA: first toss is heads. BB: second toss is heads. CC: both tosses are the same. Are A,B,CA,B,C independent?

Solution. P(A)=P(B)=P(C)=12P(A)=P(B)=P(C)=\frac12 (CC = HH or TT).

  • P(A∩B)=P(HH)=14=P(A)P(B)P(A\cap B)=P(HH)=\frac14=P(A)P(B). ✓
  • P(A∩C)=P(HH)=14=P(A)P(C)P(A\cap C)=P(HH)=\frac14=P(A)P(C). ✓
  • P(B∩C)=P(HH)=14=P(B)P(C)P(B\cap C)=P(HH)=\frac14=P(B)P(C). ✓

Every pair is independent. But P(A∩B∩C)=P(HH)=14P(A\cap B\cap C)=P(HH)=\frac14, while P(A)P(B)P(C)=18P(A)P(B)P(C)=\frac18. They are not mutually independent. A classic trap.

Idea 2: Random variables, expectation and variance

A discrete random variable takes separate values with a probability mass function p(x)=P(X=x)p(x)=P(X=x). A continuous one has a density f(x)f(x), and P(a≤X≤b)=∫abf(x) dxP(a\le X\le b)=\int_a^bf(x)\,dx (area under the curve). The total area is 1.

E[X]=∑xx p(x)or∫xf(x) dx,Var⁡(X)=E[X2]−(E[X])2E[X]=\sum_x x\,p(x)\quad\text{or}\quad\int x f(x)\,dx,\qquad\operatorname{Var}(X)=E[X^2]-(E[X])^2
The idea
  • Linearity (always true): E[aX+b]=aE[X]+bE[aX+b]=aE[X]+b and E[X+Y]=E[X]+E[Y]E[X+Y]=E[X]+E[Y].
  • Var⁡(aX+b)=a2Var⁡(X)\operatorname{Var}(aX+b)=a^2\operatorname{Var}(X).
  • If X,YX,Y are independent: Var⁡(X+Y)=Var⁡(X)+Var⁡(Y)\operatorname{Var}(X+Y)=\operatorname{Var}(X)+\operatorname{Var}(Y).
  • Covariance Cov⁡(X,Y)=E[XY]−E[X]E[Y]\operatorname{Cov}(X,Y)=E[XY]-E[X]E[Y]. Independent ⇒\Rightarrow covariance 00, but covariance 0 does not imply independent.

Two variables together

A joint density f(x,y)f(x,y) describes both at once. The marginal of XX is what you get by integrating yy away: fX(x)=∫f(x,y) dyf_X(x)=\int f(x,y)\,dy.

Solved example: 3. A joint density

Question. f(x,y)=c xyf(x,y)=c\,xy on the unit square 0≤x≤10\le x\le1, 0≤y≤10\le y\le1 (and 0 elsewhere). Find cc, the marginal of XX, and E[X]E[X].

Solution.

  1. Total probability is 1: ∫01 ⁣ ⁣∫01c xy dy dx=c⋅12⋅12=c4=1⇒c=4\int_0^1\!\!\int_0^1c\,xy\,dy\,dx=c\cdot\frac12\cdot\frac12=\frac c4=1\Rightarrow\mathbf{c=4}.
  2. Marginal: fX(x)=∫014xy dy=4x⋅12=2xf_X(x)=\int_0^14xy\,dy=4x\cdot\frac12=\mathbf{2x} for 0≤x≤10\le x\le1.
  3. E[X]=∫01x⋅2x dx=23E[X]=\int_0^1x\cdot2x\,dx=\frac23.

Since f(x,y)=(2x)(2y)=fX(x)fY(y)f(x,y)=(2x)(2y)=f_X(x)f_Y(y), the two variables are independent here.

Idea 3: The distributions you must know

NameDescribesMeanVariance
Bernoulli(pp)one yes/no trialppp(1−p)p(1-p)
Binomial(n,pn,p)number of yeses in nn independent trialsnpnpnp(1−p)np(1-p)
Uniform(a,b)(a,b)"anything in [a,b][a,b] equally likely"a+b2\frac{a+b}{2}(b−a)212\frac{(b-a)^2}{12}
Exponential(λ\lambda)waiting time until something happens1λ\frac1\lambda1λ2\frac1{\lambda^2}
Normal(μ,σ2)(\mu,\sigma^2)the bell curveμ\muσ2\sigma^2

Exponential details: density λe−λx\lambda e^{-\lambda x} for x≥0x\ge0; P(X>t)=e−λtP(X>t)=e^{-\lambda t}. It is memoryless: if you have already waited ss minutes, the chance of waiting tt more is the same as if you had just arrived: P(X>s+t∣X>s)=P(X>t)P(X>s+t\mid X>s)=P(X>t).

Normal details: about 68% of the mass lies within ±1σ\pm1\sigma of μ\mu, 95% within ±2σ\pm2\sigma, 99.7% within ±3σ\pm3\sigma. Linear changes stay normal: aX+b∼N(aμ+b, a2σ2)aX+b\sim N(a\mu+b,\,a^2\sigma^2); and for independent normals, means add and variances add.

Solved example: 4. Exponential and uniform

Question. (a) The waiting time for a bus is exponential with mean 5 minutes. Find P(wait>10)P(\text{wait}>10) and the 95th percentile. (b) A job's completion time is uniform on [10,b][10,b] with mean 15 minutes. Find bb and P(X>16)P(X>16), then P(X>16∣X>12)P(X>16\mid X>12).

Solution.

(a) Mean 5⇒λ=0.25\Rightarrow\lambda=0.2. P(X>10)=e−0.2⋅10=e−2≈0.135P(X>10)=e^{-0.2\cdot10}=e^{-2}\approx0.135. The 95th percentile xx solves 1−e−0.2x=0.951-e^{-0.2x}=0.95: e−0.2x=0.05e^{-0.2x}=0.05, so x=ln⁡200.2≈14.98x=\frac{\ln20}{0.2}\approx\mathbf{14.98} minutes.

(b) 10+b2=15⇒b=20\frac{10+b}2=15\Rightarrow b=20. P(X>16)=20−1620−10=0.4P(X>16)=\frac{20-16}{20-10}=0.4. For the conditional probability, restrict to X>12X>12: the remaining range is [12,20][12,20], length 8, and the part above 16 has length 4: P(X>16∣X>12)=48=0.5P(X>16\mid X>12)=\frac48=\mathbf{0.5}.

Solved example: 5. Binomial variance

Question. 20% of 400 students own a laptop. If we count the owners, what are the mean and variance of that count?

Solution. Binomial with n=400n=400, p=0.2p=0.2. Mean np=80np=80, variance np(1−p)=400(0.2)(0.8)=64np(1-p)=400(0.2)(0.8)=\mathbf{64} (so σ=8\sigma=8).

Idea 4: Four results that explain why data works

Markov and Chebyshev: bounds with almost no information

The idea

Markov (for X≥0X\ge0, knowing only the mean): for any a>0a>0

P(X≥a)≤E[X]aP(X\ge a)\le\frac{E[X]}{a}

Chebyshev (knowing mean μ\mu and variance σ2\sigma^2): for any k>0k>0

P(∣X−μ∣≥kσ)≤1k2,equivalentlyP(∣X−μ∣≥ε)≤σ2ε2P(|X-\mu|\ge k\sigma)\le\frac1{k^2},\qquad\text{equivalently}\qquad P(|X-\mu|\ge\varepsilon)\le\frac{\sigma^2}{\varepsilon^2}
Think of it like this

Markov: "The average person in the class is 12 years old, so at most one-sixth of them can be 72 or older." There just isn't enough "age" to go round. Chebyshev: "If most people are close to the average, few can be very far." Both give guarantees that hold for any distribution, which is why they are conservative.

Solved example: 6. Markov and Chebyshev

Question. (a) Daily sales have mean 50 (and cannot be negative). Bound P(sales≥200)P(\text{sales}\ge200). (b) Marks have μ=70\mu=70 and σ=8\sigma=8. Bound the chance that a mark differs from 70 by more than 16.

Solution. (a) Markov: ≤50200=0.25\le\frac{50}{200}=\mathbf{0.25}. (b) 16=2σ16=2\sigma, so k=2k=2: P≤122=0.25P\le\frac1{2^2}=\mathbf{0.25}.

The law of large numbers and the central limit theorem

Take nn independent repeats X1,…,XnX_1,\dots,X_n of the same experiment with mean μ\mu and variance σ2\sigma^2, and average them: Xˉn=1n∑Xi\bar X_n=\frac1n\sum X_i. Then E[Xˉn]=μE[\bar X_n]=\mu and Var⁡(Xˉn)=σ2/n\operatorname{Var}(\bar X_n)=\sigma^2/n.

  • Weak Law of Large Numbers (WLLN): as nn grows, Xˉn\bar X_n gets close to μ\mu. Chebyshev makes it precise: P(∣Xˉn−μ∣≥ε)≤σ2nε2→0P(|\bar X_n-\mu|\ge\varepsilon)\le\dfrac{\sigma^2}{n\varepsilon^2}\to0.
  • Central Limit Theorem (CLT): for large nn, Xˉn≈N(μ,σ2/n)\bar X_n\approx N(\mu,\sigma^2/n), whatever shape the original distribution had. This is why bell curves show up everywhere.
Solved example: 7. WLLN with bulbs

Question. Bulb lifetimes are exponential with λ=0.4\lambda=0.4 per year. The average of 50 bulbs is Xˉ\bar X. Give a lower bound for P(1.5<Xˉ<3.5)P(1.5<\bar X<3.5).

Solution. One bulb: μ=1λ=2.5\mu=\frac1\lambda=2.5, σ2=1λ2=6.25\sigma^2=\frac1{\lambda^2}=6.25. For the mean of 50: variance =6.25/50=0.125=6.25/50=0.125. The interval (1.5,3.5)(1.5,3.5) is μ±1\mu\pm1, so by Chebyshev P(∣Xˉ−2.5∣≥1)≤0.12512=0.125P(|\bar X-2.5|\ge1)\le\frac{0.125}{1^2}=0.125. Hence P(1.5<Xˉ<3.5)≥1−0.125=0.875P(1.5<\bar X<3.5)\ge1-0.125=\mathbf{0.875}.

Your turn

Your turn: 1. Bayes

A factory has two machines. Machine A makes 60% of items with 2% defective; machine B makes 40% with 5% defective. An item is defective. What is the chance it came from B?

Need a hint?

Bayes: P(B∣def)=P(def∣B)P(B)P(def)P(B\mid\text{def})=\dfrac{P(\text{def}\mid B)P(B)}{P(\text{def})}.

Show the full solution

P(def)=0.02(0.6)+0.05(0.4)=0.012+0.02=0.032P(\text{def})=0.02(0.6)+0.05(0.4)=0.012+0.02=0.032. P(B∣def)=0.020.032=0.625P(B\mid\text{def})=\frac{0.02}{0.032}=\mathbf{0.625}.

Your turn: 2. Expectation and variance

XX takes values 0,1,20,1,2 with probabilities 0.2, 0.5, 0.30.2,\,0.5,\,0.3. Find E[X]E[X] and Var⁡(X)\operatorname{Var}(X).

Need a hint?

Var⁡=E[X2]−(E[X])2\operatorname{Var}=E[X^2]-(E[X])^2.

Show the full solution

E[X]=0+0.5+0.6=1.1E[X]=0+0.5+0.6=1.1. E[X2]=0+0.5+1.2=1.7E[X^2]=0+0.5+1.2=1.7. Var⁡=1.7−1.21=0.49\operatorname{Var}=1.7-1.21=\mathbf{0.49}.

Your turn: 3. Normal combinations

X∼N(10,4)X\sim N(10,4) and Y∼N(5,9)Y\sim N(5,9) are independent. What is the distribution of 2X−Y+12X-Y+1?

Need a hint?

Mean: use linearity. Variance: a2a^2 and add (independent).

Show the full solution

Mean =2(10)−5+1=16=2(10)-5+1=16. Variance =22⋅4+(−1)2⋅9=16+9=25=2^2\cdot4+(-1)^2\cdot9=16+9=25. So 2X−Y+1∼N(16, 25)2X-Y+1\sim N(16,\,25).

Your turn: 4. Chebyshev

A variable has mean 100 and standard deviation 10. What is the best Chebyshev bound on P(∣X−100∣≥30)P(|X-100|\ge30)?

Need a hint?

30=kσ30=k\sigma.

Show the full solution

k=3k=3, so the bound is 19≈0.111\frac19\approx0.111.

Your turn: 5. Exponential memorylessness

Waiting times are exponential with mean 4 minutes. You have waited 6 minutes already. What is the probability you wait at least 2 more?

Need a hint?

Use memorylessness.

Show the full solution

P(X>8∣X>6)=P(X>2)=e−2/4=e−0.5≈0.607P(X>8\mid X>6)=P(X>2)=e^{-2/4}=e^{-0.5}\approx\mathbf{0.607}. The 6 minutes already waited are irrelevant.

Exam radar

Exam radar

Probability fills the second half of the End Term:

  • Chebyshev in 23 paper summaries, Markov in 20, WLLN in 9, CLT in 9, normal distribution in 12, conditional probability in 10.
  • Repeated numbers: Chebyshev with μ=70,σ=8\mu=70,\sigma=8, deviation 16 →0.25\to0.25 (8 times); WLLN with exponential bulbs λ=0.4\lambda=0.4, n=50→0.875n=50\to0.875 (6 times); Markov bounds on sales/defects/processing time; binomial variance for 20% of 400; fair coin twice, independence of A,B,CA,B,C (6 times).
  • Trending up in 2025 to 2026: exponential waiting times (percentiles, intervals, memorylessness), uniform completion times, joint-density integrals, and spam-style probability stories.
Watch out - real exam trap
  • Markov needs a non-negative variable. Chebyshev needs mean and variance, and its bound is for the two-sided event ∣X−μ∣≥kσ|X-\mu|\ge k\sigma.
  • Chebyshev's σ\sigma is the standard deviation, not the variance; the sample-mean version uses σ2/n\sigma^2/n.
  • Pairwise independence ≠\ne mutual independence.
  • Covariance 0≠0\ne independent.
  • For Var⁡(aX)\operatorname{Var}(aX) remember a2a^2. For independent sums, variances add; standard deviations do not.
  • Exponential: mean is 1/λ1/\lambda, not λ\lambda.

Quick quiz

Quick quiz

Markov's inequality for a non-negative X with mean 10 says P(X at least 50) is at most...

  • 0.5
  • 0.2
  • 0.02
  • 5
E[X] / a = 10 / 50 = 0.2.

For independent X and Y, Var(2X + 3Y) equals...

  • 2 Var(X) + 3 Var(Y)
  • 5 Var(X) + 5 Var(Y)
  • 4 Var(X) + 9 Var(Y)
  • 6 Var(X) Var(Y)
Constants are squared and the variances of independent variables add.

An exponential waiting time has mean 5. The rate lambda is...

  • 5
  • 0.2
  • 25
  • 0.5
Mean = 1/lambda, so lambda = 1/5 = 0.2.

Select all TRUE statements. (select all that apply)

  • Independent random variables have zero covariance.
  • The central limit theorem makes sample averages roughly normal for large n.
  • Zero covariance guarantees independence.
  • Chebyshev's inequality needs the variable to be non-negative.
Zero covariance does not imply independence. Chebyshev needs only a mean and variance.

Recap

Remember this
  • Rules: complement, either-or, conditional, independence, Bayes. Pairwise ≠\neq mutual independence.
  • E[aX+b]=aE[X]+bE[aX+b]=aE[X]+b; Var⁡(aX+b)=a2Var⁡X\operatorname{Var}(aX+b)=a^2\operatorname{Var}X; independent variances add.
  • Distributions: Bernoulli, binomial (npnp, np(1−p)np(1-p)), uniform, exponential (mean 1/λ1/\lambda, memoryless), normal.
  • Markov P(X≥a)≤E[X]/aP(X\ge a)\le E[X]/a; Chebyshev P(∣X−μ∣≥kσ)≤1/k2P(|X-\mu|\ge k\sigma)\le1/k^2; WLLN: averages converge; CLT: averages are approximately normal with variance σ2/n\sigma^2/n.
Formulas to keep
  • P(A∣B)=P(A∩B)P(B)P(A\mid B)=\frac{P(A\cap B)}{P(B)}; Bayes P(A∣B)=P(B∣A)P(A)P(B)P(A\mid B)=\frac{P(B\mid A)P(A)}{P(B)}
  • Var⁡X=E[X2]−(E[X])2\operatorname{Var}X=E[X^2]-(E[X])^2; Cov⁡(X,Y)=E[XY]−E[X]E[Y]\operatorname{Cov}(X,Y)=E[XY]-E[X]E[Y]
  • Binomial: npnp, np(1−p)np(1-p); Uniform: a+b2\frac{a+b}2, (b−a)212\frac{(b-a)^2}{12}; Exponential: 1λ\frac1\lambda, 1λ2\frac1{\lambda^2}, P(X>t)=e−λtP(X>t)=e^{-\lambda t}
  • aX+b∼N(aμ+b,a2σ2)aX+b\sim N(a\mu+b,a^2\sigma^2); independent sum: means and variances add
  • Markov: P(X≥a)≤E[X]/aP(X\ge a)\le E[X]/a; Chebyshev: P(∣X−μ∣≥kσ)≤1/k2P(|X-\mu|\ge k\sigma)\le1/k^2
  • Sample mean: E=μE=\mu, Var⁡=σ2/n\operatorname{Var}=\sigma^2/n; WLLN: P(∣Xˉn−μ∣≥ε)≤σ2nε2P(|\bar X_n-\mu|\ge\varepsilon)\le\frac{\sigma^2}{n\varepsilon^2}
Connected weeks (learn them together)

Practise with real exam questions

These come straight from past papers (with the real figures and the official answer key). Open 45 real questions on this week   All End Term papers