Probability Basics › Expected Value and Variance
Machine Learning from ScratchAll chapters Probability Basics › Expected Value and VarianceOne section · Sections in this chapter5 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
While a full probability distribution gives complete information about a random variable, we often need summary statistics that capture the key features with just a few numbers. The two most important summary measures are the expected value and variance, which describe the center and spread of a distribution.
Expected Value
The expected value (or mean) of a random variable represents its long-run average value if we repeated the random process infinitely many times. For a discrete random variable with values and corresponding probabilities , the expected value is:
Example: Expected Number of Heads in Coin Flips
For a binomial random variable (like counting heads in coin flips), there's a convenient formula: , where is the number of trials and is the probability of success on each trial. If we flip a fair coin 100 times, the expected number of heads is:
This means that over many repetitions of 1000 coin flips, the average number of heads will converge to 500.
Example: Expected Value of a Fair Die Roll
Consider rolling a fair six-sided die. The random variable represents the outcome, which can be any value from 1 to 6, each with probability :
Notice that the expected value of 3.5 is not even a possible outcome of a single die roll! This illustrates an important point: the expected value represents the long-run average, not necessarily an achievable result. If you rolled a die 1000 times and averaged all the results, you'd get very close to 3.5.
For a continuous random variable with probability density function , the expected value is:
The expected value provides a measure of central tendency, answering the question: "What value should I expect on average?" However, knowing only the average doesn't tell us how much variation to expect around that average.
Example: Expected Value of an Exponential Distribution
Consider a continuous random variable following an exponential distribution with rate parameter . The exponential distribution models waiting times between events (like time between customer arrivals or component failures). Its probability density function is:
To find the expected value, we compute the integral of weighted by the probability density function:
This integral requires integration by parts, which follows the formula:
We strategically choose our parts to simplify the integral. The key insight is to let be the polynomial term (which simplifies when differentiated) and be the exponential term (which remains manageable when integrated):
To verify the calculation of : when we integrate , we use substitution. Let , so , which means . Then:
Now we apply integration by parts:
Evaluating the boundary term :
At the lower limit ():
At the upper limit (): We need to evaluate . This is an indeterminate form of type , where the linear term grows without bound while the exponential term decays to zero. To resolve this, we rewrite it as a fraction and apply L'Hôpital's rule:
This is now an form, so we differentiate the numerator and denominator:
The exponential growth in the denominator dominates the linear growth in the numerator. Therefore:
Evaluating the remaining integral :
Using the antiderivative (which can be verified by differentiation):
Note: As , we have since .
Combining the results:
For , this gives . This means that on average, we expect to wait 2 time units between events. The result is intuitive: a higher rate (more frequent events) leads to a shorter expected waiting time, while a lower rate leads to longer waits. The integral converges beciance
Variance
The variance measures how spread out the distribution is around its expected value. It quantifies the average squared deviation from the mean, giving us a sense of how much uncertainty or variability exists in the random variable. The variance of a random variable is defined as:
Where:
- is the variance of the random variable
- is the expected value (mean)
- is the expected value of the squared random variable
A closely related measure is the standard deviation, which is simply the square root of the variance: . The standard deviation has the advantage of being in the same units as the original random variable, making it more interpretable. For example, if we're measuring heights in centimeters, the standard deviation is also in centimeters, while the variance would be in squared centimeters.
These summary statistics prove invaluable in practice. For example, when comparing investment options, the expected value tells us the average return, while the variance indicates the risk. When designing systems, knowing the expected load and its variability helps us provision appropriate capacity.
Example: Variance of the Exponential Distribution
For our exponential distribution with PDF , we'll compute the variance using the formula .
We already found that , so .
Now we need to find :
We'll use integration by parts twice to evaluate .
First integration by parts: Let and , then and .
Note: The boundary term vanishes because (exponential decay dominates polynomial growth) and the term at is also zero.
Second integration by parts: For , let and , then and .
Combining the results:
Therefore:
Computing the variance:
For , this gives , and the standard deviation is .
Notice that for the exponential distribution, the standard deviation equals the mean (). This is a unique property of the exponential distribution and reflects its memoryless nature.the variability is proportional to the expected waiting time.
Example: Visualizing Expected Value and Variance
This example illustrates how expected value and variance characterize different aspects of a distribution. Two distributions can have the same mean but vastly different spreads.
![Narrow normal density with a legend identifying μ=0, σ²=1 and the dashed expected-value line E[X]=0.](https://assets.mbrenndoerfer.com/_optimized/notebooks/3_probability_basics_files/probability-low-variance-distribution-1920w.webp)
![Wide normal density with a legend identifying μ=0, σ²=4 and the same dashed expected-value line E[X]=0.](https://assets.mbrenndoerfer.com/_optimized/notebooks/3_probability_basics_files/probability-high-variance-distribution-1920w.webp)