Random Variables
Formal
(Random Variable)
A random variable is a measurable function that maps outcomes in the sample space to real numbers. All randomness comes from ; the function itself is deterministic.
(Discrete Random Variable)
is discrete if its image is countable. It is characterised by a Probability Mass Function (PMF):
(Continuous Random Variable)
is continuous if its image is uncountable. It is characterised by a Probability Density Function (PDF) such that
Note: for any specific in the continuous case.
(Cumulative Distribution Function)
The CDF is defined for both discrete and continuous RVs:
For continuous RVs: .
Intuition
A Random Variable is a type-safe parser for raw outcomes. The sample space contains unstructured events — a coin toss result, an HTTP response, a user action. A random variable extracts a single numeric value of interest from that event.
raw outcome ω ──[X : Ω → ℝ]──► numeric value x
"packet arrived late" ──► latency_ms = 340
The PMF or PDF is then the frequency histogram of those numeric values across all possible outcomes, weighted by their probability.
ML Applications
- Features and labels — every input feature and output label in supervised learning is an RV. Training a model is estimating the joint distribution .
- Model outputs — a classifier outputs , a conditional PMF over class labels. A regression model outputs an estimate of .
- Loss functions as expectations — the expected loss is an expectation of an RV. Minimising training loss is an approximation of minimising this.
- Latent variables — in models like GMMs and VAEs, hidden structure is represented as unobserved RVs that the model must infer.