Cross-validation Created 2026-09-24 Updated 2026-10-14
Cross-validation estimates predictive performance by repeatedly fitting on one part of the data and evaluating on held-out observations. In K-fold cross-validation, divide training data into disjoint folds ; identifies observation 's fold, and is fitted without fold . The displayed average scores each observation using a rule that did not train on it. Weight by observation count when fold sizes differ. Leave-one-out cross-validation uses one observation per fold. [ref]
https://web.stanford.edu/~hastie/ISLR2/Slides/Ch5_Resampling_Methods.pdf. ISLR chapter 5 slides, resampling methods
For the training error example, three folds contain indices with equal remainder modulo 3. Each fit uses eight observations. The squared-error loss averages for degrees 1, 2, and 7 are , , and respectively. Select degree 2 and refit on all twelve training data observations. The folds reuse scarce data while challenging each candidate to predict unseen responses; they do not touch the final test set.
Any learned preprocessing, including variable selection, must also be fitted within each training fold to avoid data leakage. [ref]
https://web.stanford.edu/~hastie/ISLR2/Slides/Ch5_Resampling_Methods.pdf. ISLR chapter 5 slides, the wrong and right way
Repeated tuning can itself overfit the cross-validation score; nested cross-validation uses inner folds for model selection and outer folds for assessment of that entire procedure. [ref]Folds use fewer training observations than the final refit, and their scores are dependent because training observations overlap. [ref]
https://web.stanford.edu/~hastie/ISLR2/Slides/Ch5_Resampling_Methods.pdf. ISLR chapter 5 slides, correlated fold estimates
Splitting must match deployment: for time series forecasting, rolling-origin cross-validation trains on the past and evaluates later observations, preventing future information from entering a forecast. Ordinary random folds need not answer that forecasting question. [ref] Generalized cross-validation Created 2026-10-06 Updated 2026-10-14
For a fixed linear smoother, generalized cross-validation replaces the individual leverage corrections of Leave-one-out cross-validation by their average. It selects smoothing parameters by minimizing the displayed criterion. It approximates a predictive error criterion; it is not a universal exact estimate of future error and requires care when observation errors are dependent.
Minimize the displayed criterion using a Leave-one-out cross-validation estimate in the second term. Its expectation is the exact mean integrated squared error minus , which does not depend on h. With standard smoothness and appropriate search ranges, the chosen bandwidth is asymptotically optimal. Its relative fluctuations are ordinarily of order , considerably larger than the estimation error achievable by well-chosen plug-in pilots.
Past exam of the mathematics course of the University of Cambridge 2007 iii Paper 43 5 d Solution Created 2026-10-03 Updated 2026-10-14
Let be the influence matrix, so . Its trace is the effective degrees of freedom, accounting for shrinkage of the fitted smooth rather than just counting basis coefficients. The generalised cross-validation score isFor a fixed smoothing parameter, the exact leave-one-out residual of this penalized linear fit is , obtained by removing its observation's contribution to the normal equations. Thus Leave-one-out cross-validation uses the average of their squared values. GCV replaces the individual leverages by their average . This avoids separate refits and gives a criterion balancing the small training residuals of a flexible fit against its larger complexity.
Evaluate the score across positive , or optimize it numerically, and choose minimizing GCV. Then refit or retain the spline at this value. In the full natural smoothing-spline family the trace decreases from towards as smoothing increases. The selected parameter is intended to give good prediction, rather than necessarily to pass through every point.
Past exam of the mathematics course of the University of Cambridge 2007 iii Paper 49 4 Solution Created 2026-10-03 Updated 2026-10-14
In kernel density estimation, take a kernel for density estimation that is nonnegative, symmetric, and has integral one, finite , and finite . Its smoothing bandwidth gives and the kernel density estimatorfrom an independent and identically distributed sample with probability density function . Nonnegativity and unit mass make the estimate itself a probability density function. We compare kernel for density estimation shapes by their optimized mean integrated squared error, rather than by their performance at an arbitrarily common numerical smoothing bandwidth.
For the usual second-order theory, assume, for example, that belongs to the Sobolev space and , and let , . The expectation is the convolution . The vanishing first moment of the symmetric kernel for density estimation and the integral Taylor remainder giveContinuity of translations in the L2 norm, with domination by , shows that in the L2 norm. Hence the integrated squared bias of a kernel density estimator isBy independence, the exact integrated variance of a kernel density estimator isIndeed the integrated second moment of a single summand is , and its integrated squared mean is . The latter quantity is bounded by , by Young's convolution inequality, so its contribution is . The bias-variance decomposition of mean squared error therefore yields the leading criterionThis asymptotic mean integrated squared error displays the bias-variance tradeoff: a small smoothing bandwidth increases integrated variance, while a large one increases squared bias of an estimator.
Differentiating the asymptotic mean integrated squared error with respect to gives . It changes sign once, from negative to positive, so its unique minimum isAt this minimum the integrated variance term is four times the squared bias of an estimator term. Substitution givesThus the leading rate is , and the shape comparison reduces to minimizing .
There is an essential scale ambiguity: if , then . Changing the scale of the kernel for density estimation merely changes the numerical convention for the smoothing bandwidth. MoreoverA comparison at the same raw is therefore not a fair comparison of shape. One can normalize the second moment to one, but that does not make the optimal smoothing bandwidth independent of shape.
The canonical kernel for density estimation instead chooses the unique scaleIt satisfies , and soConsequently all canonical kernels share the same leading optimal bandwidth . Only the multiplicative constant depends on shape. This is precisely the separation of shape choice and scale choice that makes the canonical kernel normalization useful. For an original unscaled kernel for density estimation, its corresponding optimal smoothing bandwidth is .
To prove optimal shape, scale a candidate kernel for density estimation to have second moment one. Let andDirect integration gives , , and . Thus is a rescaled Epanechnikov kernel. For any admissible with the same mass and second moment,Outside , and , because . The integral inside is therefore nonnegative, and multiplying by gives . Expanding the square now provesEquality forces almost everywhere. At fixed second moment, minimizing is equivalent to minimizing . Since is scale invariant, this proves the optimality of the Epanechnikov kernel over all nonnegative symmetric second-order kernels for density estimation, including the equality case up to rescaling.
In its usual scale, the optimal Epanechnikov kernel isIts canonical scale is , givingThe optimal Epanechnikov kernel shape is therefore a truncated parabola, rather than a particular support radius. The canonical kernel and unit-second-moment version represent the same shape but different scale conventions.
The numerical gains over other reasonable kernels for density estimation are modest. Define asymptotic relative efficiency against the optimal Epanechnikov kernel by the sample-size fraction giving the same optimized leading mean integrated squared error:For the Gaussian density kernel , and , so its efficiency is . For the uniform smoothing kernel , and , giving efficiency . The Gaussian density kernel is infinitely smooth, whereas the optimal Epanechnikov kernel has compact support and allows each observation to affect only a finite window. Such computational and smoothness considerations may outweigh a small leading-efficiency difference.
In practice is unknown. A plug-in estimator estimates this roughness functional from a pilot estimate of the second derivative and substitutes it into the optimal smoothing bandwidth formula. Alternatively, Leave-one-out cross-validation minimizeswhere uses the other observations. By independence, the expectation of the second term is , so . Thus it targets integrated error without knowing . The choice of smoothing bandwidth remains important: even for the optimal Epanechnikov kernel, setting multiplies the leading minimum error by .
The preceding optimum concerns nonnegative second-order kernels for density estimation and twice-smooth densities on the real line. Signed kernels of order ell can cancel higher moments for smoother densities and yield different rates, but may produce negative density estimates. A support boundary or a density jump also requires separate bias of a kernel density estimator analysis. These settings do not contradict the proved second-order optimality of the Epanechnikov kernel.
Past exam of the mathematics course of the University of Cambridge 2014 iii Paper 35 4 j Solution Created 2026-10-03 Updated 2026-10-06
Fit both the normal and Student t random-effect model with comparable proper prior distributions. Compare priors on the same spread measure: a normal distribution scale is a standard deviation, whereas the standard deviation is .
Use a posterior predictive check: draw study effects and binomial counts from each fitted hierarchy and compare replicated dispersion and extreme study contrasts with the observations. For predicting a new study, generate a new effect from the hierarchy rather than reusing an existing fitted effect. A Leave-one-out cross-validation with entire studies held out can compare integrated predictive probabilities for both arms of each omitted trial, averaging over hyperparameters and its unobserved study effect. Leave-one-study-out influence analysis also reveals whether the difference is driven by a single trial.
Prefer the heavier-tailed hierarchy if it improves the relevant predictive checks and held-out study predictions robustly to reasonable prior choices. The deviance information criterion can supplement the comparison, but its effective parameter count can depend on the latent-variable representation, and six studies give limited information about tail shape. A small numerical criterion difference alone is insufficient evidence.
Past exam of the mathematics course of the University of Cambridge 2016 iii Paper 206 5 b Solution Created 2026-10-03 Updated 2026-10-06
Assume initially that the design points are distinct and ordered on . The cubic smoothing spline minimizesover functions with an absolutely continuous first derivative and square-integrable second derivative. Dividing the residual term by simply changes the scaling assigned to . The minimum roughness property of the natural cubic spline interpolant reduces the problem to natural cubic splines with knots at the design points: among functions with any prescribed fitted values, that interpolant has the smallest integrated squared curvature. The minimizer is therefore a natural cubic smoothing spline, with natural second-derivative boundary conditions and linear tails when extended.
Choose a full basis for this natural-spline space. Put and . Writing changes the objective toDifferentiation gives . Although the curvature penalty has an affine nullspace, the full basis at distinct design points makes the combined matrix positive definite. HenceEquivalently, use the cardinal basis that interpolates the observations, making and . These are smoothing matrices, symmetric but generally not idempotent. Their effective degrees of freedom are . As the fit interpolates; as it approaches ordinary least squares on the affine functions. With replicated predictors, use a design matrix for distinct knots and observation weights; the basis form remains valid when identifiable.
Useful choices include Leave-one-out cross-validation, generalized cross-validation, and estimation of smoothness by restricted maximum likelihood through a mixed-model representation. For fixed , the leave-one-out residual identity for a linear smoother givesMinimize these over a suitable range. Choose smoothing by predictive performance or a variance-component likelihood, not by arbitrarily forcing a visually appealing curve.
Past exam of the mathematics course of the University of Cambridge 2018 iii Paper 218 2 c Solution Created 2026-10-03 Updated 2026-10-05
Choose a candidate grid of . For each candidate and each , fit the soft-margin support vector machine to all observations except , keeping exactly the same in the unnormalized sum objective. Let be its fitted score. Use a fixed rule for assigning a label when the score is zero. The binary misclassification estimate from Leave-one-out cross-validation isChoose a minimizing candidate, break tuning ties by a predetermined rule, and refit on all observations. Any estimated preprocessing must also be fitted inside each training fold to avoid data leakage. If a normalized average-loss parameterization is used instead, translate its parameter so that the same is retained when the sample size decreases.
Past exam of the mathematics course of the University of Cambridge 2024 iii Paper 210 3 Solution Created 2026-09-24 Updated 2026-10-03
A cubic spline with knots is twice continuously differentiable and restricts to a polynomial of degree at most three between consecutive knots. It is a natural cubic spline when it is linear outside , equivalently when its second derivative vanishes at the two outer knots and on the exterior intervals.
Let be the natural cubic spline interpolating prescribed values and let be any other interpolant in . Then . Piecewise integration by parts, using that between knots, is continuous, on the exterior intervals, and every jump of is multiplied by , givesConsequentlyEquality forces almost everywhere. Then is affine and its zeros at at least two distinct knots force , proving uniqueness.
For the penalized problem, fix a vector of fitted values. The preceding variational result says that its natural spline interpolant has the least roughness among all functions taking those values, and by assumption that roughness is . The infinite-dimensional problem therefore reduces toBecause is positive semidefinite, is positive definite. The unique fitted-value vector isand is its unique natural cubic spline interpolant.
For Leave-one-out cross-validation, let minimizeand defineIf , its normal equations sayThus , whereTaking the th coordinate and writing givesTherefore one spline fit and the diagonal of its smoothing matrix give
Past exam of the mathematics course of the University of Cambridge 2024 iii Paper 218 3 d Solution Created 2026-09-24 Updated 2026-09-25
The loop performs Leave-one-out cross-validation: for each it fits a forest to the other eight observations, tests it on observation , and averages the nine zero-one losses. A random forest's out-of-bag error estimate approximates the same held-out prediction error from one fit, because each tree automatically omits roughly a proportion of the observations in its bootstrap sample.
Past exam of the mathematics course of the University of Cambridge 2025 iii Paper 218 4 e Solution Created 2026-09-24 Updated 2026-09-25
The intended quantity is the Leave-one-out cross-validation errorwhere is trained without observation and the loss is the zero-one misclassification loss. Computing it literally requires fitting neural networks, which is prohibitively expensive.
Past exam of the mathematics course of the University of Cambridge 2026 iii Paper 218 3 e Solution Created 2026-09-24 Updated 2026-09-25
The code computes Leave-one-out cross-validation. Ifthen observation is not a support vector. Removing it leaves the optimum unchanged, and the resulting classifier still classifies it correctly. A leave-one-out error can therefore occur only for an observation on or inside the margin, which provesThus the fraction of training observations on or inside the margin is an upper bound on leave-one-out error. One can refit only after deleting support vectors, reusing the full fit for every other observation. Alternatively, K-fold cross-validation needs only fits and is often preferable for larger data sets.
Support-vector leave-one-out error bound 2026-10-05
For a fixed in the unnormalized sum-of-slacks objective and unique training optimizers, deleting an observation with preserves the Karush-Kuhn-Tucker conditions and the fitted decision function. It is correctly classified when held out. Consequently Leave-one-out cross-validation makes at most errors, where counts positive dual coefficients. With geometric support vectors, counting all points of signed margin at most one also gives the bound, without a nondegeneracy assumption.