ML Systems Lab Open interactive version →
Foundational 26 min read joint distributionscovariancecorrelation

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

Takeaway

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

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.

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?

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?

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 →