Python demo — a script that recomputes what this entry states and prints one line per check
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 random variables (discrete RVs), real-valued RVs,
random vectors, and random matrices. The analysis of
machine learning (ML) 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 (i.i.d.) RVs with a common probability distribution,
which is unknown in general.
Definition
P-weatherThe weather on a given day in the Austrian city Krems 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 reading off 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: 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: \samplespace \rightarrow \featurespace$
whose domain is the sample space $\samplespace$ of a probability space and
whose co-domain is a measurable space $\featurespace$.
Measurability refers to the $\sigma$-algebras of the two spaces:
the preimage $x^{-1}(B)$ of every measurable set $B \subseteq \featurespace$
must belong to the $\sigma$-algebra of the probability space, so that
the probability of $x$ taking a value in $B$ is defined.
The value $x(\omega) \in \featurespace$ that $x$ assigns to an
outcome $\omega \in \samplespace$ is the image of $\omega$ under
$x$ (see Fig. 2).
Figure 2: An RV $x$ sends each outcome $\omega$ of a
random experiment to its image $x(\omega)$ in a
measurable space $\featurespace$. 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
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 $\sampleidx$ has its own probability space with
sample space $\samplespace^{(\sampleidx)}$, and the
temperature of that day is an RV
$x^{(\sampleidx)} : \samplespace^{(\sampleidx)} \rightarrow \reals$; the
recorded value is one realization
$x^{(\sampleidx)}(\omega^{(\sampleidx)})$. In the second, one probability space
with sample space $\samplespace$
carries the whole reality: a single outcome $\omega \in \samplespace$
fixes the temperatures of all days simultaneously, and each day is an RV
$x^{(\sampleidx)} : \samplespace \rightarrow \reals$ on this common space.
The independent and identically distributed (i.i.d.) assumption is a statement about the second construction: the
$x^{(\sampleidx)}$ share one probability distribution and are independent. The
common-space construction is the one used for learning from data, because a
single probability distribution then governs an entire dataset.
Figure 3: Two constructions for the daily Krems temperatures
$t_{\sampleidx}$. (a) Each day $\sampleidx$ has its own
probability space with sample space $\samplespace^{(\sampleidx)}$
and RV
$x^{(\sampleidx)}$, with a separate outcome per day. (b)
One probability space with sample space $\samplespace$ carries
the whole reality, so a
single outcome $\omega$ fixes every day's temperature
$t_{\sampleidx} = x^{(\sampleidx)}(\omega)$; only this construction
supports modeling the days as i.i.d. RVs
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 random variables (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 $\reals$ (e.g., the maximum daytime temperature in Krems);
random vectors, which map outcomes to the Euclidean space $\reals^{\featuredim}$ (e.g., the red-green-blue (RGB) values of a pixel, which form a vector in $\reals^{3}$);
random matrices, which map outcomes to a space of matrices $\reals^{\samplesize \times \featuredim}$ (e.g., the datamatrix of a dataset).
See also: function, random experiment, 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. otexts.com/fpp3/
Billingsley (1986). Probability and Measure. Wiley.
Gray (2009). Probability, Random Processes, and Ergodic Properties. Springer Science+Business Media. doi.org/10.1007/978-1-4419-1090-5
Cite this entry
@misc{dictml_rv,
author = {Jung, Alexander},
editor = {Olioumtsevits, Konstantina and Schnoor, Ekkehard},
title = {random variable},
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-09-22},
url = {https://dictionaryofml.org/terms/rv.html}
}