Joint Distributions & Independence
Joint PDF/PMF, marginals, conditional distributions, covariance
You are building a credit scoring model. Two features: age (continuous) and missed_payments (count, discrete). You want to know P(age > 30, missed_payments ≥ 2). These variables are not independent — older borrowers tend to have longer credit histories and different payment patterns. You cannot multiply P(age > 30) × P(missed_payments ≥ 2) and get the right answer. You need the joint distribution P(age, missed_payments).
Joint distribution P(X, Y): for discrete variables, a 2D table of probabilities summing to 1. For continuous variables, a 2D density f(x, y) integrating to 1. Marginal distribution: integrate or sum out the other variable. P(X = x) = Σ_y P(X = x, Y = y). Conditional distribution: P(Y = y | X = x) = P(X = x, Y = y) / P(X = x). This is the Bayes denominator — the mechanism behind every probabilistic classifier.
Independence: X and Y are independent if and only if P(X, Y) = P(X) × P(Y) for all values. In ML, Naive Bayes assumes all features are conditionally independent given the label. This is almost always false, but the classification decisions can still be correct even when the probability estimates are wrong — independence of errors in different directions can cancel.
Covariance: Cov(X, Y) = E[(X - μ_X)(Y - μ_Y)] = E[XY] - E[X]E[Y]. Positive covariance means the variables tend to move together. Negative means they move oppositely. Zero means no linear relationship — NOT the same as independence. Correlation: ρ = Cov(X, Y) / (σ_X · σ_Y). Bounded in [-1, 1]. For jointly Gaussian variables, zero correlation implies independence — for any other distribution, it doesn't, as the next paragraph shows.
NOT this. Correlation = 0 does not mean the variables are independent. This is only true for jointly Gaussian random variables. For any other distribution, zero linear correlation is compatible with strong nonlinear dependence. Let X ~ Uniform(-1, 1) and Y = X². Then Cov(X, Y) = 0 by symmetry, but Y is completely determined by X — perfect deterministic dependence. Mutual information captures any dependence; correlation captures only linear dependence.
Key points
- Always compute the joint distribution (or its sample estimate) before assuming independence. A quick scatter plot or correlation matrix is a fast first check, but it only catches linear relationships — nonlinear dependence needs mutual information or a rank-based test. Ignoring dependence leads to probability estimates that are systematically wrong — the Naive Bayes independence violation is not a theoretical concern, it produces miscalibrated probabilities that cannot be used for risk-sensitive decisions.
- Trap: treating conditional probabilities as symmetric. P(fraud | transaction > $10K) ≠ P(transaction > $10K | fraud). Getting the conditioning direction wrong produces confident wrong answers. The base rate of each event determines which direction of conditioning gives useful information. Draw the causal structure first, then condition.
- Diagnostic: if a model's predicted probabilities are miscalibrated — predicted 0.8 but true frequency is 0.4 — check whether correlated features are creating double-counting of information. This is the Naive Bayes independence violation made explicit. When two features carry the same signal (high correlation), treating them as independent doubles the effective evidence, pushing predictions toward the extremes.
Zero correlation rules out linear dependence only. Two variables can have ρ = 0 while one is a deterministic function of the other. If you need to test actual independence — not just linear independence — use mutual information or a rank-based test.
Recap
- Joint P(X,Y) is required when features are dependent — can't multiply P(X)×P(Y) unless independent.
- Marginal = sum/integrate out the other variable; conditional $P(Y|X)=P(X,Y)/P(X)$ is the Bayes denominator.
- Independence ⟺ P(X,Y)=P(X)P(Y) for all values. Naive Bayes assumes this — usually false.
- Cov(X,Y)=E[XY]−E[X]E[Y]; ρ = Cov/(σ_X σ_Y) ∈ [−1,1]. Captures linear relationship only.
- Zero correlation ≠ independence: X~Uniform(−1,1), Y=X² has Cov=0 but Y fully determined by X.
- Correlated features double-count evidence in Naive Bayes → miscalibrated, over-confident probabilities.
- For real independence use mutual information or a rank test, not Pearson correlation.
Check your understanding
Q1. X and Y have joint PDF f(x,y) = 6x for 0 ≤ x ≤ y ≤ 1. Find the marginal PDFs and check if X and Y are independent.
- A) Marginal of X: f_X(x) = ∫_0^x 6x dy = 6x² for 0≤x≤1. Marginal of Y: f_Y(y) = ∫_0^1 6x dx = 3 for 0≤y≤1. Check: f_X(x)·f_Y(y) = 18x² ≠ 6x, so X and Y are NOT independent — note the marginal of X was integrated over [0,x] instead of [x,1], even though the support requires x ≤ y.
- B) Marginal of X: f_X(x) = ∫_x^1 6x dy = 6x(1−x) for 0≤x≤1. Marginal of Y: f_Y(y) = ∫_0^y 6x dx = 3y² for 0≤y≤1. Check: f_X(x)·f_Y(y) = 18xy²(1−x) ≠ 6x = f(x,y), so X and Y are NOT independent — the constraint x ≤ y means knowing Y=y restricts X to [0,y], changing X's conditional distribution.
- C) Marginal of X: f_X(x) = ∫_x^1 6x dy = 6x(1−x). Marginal of Y: f_Y(y) = ∫_0^1 6x dx = 3 for 0≤y≤1. Since f_X(x)·f_Y(y) = 18x(1−x) ≠ 6x = f(x,y), X and Y are NOT independent. The constraint x ≤ y in the joint support alone guarantees this dependence, regardless of the specific density values.
- D) Marginal of X: f_X(x) = 6x(1−x). Marginal of Y: f_Y(y) = 3y². Product f_X(x)·f_Y(y) = 18xy²(1−x). Since this equals 6x only on the measure-zero set (1−x)·3y²=1, X and Y are independent almost everywhere — the divergence occurs on a null set that shouldn't count against independence for practical modeling purposes.
Q2. Cov(X,Y) = 0 implies X and Y are independent: true or false? Which TWO of the following options give a correct verdict with a valid counterexample?
- A) False. Zero covariance does not imply independence — only linear decorrelation. Counterexample: X ~ Uniform(−1,1), Y = X². Cov(X,Y) = E[X³] − 0 = 0 since X is symmetric (odd moments vanish). But Y is fully determined by X — perfect nonlinear dependence with zero covariance. Independence ⟹ zero covariance, not the reverse in general.
- B) True. Zero covariance is the standard definition of independence for continuous random variables. The only exception is discrete distributions with finite support, where the covariance can be zero while some higher-order dependence remains. For continuous distributions, Cov(X,Y) = 0 ⟺ independence.
- C) False. Counterexample: X ~ N(0,1) and Y = |X|. Cov(X,Y) = E[X|X|] = 0 by symmetry, since x|x| is an odd function integrated against a symmetric density. But Y is not independent of X, since Y = |X| is a deterministic function of X. Zero covariance is only guaranteed to imply independence when X and Y are jointly Gaussian.
- D) True for jointly Gaussian variables, but also true whenever X has finite support — with finitely many values to check, zero covariance is claimed to be enough to rule out dependence. Example: X ~ Bernoulli(0.5) taking values ±1, Y = X². Cov(X,Y) = E[X³] − E[X]E[X²] = 0 − 0 = 0, so by this (flawed) reasoning X and Y must be independent.
Q3. You compute P(missed_payments ≥ 2 | age > 30) = P(age > 30, missed_payments ≥ 2) / P(age > 30) = 0.15 from the joint distribution. A colleague claims this number also tells you P(age > 30 | missed_payments ≥ 2). Is the colleague right?
- A) Yes — conditional probabilities are symmetric. Since both are computed from the same joint probability P(age > 30, missed_payments ≥ 2), dividing by either marginal gives numbers that mean the same thing.
- B) No. P(age > 30 | missed_payments ≥ 2) = P(age > 30, missed_payments ≥ 2) / P(missed_payments ≥ 2) — the same joint-probability numerator, but divided by a different marginal (the marginal of missed_payments ≥ 2, not of age > 30). Without that second marginal, the two conditionals cannot be assumed equal.
- C) No, because P(age > 30 | missed_payments ≥ 2) only exists if age and missed_payments are independent, and this dataset shows they are dependent, so the conditional probability is undefined here.
- D) Yes, because dividing the same joint probability by any marginal produces equivalent conditional probabilities up to a constant scaling factor that cancels out when comparing the two directions.
Try it interactively
ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.
Open ML Systems Lab →