# random variable (RV)

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

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

## Abstract

A random variable (RV) is a measurable function that maps each outcome of a random experiment to an element of a measurable space. Important types of RVs include binary RVs, discrete RVs, real-valued RVs, random vectors, and random matrices. The analysis of machine learning methods often relies on probabilistic models that represent data sources as RVs. The most widely used probabilistic model assumes that data points are independent and identically distributed RVs with a common probability distribution, which is unknown in general.

## Definition

The weather on a given day in the Austrian city Krems an der Donau is the outcome of a random experiment (Hyndman and Athanasopoulos, 2021). Each possible outcome $\omega$ is characterized by a maximum daytime temperature, the temperature at 13:00, and recording this temperature assigns a real number $x(\omega)$ to the outcome. This assignment is an RV $x$. The temperatures recorded on consecutive days are realizations of this RV (see Fig. 1).

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

*Figure 1: Each day's maximum daytime temperature, read at 13:00, is a realization of the real-valued RV $x$; the stem plot shows one realization per day over 30 consecutive days. Data generated by pythondemos/rv.py*

More generally, an RV maps the outcomes of a random experiment to elements of a measurable space (Billingsley, 1986; Gray, 2009). Mathematically, an RV is a measurable function $x: \Omega \rightarrow \mathcal{X}$ whose domain is the sample space $\Omega$ of a probability space and whose co-domain is a measurable space $\mathcal{X}$. Measurability refers to the σ-algebras of the two spaces: the preimage $x^{-1}(B)$ of every measurable set $B \subseteq \mathcal{X}$ must belong to the σ-algebra of the probability space, so that the probability of $x$ taking a value in $B$ is defined. The value $x(\omega) \in \mathcal{X}$ that $x$ assigns to an outcome $\omega \in \Omega$ is the image of $\omega$ under $x$ (see Fig. 2).

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

*Figure 2: An RV $x$ sends each outcome $\omega$ of a random experiment to its image $x(\omega)$ in a measurable space $\mathcal{X}$. The black arrow follows one outcome; the gray arrows show the remaining outcomes, two of which share the same image. An RV can therefore map a large sample space into a small measurable space*

Different types of RVs include

- binary RVs, which map each outcome to an element of a binary set (e.g., $\{-1,1\}$ or $\{\text{cat}, \text{no cat}\}$);
- discrete RVs, which take on values in a countable set (which can be finite or countably infinite; e.g., the number of heads in ten coin flips, with values in $\{0,1,\ldots,10\}$);
- real-valued RVs, which take on values in the real numbers $\mathbb{R}$ (e.g., the maximum daytime temperature in Krems);
- random vectors, which map outcomes to the Euclidean space $\mathbb{R}^{d}$ (e.g., the red-green-blue (RGB) values of a pixel, which form a vector in $\mathbb{R}^{3}$);
- random matrices, which map outcomes to a space of matrices $\mathbb{R}^{m \times d}$ (e.g., the data matrix of a dataset).

The sample space and the RVs on it are a modeling choice, not fixed by the data. The daily Krems temperatures admit two standard constructions (Fig. 3). In the first, each day $r$ has its own probability space with sample space $\Omega^{(r)}$, and the temperature of that day is an RV $x^{(r)} : \Omega^{(r)} \rightarrow \mathbb{R}$; the recorded value is one realization $x^{(r)}(\omega^{(r)})$. In the second, one probability space with sample space $\Omega$ represents all days at once: a single outcome $\omega \in \Omega$ fixes the temperatures of all days, and each day is an RV $x^{(r)} : \Omega \rightarrow \mathbb{R}$ on this common space. The independent and identically distributed assumption is a statement about the second construction: the $x^{(r)}$ share one probability distribution and are independent, a property defined for RVs on one common probability space (Billingsley, 1986, Sect. 20). The common-space construction is the one used for learning from data, because a single probability distribution then governs an entire dataset.

![Figure 3 of the entry rv](https://dictionaryofml.org/terms/fig/rv-fig3.svg)

*Figure 3: Two constructions for the daily Krems an der Donau temperatures $t_{r}$. (a) Each day $r$ has its own probability space with sample space $\Omega^{(r)}$ and RV $x^{(r)}$, with a separate outcome per day. (b) One probability space with sample space $\Omega$ represents all days at once, so a single outcome $\omega$ fixes every day's temperature $t_{r} = x^{(r)}(\omega)$; only this construction supports modeling the days as independent and identically distributed RVs*

In machine learning, RVs represent data sources, so that the behavior of learning methods can be analyzed. For example, the generation of a training set or validation set is represented by independent and identically distributed RVs sharing one underlying probability distribution in the common-space construction. This probability distribution is either postulated or estimated from actual datasets, for example via maximum likelihood. Ideally, a machine learning method should work well on datasets that arise as realizations of high probability. This is the generalization goal that empirical risk minimization pursues, minimizing the average loss on the training set as a proxy for the expected loss of the learned hypothesis on a new data point drawn from the common probability distribution.

**See also:** function, [random experiment](https://dictionaryofml.org/terms/randomexperiment.html), sample space, probability space, vector, Euclidean space, probability, measurable, realization, probabilistic model, random vector, random matrix, sub-Gaussian random variable.

## References

- Hyndman and Athanasopoulos (2021). Forecasting: Principles and Practice. *OTexts*. <https://otexts.com/fpp3/>
- Billingsley (1986). Probability and Measure. *Wiley*.
- Gray (2009). Probability, Random Processes, and Ergodic Properties. *Springer Science+Business Media*. <https://doi.org/10.1007/978-1-4419-1090-5>

## Cite this entry

```bibtex
@misc{dictml_rv,
  author = {Jung, Alexander},
  editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
  title = {random variable (RV)},
  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-11},
  url = {https://dictionaryofml.org/terms/rv.html}
}
```
