Dictionary of Applied Machine Learning: 115 machine-learning terms, each with a definition, a figure, citations and a Python demo · All terms · Demos · Start here
Updated on 2026-10-29
Readiness 100/100
See also training set validation set empirical risk minimization loss validation error overfitting hypothesis independent and identically distributed assumption generalization
The training error of a hypothesis is its average loss over the training set, the empirical risk of the hypothesis on the data points used for training. For a hypothesis delivered by empirical risk minimization (ERM), it is the smallest empirical risk that any hypothesis of the hypothesis space attains. Because the same data points selected the hypothesis, the training error is often far below the risk, by a gap that grows with the size of the hypothesis space, so a hypothesis with zero training error can have a large risk. Under the independent and identically distributed assumption (i.i.d. assumption), the training error of every hypothesis is a noisy estimate of its risk, and ERM compares all of them at once, so a generalization guarantee for the ERM solution requires the deviation to be small uniformly over the hypothesis space. A training error far below the validation error indicates overfitting, and a large training error indicates underfitting.

trainerr.py, which recomputes what the entry states: the script block by block · open in ColabB-fetchTwenty of the $1827$ days of five years, 2020 to 2024, at the weather station Krems an der Donau (Austria), every $92$nd day, are drawn in Fig. 1 as a scatterplot. Each day is a data point: its feature $x$ is the morning minimum temperature, its label $y$ the maximum temperature of the day. Three of the days, drawn in black, form a training set, the days used for training, for two empirical risk minimization (ERM)-based methods that deliver the hypotheses $\widehat{h}^{(1)}$ and $\widehat{h}^{(2)}$. The hypothesis $\widehat{h}^{(1)}$ is learned by ERM with the squared error loss over the hypothesis space of affine maps $h(x) = b + w x$, the linear model. The dotted bars are its prediction errors on the three days, the differences between the recorded maximum and the value of $\widehat{h}^{(1)}$, and the average of the three squared bars is its training error, $7.91$.
B-openingThe second hypothesis
$\widehat{h}^{(2)}$ is learned by ERM over the
hypothesis space of all polynomials of degree at most two. Although
the training error of $\widehat{h}^{(2)}$ is zero, and
therefore far below that of $\widehat{h}^{(1)}$, it is the
worse choice: averaged over all days of the five years,
the loss of
$\widehat{h}^{(2)}$ is $42.90$ against $24.22$ for
$\widehat{h}^{(1)}$.
pythondemos/trainerr.pypythondemos/trainerr.py
The training error is computed on the same data points that selected $\widehat{h}$, which limits its use as a measure of quality. The goal of a machine learning (ML) method is to learn a hypothesis that incurs a small loss on any data point, also those outside the training set, that is, to minimize the risk introduced above. The training error of the learned hypothesis is often a poor estimator for its risk, because the learned hypothesis has been adapted to the training set by minimizing the training error. A hypothesis with zero training error can therefore have a large risk, as $\widehat{h}^{(2)}$ of Fig. 1 does. The difference between the risk and the training error is the generalization gap.
Under the independent and identically distributed assumption (i.i.d. assumption), the training error becomes a random variable (RV), as it depends on the randomly generated training set. For one fixed hypothesis $h \in \mathcal{H}$, the empirical risk $\widehat{L}\big(h|\mathcal{D}^{(\rm train)}\big)$ is an average of the $m$ loss values $L\left({\mathbf z}^{(1)},h \right), \ldots, L\left({\mathbf z}^{(m)},h \right)$, which are realizations of independent and identically distributed (i.i.d.) RVs. It is therefore the realization of an RV with expectation $\bar{L} \big( h \big)$ and a variance proportional to $1/m$. ERM does not evaluate this estimate at one fixed hypothesis: it compares the estimates of all hypotheses in $\mathcal{H}$ and picks the smallest. The estimates form the family $\{ \widehat{L}\big(h|\mathcal{D}^{(\rm train)}\big) \}_{h \in \mathcal{H}}$, a stochastic process indexed by the hypothesis space: one RV for each hypothesis, all realized by the single draw of $\mathcal{D}^{(\rm train)}$. The minimizer $\widehat{h}$ of this process is itself an RV, and its training error $E_{t} = \widehat{L}\big(\widehat{h}|\mathcal{D}^{(\rm train)}\big)$ is the minimum of many noisy estimates, so it is below $\bar{L} \big( \widehat{h} \big)$ on average.
A guarantee of generalization for the ERM solution must therefore hold uniformly over the hypothesis space: if \begin{equation} \label{eq_trainerr_uniform} \sup_{h \in \mathcal{H}} \big| \widehat{L}\big(h|\mathcal{D}^{(\rm train)}\big) - \bar{L} \big( h \big) \big| \leq \epsilon \text{,} \end{equation} then $\bar{L} \big( \widehat{h} \big) \leq E_{t} + \epsilon$, and the risk of $\widehat{h}$ exceeds the smallest risk in $\mathcal{H}$ by at most $2\epsilon$ (Shalev-Shwartz and Ben-David, 2014, Lemma 4.2). A hypothesis space for which the uniform deviation \(\eqref{eq_trainerr_uniform}\) falls below any $\epsilon$ with probability at least $1-\delta$ once $m$ is large enough has the uniform convergence property (Shalev-Shwartz and Ben-David, 2014, Def. 4.3). For a finite hypothesis space and a loss with values in $[0,1]$, a union bound over the hypotheses and Hoeffding's inequality give $\epsilon = \sqrt{\ln(2 |\mathcal{H}| / \delta) / (2 m)}$ (Shalev-Shwartz and Ben-David, 2014, Cor. 4.6). For an infinite hypothesis space, $\ln |\mathcal{H}|$ is replaced by a measure of its size such as the Vapnik–Chervonenkis dimension (VC dimension) or the Rademacher complexity (Shalev-Shwartz and Ben-David, 2014, Thm. 6.8, Thm. 26.5).
In contrast, the validation error, computed as the average loss on data points not used in the training, is often a much better estimator for the risk of the learned hypothesis. For example, let the data points of the validation set be realizations of i.i.d. RVs, independent of the training set. Each summand of the validation error is then the loss on an independent draw from the probability distribution of a data point, whose expectation conditional on the training set is the risk of the learned hypothesis (Hastie et al., 2009, Eq. (7.2)). The expectation of the validation error conditional on the training set is therefore that risk. Moreover, the validation error estimates the risk of the single hypothesis that $\mathcal{A}$ delivered, so one Hoeffding bound without $|\mathcal{H}|$ suffices for it, and it concentrates around the risk at a rate that depends only on the size of the validation set, not on how the hypothesis was learned (Shalev-Shwartz and Ben-David, 2014, Thm. 11.1).
Fig. 3 shows three deviations of a training error from a risk for one year of the Krems record: for one fixed hypothesis, for the hypothesis that ERM learns, and the largest deviation over the hypothesis space. The $366$ days of the year stand in for the probability distribution of a day, so the risk of a hypothesis is its average loss over the year, and a training set of $m$ days is drawn at random from the year, $300$ times for each $m \in \{10, 20, 40, 80\}$. The hypothesis space is the linear model, which consists of all hypothesis maps $h(x) = w_{1} x + w_{0}$ with $w_{1}, w_{0} \in \mathbb{R}$.
B-uniformThe fixed hypothesis
is the one with the smallest risk in the hypothesis space, the
hypothesis learned by linear regression from all $366$ days; it does not
depend on the draw. The ERM hypothesis is
learned by linear regression from the drawn training set. The
largest deviation over the hypothesis space, the uniform deviation
\(\eqref{eq_trainerr_uniform}\), is approximated by the maximum over a
grid of $2500$ hypotheses around the learned one. Over the
repeated draws, the deviation of the
fixed hypothesis has mean zero. The training error of the
ERM hypothesis is below its risk on average, and
the largest deviation is several times the standard deviation of the
fixed hypothesis' deviation. The gap of the ERM
hypothesis never exceeds the largest deviation, as the uniform
deviation \(\eqref{eq_trainerr_uniform}\) requires, and both decrease
as the training set grows
(pythondemos/trainerr.py).
pythondemos/trainerr.pypythondemos/trainerr.py
See also: training set, validation set, empirical risk, empirical risk minimization, loss, validation error, risk, generalization gap, overfitting, underfitting, hypothesis, independent and identically distributed assumption, generalization, stochastic process, concentration inequality, Vapnik–Chervonenkis dimension.
@misc{dictml_trainerr,
author = {Jung, Alexander},
editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
title = {training error},
howpublished = {Dictionary of Applied Machine Learning (course edition)},
year = {2026},
doi = {10.5281/zenodo.21569296},
note = {ISBN 978-952-64-3013-3, CC BY 4.0, retrieved 2026-11-13},
url = {https://dictionaryofml.org/terms/trainerr.html}
}