Kullback-Leibler divergence Created 2026-09-24 Updated 2026-10-14
The Kullback-Leibler divergence, also called relative entropy, compares two probability distributions in a specified order. In , observations follow and the comparison probability distribution is : the first argument supplies the averaging weights. For probability mass functions on a finite alphabet,Here is a random variable with probability distribution . For probability density functions relative to the same measure , replace the sum by . These formulas use natural logarithms unless stated otherwise. The expected value is under , even though appears in the denominator. [ref]
Take and on two outcomes. Direct calculation givesThe second outcome contributes negatively to the first sum: assigning it more probability than does makes its individual contribution negative. Nevertheless, relative entropy nonnegativity guarantees a nonnegative total. Reversing the arguments changes both the likelihood ratio and the averaging probabilities; taking an absolute value inside the logarithm would define a different quantity.
The units depend on the logarithm: natural logarithms give nats, whereas base-two logarithms give bits. Divide a value in nats by to obtain bits; the forward example is approximately bits. Changing the base rescales every Kullback-Leibler divergence by the same positive factor. Since the two calculated directions differ, Kullback-Leibler divergence is asymmetric and cannot be a metric. It also need not satisfy the triangle inequality. [ref]
https://web.stanford.edu/~kedart/ee376a_winter1617/Lecture_3.pdf. Tse, relative entropy, 2017, Section 3.3
The operational meaning is an expected penalty for using the wrong probability distribution. A prediction incurs log-loss when outcome occurs, the negative of the logarithmic scoring rule. Under , its expected value is the cross-entropy . Predicting with itself incurs information entropy , soThus Kullback-Leibler divergence is exactly excess expected log-loss, whenever these separate quantities are finite. [ref]
https://web.stanford.edu/class/ee276/files/previous_notes/lecture_2.pdf. Weissman, information measures, 2024, property 3
For lossless source coding, ideal codeword lengths similarly give excess expected length in bits per symbol. Actual prefix codes require integer codeword lengths; Shannon's source coding theorem explains how long blocks approach ideal per-symbol lengths. The interpretation concerns an average, not a fractional physical bit attached to every outcome. In our example, ideal coding with costs one bit per symbol, while bits; the difference is exactly the computed bits. [ref]
https://web.stanford.edu/~kedart/ee376a_winter1617/Lecture_3.pdf. Tse, information theory, 2017, Section 3.4
Zeros require explicit conventions. An outcome with contributes zero, including when ; the convention agrees with the relevant limit. If but , the Kullback-Leibler divergence is infinite: the predictor has declared impossible an outcome that can occur. On a finite alphabet, the probability support of must therefore be contained in the probability support of for a finite answer. For example, and give , but . For general probability measures, failure of absolute continuity of measures likewise gives infinity. Even does not guarantee a finite integral. [ref]
https://arxiv.org/pdf/1206.2459. van Erven and Harremoës, Rényi Divergence and Kullback-Leibler Divergence, 2014, Section II
To see how confidently wrong predictions are punished, hold the true Bernoulli distribution parameter at and vary the predicted parameter . Its binary relative entropy isIt vanishes at , equals approximately nats at , and equals nats at . Both endpoints give infinity because both outcomes remain possible under . Predicting almost no successes is especially costly because successes actually occur three quarters of the time. The reversed binary relative entropy stays finite at the endpoints: its averaging probability distribution concentrates on just one outcome, and assigns positive probability to both.
For model selection, minimizing expected log-loss ranks candidate statistical models by , since is common to them. The true probability distribution is usually unknown, so one estimates predictive performance using fresh observations or cross-validation. Fitting and assessing on the same data can reward overfitting; a small fitted Kullback-Leibler divergence alone does not establish useful prediction.
In variational inference, a tractable trial probability distribution commonly minimizes against a target posterior distribution . Maximizing the evidence lower bound accomplishes this without evaluating the target's normalization constant. The averaging now follows : placing trial probability where the posterior distribution assigns almost none is strongly penalized. The chosen direction and trial family therefore matter. [ref]
https://www.cs.columbia.edu/~blei/papers/BleiKucukelbirMcAuliffe2017.pdf. Blei, Kucukelbir and McAuliffe, Variational Inference: A Review for Statisticians, 2017, Section 2.2
These comparisons do not by themselves establish causal inference. Two statistical models can reproduce the same observed probability distribution while predicting different responses to an intervention. Choosing the smaller Kullback-Leibler divergence therefore needs additional assumptions or experimental evidence before supporting a causal claim. [ref]
https://ftp.cs.ucla.edu/pub/stat_ser/r350.pdf. Pearl, Causal inference in statistics: An overview, 2009, Section 2
The original reference is S. Kullback and R. A. Leibler's 1951 paper [ref]
https://doi.org/10.1214/aoms/1177729694. On Information and Sufficiency
, published in The Annals of Mathematical Statistics 22(1), pages 79–86. Its title connects this comparison with sufficient statistics: the historical setting was statistical information, before today's widespread applications in prediction and variational inference. Mixture identifiability 2026-10-14
Simultaneously applying a permutation to the mixture weights and mixture components leaves unchanged. Thus identifiability of named components requires a convention, such as ordering distinct component means; label switching describes the associated inferential issue.[ref]
Even after choosing label names, identical mixture components reveal only their combined mixture weight, and an inactive mixture component has undetermined statistical parameters. Adding mixture components increases flexibility but can cause overfitting; judge predictions using cross-validation, rather than interpreting every fitted component as a discovered population.[ref]
Mixture Models. §21.1.6, printed pp. 445-446: probabilistic clustering and evaluation on future data
Past exam of the mathematics course of the University of Cambridge 2005 iii Paper 46 3 Solution 2026-10-14
The formula makes species the categorical response and the dot denotes all four other columns as candidate predictors. The classification tree is grown by recursive binary partitioning, not by fitting a linear regression to numerical species codes. At a node , count observations of each class, , and set . These are the multinomial maximum-likelihood probabilities. The classification-tree deviance isFor each candidate predictor and threshold, calculate and choose the largest permitted decrease. Continue recursively until a node is pure or the stopping controls prevent another split, for example because it has too few observations or insufficient deviance to warrant further growth. Only petal length, petal width and sepal length appear in the selected splits; sepal width was available but did not win a split. This greedy construction need not find a globally optimal tree. The default deviance criterion and recursive partitioning are documented in the tree package manual.
Each node number encodes its position: node has left and right children and . The reported sample size is the number reaching the node; its deviance is calculated from that node's class counts. The fitted class is the class with largest fitted probability, with a convention resolving ties. The root's three counts are equal, so its displayed class is only a tie choice. An asterisk marks a terminal node, where prediction stops.
The resulting rule is displayed below. A left edge satisfies the stated strict inequality and a right edge its complement. None of the recorded training values lies exactly at these midpoint thresholds; the diagram adopts the right branch at equality for prediction.
Its six terminal regions have the following derived class counts, in the order setosa, versicolor, virginica:The root split identifies all 50 setosa observations. Among the remaining specimens, the petal-width split is the principal separation of versicolor from virginica; further petal-length and sepal-length splits refine it. The leaf errors add to . The leaf deviances add toDividing by the software's residual degrees-of-freedom convention gives , as reported. The root deviance is . The deviance is a likelihood measure, whereas the error rate counts wrong majority-class predictions; these are different fit summaries.
Both quantities are in-sample, so the low error does not establish prediction accuracy on new specimens. Cost-complexity tree pruning, with tree size chosen by cross-validation, can remove weak splits and reduce overfitting. An independent test set is needed for a final estimate of the selected tree's prediction error.
Past exam of the mathematics course of the University of Cambridge 2024 iii Paper 218 2 e Solution Created 2026-09-24 Updated 2026-09-25
Put , so and with independent noise vectors having covariance matrix . For any deterministic linear smoother ,whereas independence givesExpanding the first trace shows that the second expression exceeds the first by , proving the identity.
For ridge regression,Its effective degrees of freedom are . Thus training error is optimistically biased for independent-copy prediction error by . The graph exhibits exactly this effect: the dashed training curve keeps falling as decreases, while the solid test curve eventually rises through overfitting.
Past exam of the mathematics course of the University of Cambridge 2026 iii Paper 218 5 d Solution Created 2026-09-24 Updated 2026-09-25
The dashed curve is training accuracy: it continues to rise as optimization adapts to the training observations. The solid curve is testing accuracy: it peaks near 10 epochs and then declines. The widening gap is overfitting.
A sensible choice is about 10 epochs, selected by early stopping at the maximum validation accuracy. In a proper analysis, a validation set rather than the final test set should choose this epoch. Early stopping is an implicit regularization method because it limits how far the parameters can adapt to training-specific noise.
Test set Created 2026-09-28 Updated 2026-10-14
A test set is held out from both parameter fitting and model selection and is used to estimate the final selected procedure's prediction error. A validation set influences the choice; a test set assesses that choice after it is fixed. The distinction concerns how observations are used, not their file names.
For a fixed rule and an independent test set of size from the target probability distribution,This test error is an estimate, with sampling uncertainty; it is not a guarantee for each future prediction. Dataset shift changes what performance the estimate represents.
In the overfitting example, all degree choices are fixed in advance, cross-validation uses only training data, and the selected degree is locked before evaluating 400 separate points. Displaying the other curves afterward explains their behavior; it does not authorize selecting by those scores. Repeatedly inspecting a test set and changing the model makes it part of model selection, introducing data leakage and potentially optimistic assessment. [ref]
https://jmlr.org/papers/v11/cawley10a.html. Cawley and Talbot, over-fitting in model selection, 2010
Training error Created 2026-09-24 Updated 2026-10-14
Training error is the average loss function evaluated on the observations used to fit the prediction rule. It is the empirical risk of the fitted rule on its own training data. With squared-error loss, it is the average squared regression residual, measuring fit to observed responses rather than performance on fresh responses. Flexible fitting usually makes it optimistically biased for prediction error, as quantified by prediction optimism.
For a reproducible polynomial regression example, take , , and the known noiseless target . Construct responses with fixed disturbancesOrdinary least squares over polynomials of polynomial degree at most 1, 2, and 7 gives training errors , , and . The monotone improvement follows because these candidate families are nested: every smaller-degree fit remains available in the larger family. This argument concerns minimum training error, not generalization, and assumes the fitting mathematical optimization is solved. Degrees 2 and 7 fitted instead to the exact noiseless responses have mathematically zero training error; the script obtains approximately and from rounding. Extra flexibility alone does not force overfitting.


