Intuition The Running Total Perspective
Imagine you're at a shooting range measuring where bullets land. A probability density tells you the density of hits at each distance. But what if you want to know: "What fraction of all shots landed at or before 50 meters?"
That's exactly what the Cumulative Distribution Function (CDF) gives you: the probability that a random variable is≤ some value . It's the running total of probability as you sweep from left to right across all possible outcomes.
Why does this matter in ML? CDFs are the backbone of understanding distributions, computing percentiles (e.g., "95% of predictions fall below this threshold"), generating random samples, and building probabilistic models.
Definition CDF — Formal Definition
For a random variable X X X , the cumulative distribution function F X ( x ) F_X(x) F X ( x ) is defined as:
F X ( x ) = P ( X ≤ x ) F_X(x) = P(X \leq x) F X ( x ) = P ( X ≤ x )
This is the probability that the random variable X X X takes a value less than or equal to x x x .
Domain: x ∈ R x \in \mathbb{R} x ∈ R (all real numbers)
Range: F X ( x ) ∈ [ 0 , 1 ] F_X(x) \in [0, 1] F X ( x ) ∈ [ 0 , 1 ] (probabilities)
Key properties that every CDF must satisfy:
Monotonically non-decreasing: If x 1 < x 2 x_1 < x_2 x 1 < x 2 , then F X ( x 1 ) ≤ F X ( x 2 ) F_X(x_1) \leq F_X(x_2) F X ( x 1 ) ≤ F X ( x 2 )
Limits: lim x → − ∞ F X ( x ) = 0 \lim_{x \to -\infty} F_X(x) = 0 lim x → − ∞ F X ( x ) = 0 and lim x → ∞ F X ( x ) = 1 \lim_{x \to \infty} F_X(x) = 1 lim x → ∞ F X ( x ) = 1
Right-continuous: lim h → 0 + F X ( x + h ) = F X ( x ) \lim_{h \to 0^+} F_X(x+h) = F_X(x) lim h → 0 + F X ( x + h ) = F X ( x )
Start with the PMF: Suppose we have a discrete random variable X X X with probability mass function p X ( x ) = P ( X = x ) p_X(x) = P(X = x) p X ( x ) = P ( X = x ) .
Step 1 — What does P ( X ≤ x ) P(X \leq x) P ( X ≤ x ) mean?
We want the total probability of all outcomes up to and including x x x . Since probabilities of disjoint events add:
F X ( x ) = P ( X ≤ x ) = ∑ x i ≤ x p X ( x i ) F_X(x) = P(X \leq x) = \sum_{x_i \leq x} p_X(x_i) F X ( x ) = P ( X ≤ x ) = ∑ x i ≤ x p X ( x i )
Why this step? We're accumulating individual point probabilities. Each value x i x_i x i that's ≤ x \leq x ≤ x contributes its probability mass.
Worked example Discrete CDF — Fair Die Roll
Let X X X be the outcome of rolling a fair six-sided die. The PMF is p X ( k ) = 1 6 p_X(k) = \frac{1}{6} p X ( k ) = 6 1 for k ∈ { 1 , 2 , 3 , 4 , 5 , 6 } k \in \{1,2,3,4,5,6\} k ∈ { 1 , 2 , 3 , 4 , 5 , 6 } .
Find: F X ( 3.7 ) F_X(3.7) F X ( 3.7 ) — probability of rolling 3.7 or less.
Solution:
F X ( 3.7 ) = P ( X ≤ 3.7 ) = P ( X = 1 ) + P ( X = 2 ) + P ( X = 3 ) F_X(3.7) = P(X \leq 3.7) = P(X=1) + P(X=2) + P(X=3) F X ( 3.7 ) = P ( X ≤ 3.7 ) = P ( X = 1 ) + P ( X = 2 ) + P ( X = 3 )
= 1 6 + 1 6 + 1 6 = 3 6 = 0.5 = \frac{1}{6} + \frac{1}{6} + \frac{1}{6} = \frac{3}{6} = 0.5 = 6 1 + 6 1 + 6 1 = 6 3 = 0.5
Why this step? Only discrete values 1, 2, 3 are ≤ 3.7. The die can't land on 3.7 itself
The full CDF looks like a staircase:
F X ( x ) = { 0 x < 1 k 6 k ≤ x < k + 1 , k ∈ { 1 , … , 5 } 1 x ≥ 6 F_X(x) = \begin{cases} 0 & x < 1 \\ \frac{k}{6} & k \leq x < k+1, \; k \in \{1,\ldots,5\} \\ 1 & x \geq 6 \end{cases} F X ( x ) = ⎩ ⎨ ⎧ 0 6 k 1 x < 1 k ≤ x < k + 1 , k ∈ { 1 , … , 5 } x ≥ 6
Start with the PDF: For continuous X X X with probability density function f X ( x ) f_X(x) f X ( x ) , probabilities are areas under the curve.
Step 1 — Probability as an integral:
Since P ( a < X ≤ b ) = ∫ a b f X ( x ) d x P(a < X \leq b) = \int_a^b f_X(x)\,dx P ( a < X ≤ b ) = ∫ a b f X ( x ) d x , the cumulative probability from − ∞ -\infty − ∞ to x x x is:
F X ( x ) = P ( X ≤ x ) = ∫ − ∞ x f X ( t ) d t F_X(x) = P(X \leq x) = \int_{-\infty}^{x} f_X(t)\,dt F X ( x ) = P ( X ≤ x ) = ∫ − ∞ x f X ( t ) d t
Why this step? We're integrating (accumulating) all the infinitesimal probability "slices" f X ( t ) d t f_X(t)\,dt f X ( t ) d t from the far left up to point x x x .
Step 2 — Recovering the PDF from the CDF:
By the Fundamental Theorem of Calculus:
f X ( x ) = d d x F X ( x ) f_X(x) = \frac{d}{dx} F_X(x) f X ( x ) = d x d F X ( x )
Why this relationship? The PDF is the rate of change of cumulative probability. The CDF is the antiderivative.
Worked example Continuous CDF — Uniform Distribution
Let X ∼ Uniform ( 0 , 1 ) X \sim \text{Uniform}(0, 1) X ∼ Uniform ( 0 , 1 ) , meaning X X X is equally likely to be anywhere in [ 0 , 1 ] [0,1] [ 0 , 1 ] .
The PDF is:
f X ( x ) = { 1 0 ≤ x ≤ 1 0 otherwise f_X(x) = \begin{cases} 1 & 0 \leq x \leq 1 \\ 0 & \text{otherwise} \end{cases} f X ( x ) = { 1 0 0 ≤ x ≤ 1 otherwise
Derive the CDF:
For x < 0 x< 0 x < 0 : No probability accumulated yet.
F X ( x ) = ∫ − ∞ x 0 d t = 0 F_X(x) = \int_{-\infty}^{x} 0\,dt = 0 F X ( x ) = ∫ − ∞ x 0 d t = 0
For 0 ≤ x ≤ 1 0 \leq x \leq 1 0 ≤ x ≤ 1 : Integrating the constant density.
F X ( x ) = ∫ − ∞ 0 0 d t + ∫ 0 x 1 d t = 0 + [ t ] 0 x = x F_X(x) = \int_{-\infty}^{0} 0\,dt + \int_{0}^{x} 1\,dt = 0 + [t]_0^x = x F X ( x ) = ∫ − ∞ 0 0 d t + ∫ 0 x 1 d t = 0 + [ t ] 0 x = x
Why this step? The area under a rectangle of height1 from 0 to x x x is just x x x .
For x > 1 x > 1 x > 1 : All probability accumulated.
F X ( x ) = ∫ − ∞ 1 f X ( t ) d t = 1 F_X(x) = \int_{-\infty}^{1} f_X(t)\,dt = 1 F X ( x ) = ∫ − ∞ 1 f X ( t ) d t = 1
Final CDF:
F X ( x ) = { 0 x < 0 x 0 ≤ x ≤ 1 1 x > 1 F_X(x) = \begin{cases} 0 & x < 0 \\ x & 0 \leq x \leq 1 \\ 1 & x > 1 \end{cases} F X ( x ) = ⎩ ⎨ ⎧ 0 x 1 x < 0 0 ≤ x ≤ 1 x > 1
This is a ramp function — linearly increasing from 0 to 1.
Worked example Interval Probability — Exponential Distribution
Suppose X ∼ Exp ( λ ) X \sim \text{Exp}(\lambda) X ∼ Exp ( λ ) with CDF:
F X ( x ) = { 1 − e − λ x x ≥ 0 0 x < 0 F_X(x) = \begin{cases} 1 - e^{-\lambda x} & x \geq 0 \\ 0 & x < 0 \end{cases} F X ( x ) = { 1 − e − λ x 0 x ≥ 0 x < 0
Find: P ( 1 < X ≤ 3 ) P(1 < X \leq 3) P ( 1 < X ≤ 3 ) when λ = 0.5 \lambda = 0.5 λ = 0.5 .
Solution:
P ( 1 < X ≤ 3 ) = F X ( 3 ) − F X ( 1 ) P(1 < X \leq 3) = F_X(3) - F_X(1) P ( 1 < X ≤ 3 ) = F X ( 3 ) − F X ( 1 )
= ( 1 − e − 0.5 ⋅ 3 ) − ( 1 − e − 0.5 ⋅ 1 ) = (1 - e^{-0.5 \cdot 3}) - (1 - e^{-0.5 \cdot 1}) = ( 1 − e − 0.5 ⋅ 3 ) − ( 1 − e − 0.5 ⋅ 1 )
= ( 1 − e − 1.5 ) − ( 1 − e − 0.5 ) = (1 - e^{-1.5}) - (1 - e^{-0.5}) = ( 1 − e − 1.5 ) − ( 1 − e − 0.5 )
= e − 0.5 − e − 1.5 = e^{-0.5} - e^{-1.5} = e − 0.5 − e − 1.5
= 0.6065 − 0.231 = 0.3834 = 0.6065 - 0.231 = 0.3834 = 0.6065 − 0.231 = 0.3834
Why this step? The CDF differences automatically give us the "probability mass" in the interval.
Why do we care in ML?
Confidence intervals: "95% of predictions fall below this threshold"
Random sampling: Generate samples via X = F − 1 ( U ) X = F^{-1}(U) X = F − 1 ( U ) where U ∼ Uniform ( 0 , 1 ) U \sim \text{Uniform}(0,1) U ∼ Uniform ( 0 , 1 )
Outlier detection: Flag data points beyond the 99th percentile
Worked example Finding the Median — Exponential Distribution
For X ∼ Exp ( λ ) X \sim \text{Exp}(\lambda) X ∼ Exp ( λ ) with F X ( x ) = 1 − e − λ x F_X(x) = 1 - e^{-\lambda x} F X ( x ) = 1 − e − λ x , find the median.
Setup: We want x x x such that F X ( x ) = 0.5 F_X(x) = 0.5 F X ( x ) = 0.5 .
1 − e − λ x = 0.5 1 - e^{-\lambda x} = 0.5 1 − e − λ x = 0.5
e − λ x = 0.5 e^{-\lambda x} = 0.5 e − λ x = 0.5
− λ x = ln ( 0.5 ) = − ln ( 2 ) -\lambda x = \ln(0.5) = -\ln(2) − λ x = ln ( 0.5 ) = − ln ( 2 )
x = ln ( 2 ) λ x = \frac{\ln(2)}{\lambda} x = λ l n ( 2 )
Why this step? We inverted the CDF algebraically. For λ = 1 \lambda = 1 λ = 1 , the median is ln ( 2 ) ≈ 0.693 \ln(2) \approx 0.693 ln ( 2 ) ≈ 0.693 , meaning half of exponentially-distributed events occur before time0.693.
Common mistake Common Mistake — Confusing PDF and CDF
Wrong idea: "The CDF at x x x tells me how likely x x x is."
Why it feels right: Both are functions of x x x describing the distribution.
The fix:
PDF f X ( x ) f_X(x) f X ( x ) : probability density at x x x (height of the curve). Can be > 1!
CDF F X ( x ) F_X(x) F X ( x ) : cumulative probability up to x x x (area to the left). Always in [ 0 , 1 ] [0, 1] [ 0 , 1 ] .
For continuous variables, P ( X = x ) = 0 P(X = x) = 0 P ( X = x ) = 0 always. The PDF gives relative likelihood, not absolute probability.
Common mistake Common Mistake — Forgetting CDF is Non-Decreasing
Wrong calculation: Computing F X ( 5 ) − F X ( 8 ) = − 0.2 F_X(5) - F_X(8) = -0.2 F X ( 5 ) − F X ( 8 ) = − 0.2 and thinking this is a probability.
Why it feels wrong: You get a negative number for a probability.
The fix: Probabilities are always non-negative. The CDF is monotonically non-decreasing, so:
F X ( a ) ≤ F X ( b ) whenever a < b F_X(a) \leq F_X(b) \text{ whenever } a < b F X ( a ) ≤ F X ( b ) whenever a < b
To find P ( 5 < X ≤ 8 ) P(5 < X \leq 8) P ( 5 < X ≤ 8 ) , you must do F X ( 8 ) − F X ( 5 ) F_X(8) - F_X(5) F X ( 8 ) − F X ( 5 ) , not the reverse.
Model Evaluation:
Computing prediction intervals: P ( y pred ∈ [ a , b ] ) P(y_{\text{pred}} \in [a, b]) P ( y pred ∈ [ a , b ])
Calibration curves compare predicted CDF to empirical CDF
Data Preprocessing:
Quantile normalization : map data to uniform distribution via CDF
Outlier detection: flag points where F X ( x ) > 0.99 F_X(x) > 0.99 F X ( x ) > 0.99 or < 0.01 < 0.01 < 0.01
Generative Models:
Inverse transform sampling: Generate samples from any distribution using uniform random numbers
Copulas: Model joint distributions by combining marginal CDFs
Statistical Tests:
Kolmogorov-Smirnov test compares empirical CDF to theoretical CDF
p-values are tail probabilities: p = 1 − F null ( t obs ) p =1 - F_{\text{null}}(t_{\text{obs}}) p = 1 − F null ( t obs )
Recall Explain to a 12-Year-Old
Imagine you're collecting Pokémon cards, and you track how rare each card is.
The probability density is like a bar chart showing how common each card level is. A CDF is different — it answers: "If I pick a random card, what's the chance it's this rare or less ?"
Picture walking through the cards from least rare to most rare, and keeping running count of "How many have I seen so far?" That running percentage is the CDF.
When you reach the end (the rarest card), your CDF hits 100% because you've counted all the cards.
Why is this useful? If someone asks "What's the chance I pull a card that's in the bottom 75%?", you just look at the CDF at the 75% mark. No complicated addition needed!
Mnemonic CDF = "Cumulative = Collect Everything Below"
C umulative → C ollect
D istribution → D istance traveled from − ∞ -\infty − ∞
F unction → F raction accumulated
Think: "The CDF is the C ollected F raction D one by point x x x ."
Visual mnemonic: The CDF curve always climbs upward (or stays flat) like climbing stairs — you never go down because you're always adding more probability.
Probability Distributions — CDF is the integral of the PDF
Random Variables — CDF is defined for any random variable
Expected Value and Variance — Can compute E [ X ] E[X] E [ X ] using CDF
Inverse Transform Sampling — Uses F − 1 F^{-1} F − 1 to generate random samples
Quantile Functions — The inverse of the CDF
Empirical Distribution — Sample-based estimate of the CDF
Kolmogorov-Smirnov Test — Compares CDFs for goodness-of-fit
Copulas — Join marginal CDFs to model dependence
Survival Analysis — Uses survival function S ( x ) = 1 − F X ( x ) S(x) = 1 - F_X(x) S ( x ) = 1 − F X ( x )
#flashcards/ai-ml
What does the CDF F X ( x ) F_X(x) F X ( x ) represent? :: The probability that random variable X X X is less than or equal to x x x : F X ( x ) = P ( X ≤ x ) F_X(x) = P(X \leq x) F X ( x ) = P ( X ≤ x )
What are the range and domain of a CDF? Domain: all real numbers
R \mathbb{R} R . Range:
[ 0 , 1 ] [0, 1] [ 0 , 1 ] (probabilities).
True or False: A CDF can decrease as x x x increases. False. CDFs are monotonically non-decreasing.
How do you compute P ( a < X ≤ b ) P(a < X \leq b) P ( a < X ≤ b ) using the CDF? P ( a < X ≤ b ) = F X ( b ) − F X ( a ) P(a < X \leq b) = F_X(b) - F_X(a) P ( a < X ≤ b ) = F X ( b ) − F X ( a )
For a continuous random variable, what is the relationship between PDF and CDF? F X ( x ) = ∫ − ∞ x f X ( t ) d t F_X(x) = \int_{-\infty}^{x} f_X(t)\,dt F X ( x ) = ∫ − ∞ x f X ( t ) d t and
f X ( x ) = d d x F X ( x ) f_X(x) = \frac{d}{dx} F_X(x) f X ( x ) = d x d F X ( x )
For a discrete random variable, how is the CDF computed from the PMF? F X ( x ) = ∑ x i ≤ x p X ( x i ) F_X(x) = \sum_{x_i \leq x} p_X(x_i) F X ( x ) = ∑ x i ≤ x p X ( x i ) (sum all probabilities of outcomes
≤ x \leq x ≤ x )
What is the quantile function? The inverse CDF
F X − 1 ( p ) F_X^{-1}(p) F X − 1 ( p ) , which gives the value
x x x such that
F X ( x ) = p F_X(x) = p F X ( x ) = p .
What is F X − 1 ( 0.5 ) F_X^{-1}(0.5) F X − 1 ( 0.5 ) called? The median of the distribution.
What is P ( X = x ) P(X = x) P ( X = x ) for a continuous random variable? Zero. For continuous variables,
P ( X = x ) = 0 P(X = x) = 0 P ( X = x ) = 0 .
How do you compute P ( X > x ) P(X > x) P ( X > x ) using the CDF? P ( X > x ) = 1 − F X ( x ) P(X > x) = 1 - F_X(x) P ( X > x ) = 1 − F X ( x )
What are the limit properties of a CDF? lim x → − ∞ F X ( x ) = 0 \lim_{x \to -\infty} F_X(x) = 0 lim x → − ∞ F X ( x ) = 0 and
lim x → ∞ F X ( x ) = 1 \lim_{x \to \infty} F_X(x) = 1 lim x → ∞ F X ( x ) = 1
For X ∼ Uniform ( 0 , 1 ) X \sim \text{Uniform}(0,1) X ∼ Uniform ( 0 , 1 ) , what is F X ( 0.3 ) F_X(0.3) F X ( 0.3 ) ? F X ( 0.3 ) = 0.3 F_X(0.3) = 0.3 F X ( 0.3 ) = 0.3 (the CDF is
F X ( x ) = x F_X(x) = x F X ( x ) = x for
x ∈ [ 0 , 1 ] x \in [0,1] x ∈ [ 0 , 1 ] )
What shape does a discrete CDF have? A staircase (step function) with jumps at each possible value.
How is inverse transform sampling performed? Generate
U ∼ Uniform ( 0 , 1 ) U \sim \text{Uniform}(0,1) U ∼ Uniform ( 0 , 1 ) , then compute
X = F X − 1 ( U ) X = F_X^{-1}(U) X = F X − 1 ( U ) .
What does the95th percentile mean? The value
x x x such that 95% of the distribution is
≤ x \leq x ≤ x , i.e.,
F X ( x ) = 0.95 F_X(x) = 0.95 F X ( x ) = 0.95 .
Percentiles and thresholds
Intuition Hinglish mein samjho
Intuition Hinglish mein samjho
Dekho, CDF ka core idea bahut simple hai — ye ek "running total" hai probability ka. Socho tum shooting range pe ho aur poochte ho ki "kitne percent bullets 50 meters ke andar giri?" Toh yahan tum ek specific point tak ki saari probability jod rahe ho. Formally, F X ( x ) = P ( X ≤ x ) F_X(x) = P(X \leq x) F X ( x ) = P ( X ≤ x ) , matlab random variable x x x ya usse chhoti value lene ka chance kitna hai. Left se right ko sweep karte jao aur probability accumulate hoti jati hai — isliye ye hamesha 0 se start hoke 1 par khatam hoti hai, aur beech mein kabhi ghatti nahi (monotonically non-decreasing).
Ab discrete aur continuous case ka fark samajh lo. Discrete case mein — jaise dice roll — tum bas alag-alag point probabilities ko jodte ho, isliye CDF ek "staircase" jaisi dikhti hai, har value pe ek step jump. Continuous case mein — jaise Uniform distribution — probability area hoti hai curve ke neeche, toh tum integrate karte ho PDF ko − ∞ -\infty − ∞ se lekar x x x tak. Aur ek khoobsurat baat: agar tum CDF ka derivative lo, toh wapas PDF mil jati hai (Fundamental Theorem of Calculus). Matlab PDF cumulative probability ki rate of change hai, aur CDF uska antiderivative — dono ek dusre se connected hain.
Ye cheez ML mein kyun important hai? Kyunki CDF se tum percentiles nikaal sakte ho — jaise "95% predictions is threshold ke neeche aati hain", ya confidence intervals banate ho. Random sampling generate karne mein bhi CDF ka inverse use hota hai (inverse transform sampling), aur probabilistic models samajhne ka backbone yahi hai. Toh jab bhi tumhe distribution ke baare mein "kitna tak" wale sawaal aaye, CDF hi tumhara tool hai. Isko achhe se pakad lo — aage har jagah kaam aayega.