# mean

*Entry of the [Dictionary of Applied Machine Learning](https://dictionaryofml.org) (course edition), by Alexander Jung, Aalto University. CC BY 4.0. Updated 2026-10-29. [HTML](https://dictionaryofml.org/terms/mean.html) · [typeset PDF](https://dictionaryofml.org/terms/mean.pdf) · [LaTeX](https://dictionaryofml.org/terms/mean.tex) · [Python demo](https://dictionaryofml.org/terms/mean.py) · [notebook](https://dictionaryofml.org/terms/mean.ipynb)*

Math is LaTeX with the book's macros expanded, so no notation package is needed to read it.

## Abstract

The mean of a random vector ${\mathbf x}$ is its expectation, the Lebesgue integral of ${\mathbf x}$ with respect to its probability distribution. The term also refers to the sample mean, i.e., the average of the data points in a dataset. The two usages are consistent: the sample mean is the mean of the random vector obtained by drawing a data point uniformly from the dataset. Both usages share a further characterization: for a random vector with a finite second moment, the mean is the unique solution of a risk minimization problem under the squared error loss. For the random vector from a dataset, this optimization problem reduces to empirical risk minimization in the simplest regression setting: predicting a numeric label without features, for which the learned hypothesis is the sample mean of the labels.

## Definition

A weather station records the daily maximum temperature for a year. Adding the $365$ numbers and dividing by $365$ returns a single value that summarizes the whole record. This is the mean of the recorded numbers, and the same word names the corresponding quantity for a probability distribution.

The mean of a random vector ${\mathbf x}$, which takes on values in a Euclidean space $\mathbb{R}^{d}$, is its expectation $\mathbb{E}\{{\mathbf x}\}$. It is the Lebesgue integral of ${\mathbf x}$ with respect to its probability distribution $\mathbb{P}$ (e.g., see Billingsley (1986) or Rudin (1987)), i.e.,

$$
\mathbb{E}\{{\mathbf x}\} = \int_{\mathbb{R}^{d}} {\mathbf x} \, \mathrm{d}\mathbb{P}({\mathbf x}) \text{.}
$$

Here, $\mathbb{P}$ is the probability distribution that ${\mathbf x}$ induces on $\mathbb{R}^{d}$, so the integral runs over the values ${\mathbf x}$ takes rather than over the underlying sample space. No probability density function need exist for the mean to be defined; when one does, denoted by $p$, it is $\int_{\mathbb{R}^{d}} {\mathbf x} \, p({\mathbf x}) \, \mathrm{d}{\mathbf x}$.

The average of the opening paragraph is the sample mean of a finite dataset of sample size $m$, $\mathcal{D} = \left\{ {\mathbf x}^{(1)}, \,\ldots, \,{\mathbf x}^{(m)} \in \mathbb{R}^{d}\right\}$. These two usages are consistent. A dataset defines a discrete random variable $\widetilde{{\mathbf x}}^{(\mathcal{D})}={\mathbf x}^{(I)}$ on the sample space $\{1, \,\ldots, \,m\}$. Here, the index $I$ is chosen uniformly at random, i.e., $\mathbb{P}\left(I=r\right)=1/m$ for all $r=1,\ldots,m$. The mean of $\widetilde{{\mathbf x}}^{(\mathcal{D})}$ is precisely the sample mean

$$
({1}/{m}) \sum_{r=1}^{m}
{\mathbf x}^{(r)} \text{.}
$$

The probability distribution of $\widetilde{{\mathbf x}}^{(\mathcal{D})}$, which places mass $1/m$ on each data point, is the empirical distribution of the dataset. Fig. 1 shows both readings for a real-valued random variable and a dataset of seven numbers, with the empirical distribution drawn as its cumulative distribution function.

![Figure 1 of the entry mean](https://dictionaryofml.org/terms/fig/mean-fig1.svg)

*Figure 1: The two readings of *mean*. (a) A real-valued random variable with the standard normal probability density function has mean $\mathbb{E}\{x\} = 0$, the Lebesgue integral of $x$ against that probability density function. (b) The $m = 7$ data points average to the sample mean $0.1$. (c) The empirical distribution of the same data points, drawn as its cumulative distribution function $F^{(\mathcal{D})}\left(x\right)$: a staircase rising by $1/m$ at each data point, from $0$ to $1$. It is the probability distribution of the discrete random variable $\widetilde{{\mathbf x}}^{(\mathcal{D})}$ above, and its mean is the sample mean of (b). The sample mean $0.1$ of (b) and (c) differs from the mean $0$ of the random variable in (a) because $m$ is finite*

The two readings are further connected by a shared characterization. Consider any random vector with a finite second moment, i.e., $\mathbb{E}\{ \left\lVert {\mathbf x} \right\rVert_{2}^{2} \} < \infty$. Its mean is the unique solution of the following risk minimization problem (Bertsekas and Tsitsiklis, 2008):

$$
\mathbb{E}\{{\mathbf x}\} = \mathop{\mathrm{arg\,min}}_{{\mathbf c} \in \mathbb{R}^{d}}
\mathbb{E} \big\{\left\lVert {\mathbf x} - {\mathbf c} \right\rVert_{2}^{2}\big \} \text{.}
$$

The objective function of this problem is a strictly convex function of the optimization variable ${\mathbf c} \in \mathbb{R}^{d}$.

For the discrete random variable that a dataset defines, the risk is the average squared error over the dataset, so this risk-minimization characterization applies directly to the simplest machine learning problem, predicting a numeric label without any features. Consider a training set $\mathcal{D}^{(\rm train)} = \big\{ y^{(1)}, \,\ldots, \,y^{(m)} \big\}$ that consists of labels $y^{(r)} \in \mathbb{R}$ only. A hypothesis is then a single number $h \in \mathbb{R}$ that serves as the prediction for every data point. Empirical risk minimization with the squared error loss searches over candidate hypotheses $h' \in \mathbb{R}$ and learns

$$
\widehat{h}
= \mathop{\mathrm{arg\,min}}_{h' \in \mathbb{R}}
\frac{1}{m} \sum_{r=1}^{m}
\big(y^{(r)} - h'\big)^{2}
= \frac{1}{m} \sum_{r=1}^{m}
y^{(r)} \text{,}
$$

i.e., the learned hypothesis is the sample mean of the labels (see Fig. 2). This setting coincides with linear regression for data points that carry the constant scalar feature $x = 1$.

![Figure 2 of the entry mean](https://dictionaryofml.org/terms/fig/mean-fig2.svg)

*Figure 2: A training set of $m = 5$ numeric labels $y^{(r)}$ (filled circles) and the learned hypothesis $\widehat{h} = 4$ (horizontal dashed line), which is the sample mean of the labels. The vertical gray segments are the errors $y^{(r)} - \widehat{h}$; the sample mean minimizes the average of their squares*

Squaring the deviations also makes the mean sensitive to outliers. Moving one of $m$ data points by an amount $\delta$ shifts the sample mean by $\delta / m$, so a single corrupted data point can move the mean arbitrarily far. The trimmed mean that discards a fraction $\gamma$ at each end stays bounded however far at most $\gamma m$ data points are moved, and the median stays bounded however far up to half of the $m$ data points are moved. Both are therefore preferred when features or labels may be unreliable (Huber, 1992; pythondemos/mean.py).

**Synonyms:** expectation, expected value.

**See also:** [random variable](https://dictionaryofml.org/terms/rv.html), random vector, expectation, sample mean, [probability distribution](https://dictionaryofml.org/terms/probdist.html), Lebesgue integral, [empirical risk minimization](https://dictionaryofml.org/terms/erm.html), squared error loss, [linear regression](https://dictionaryofml.org/terms/linreg.html), median, trimmed mean.

## References

- Bertsekas and Tsitsiklis (2008). Introduction to Probability. *Athena Scientific*.
- Huber (1992). Robust estimation of a location parameter. *Breakthroughs in Statistics: Methodology and Distribution*.
- Billingsley (1986). Probability and Measure. *Wiley*.
- Rudin (1987). Real and Complex Analysis. *McGraw-Hill*.

## Cite this entry

```bibtex
@misc{dictml_mean,
  author = {Jung, Alexander},
  editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
  title = {mean},
  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-04},
  url = {https://dictionaryofml.org/terms/mean.html}
}
```
