Skip to the workspace
Pebellslearn by building
Probability  ›  Lesson

Random Variables and PDFs

Random Variances, PDFs 15 minA random variable is a number decided by chance; a discrete one puts probability on single values, while a continuous one spreads it as a density whose area gives probability.

machine learning / Random Variables and PDFs

Explore each scene at your own pace.

01 · The rule

The rule

Random Variables and PDFs

Pick one of the five flats at random. Its number of rooms is not fixed until you pick, but you can still say exactly how likely each value is. A number decided by chance is a random variable, and models describe their uncertainty with them all the time: "rent is probably around 20, give or take 4".

The rule

Discrete: probability sits on points. Continuous: probability is area under the density.

Discrete random variables take separate values you can list. Let RR be the rooms of a random flat from A to E. The rooms are 1, 2, 3, 2 and 2, so the probability mass function is:

Rooms 1 2 3
Probability 0.2 0.6 0.2

The probabilities sum to 1. The expected value is the probability-weighted average:

E[R]=1(0.2)+2(0.6)+3(0.2)=2.0E[R] = 1(0.2) + 2(0.6) + 3(0.2) = 2.0

Continuous random variables can take any value in a range, like the exact rent of a flat in a new city. There are infinitely many possible values, so any single exact value has probability 0. Instead, a probability density function (PDF) f(x)f(x) is a curve, and the probability of landing in a range is the area under the curve over that range. The total area is 1.

Suppose rents in a new city are equally likely anywhere from 10 to 30 thousand. The density is flat, and to make the total area 1 over a width of 20, its height is 1/20=0.051/20 = 0.05. Then

P(15≤X≤20)=5×0.05=0.25P(15 \le X \le 20) = 5 \times 0.05 = 0.25

A density is probability per unit, not a probability. So it can be bigger than 1: a density spread evenly from 0 to 0.5 must have height 2 to give area 1. The cumulative distribution function F(x)=P(X≤x)F(x) = P(X \le x) is the area to the left of xx, and it always climbs from 0 to 1.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.