A streaming service checks how well a user's recommendation list matches their taste. The user's viewing history p splits drama / comedy / documentary as 0.5 / 0.3 / 0.2, and the recommended list q splits them as 0.8 / 0.2 / 0.0. Using natural logs, what are KL(p‖q) and KL(q‖p), and what follows?
Show the answer and explanation
Correct answer: B, KL(p‖q) is infinite, because the list gives documentaries zero share where the user has 0.2, while KL(q‖p) ≈ 0.29 nats; Jensen–Shannon is a bounded, symmetric option.
Explanation Information Theory
KL(p‖q) = Σ p(x)·ln[p(x)/q(x)] is the expected extra log-loss from using q where the data follow p. It is ≥ 0, equals 0 only when p = q, and is not symmetric.
- KL(p‖q): the documentary term is 0.2 · ln(0.2/0) = +∞. Whenever q puts zero mass where p has mass, KL(p‖q) is infinite: the list completely ignores a genre the user watches.
- KL(q‖p) = 0.8·ln(0.8/0.5) + 0.2·ln(0.2/0.3) + 0·ln(0/0.2) = 0.3760 − 0.0811 + 0 = 0.2949 ≈ 0.29 nats. The convention 0·log 0 = 0 applies when the first argument is zero, so this direction stays finite.
Why the distractors fail: KL is not a distance (no symmetry, no triangle inequality), so the two directions differ. The zero-share problem is direction-specific, so KL is not infinite both ways. Reversing the arguments does give a finite number, but it asks a different question: in KL(q‖p) the missing genre contributes exactly 0, so the metric no longer punishes a list that ignores documentaries.
Jensen–Shannon compares both distributions with their mixture m = (p + q)/2: JS(p, q) = ½·KL(p‖m) + ½·KL(q‖m). Because m > 0 wherever either distribution has mass, JS is always finite, symmetric and at most ln 2 ≈ 0.693 nats (1 bit). Here m = (0.65, 0.25, 0.10) and JS ≈ 0.092 nats. Calibrated-recommendation methods take another route: they keep KL(p‖q̃) but smooth the list as q̃ = (1 − α)·q + α·p with a small α such as 0.01.
Interview tip: always state the direction and the log base when you report KL. For monitoring or similarity scores, prefer a bounded, symmetric measure such as Jensen–Shannon (its square root is a true metric), and handle zero counts explicitly with smoothing instead of silently dropping terms.