Practice: Random variables and expected value
The core skill is computing an expected value (multiply each value by its probability, add) and reading it correctly as a long-run average, plus keeping variance in view as the risk that expected value alone hides. Keep a scratchpad.
Self-check
Section titled “Self-check”Six short questions. Answer each in your head before opening the collapsible.
1. What is a random variable, and what are the two kinds?
Show answer
A number whose value is a numerical outcome of a random process (the result of a die roll, a count of tickets, a payoff). Discrete random variables have separate, listable values (counts, dice); continuous ones fill a range (heights, times) and cannot be listed.
2. How do you compute the expected value of a discrete random variable?
Show answer
Multiply each possible value by its probability and add them all up: E[X] = sum of (value x its probability). It is the probability-weighted average, not the plain average, unless the values are equally likely.
3. The expected value of a die roll is 3.5, but a die never shows 3.5. Explain.
Show answer
The expected value is the long-run average, not a value any single roll produces. Over thousands of rolls the average closes in on 3.5; on any one roll you get a whole number. An expected value need not be an achievable outcome.
4. Two bets have the same expected value. Does that make them equally good?
Show answer
Not necessarily. They can have very different variance (risk). One might pay close to the average almost every time; the other might swing between a big win and a big loss. Expected value gives the center; variance gives the spread, and you usually care about both.
5. What does the variance of a random variable measure?
Show answer
How far the outcomes typically land from the expected value: the probability-weighted average of the squared distances from E[X]. Its square root, the standard deviation, is in the original units. Bigger variance means more spread-out, riskier outcomes.
6. Where does expected value appear in machine learning?
Show answer
A loss function is an expected error the model minimizes; a reward is an expected payoff an agent maximizes; reported performance (accuracy, error rate) is an expected value over the data distribution. “Minimize the loss” and “maximize reward” are both expected-value statements.
Try it yourself: compute the expected value
Section titled “Try it yourself: compute the expected value”A support agent closes a number of tickets per hour with this distribution:
tickets closed: 0 1 2 3probability: 0.1 0.3 0.4 0.2What is the expected number of tickets closed per hour? (First confirm the probabilities are valid.)
Show answer
Probabilities sum to 0.1 + 0.3 + 0.4 + 0.2 = 1.0 (valid).
E[tickets] = 0(0.1) + 1(0.3) + 2(0.4) + 3(0.2) = 0 + 0.3 + 0.8 + 0.6 = 1.7 tickets per hourThe agent closes 1.7 tickets per hour on average, even though 1.7 is not a possible single-hour count. Over many hours the average lands near 1.7; in any one hour the count is a whole number.
Try it yourself: compare two bets (value and risk)
Section titled “Try it yourself: compare two bets (value and risk)”Two options, each costing nothing to play:
Bet A: win $5 with probability 0.5, lose $2 with probability 0.5.Bet B: win $20 with probability 0.1, win $0 with probability 0.9.Compute the expected value of each. Which has the higher expected value, and what does variance add to the picture?
Show answer
E[A] = (+5)(0.5) + (-2)(0.5) = 2.5 - 1.0 = 1.5E[B] = (+20)(0.1) + (0)(0.9) = 2.0 + 0 = 2.0Bet B has the higher expected value (2.0 vs 1.5), so over many plays B earns more on average. But B is far riskier: 90% of the time it pays nothing, and all its value rides on the rare $20 win, while A pays something close to its average more often. If you only play once or twice, that variance matters a lot; if you play thousands of times, the higher expected value of B wins out. Expected value picks the long-run winner; variance tells you how bumpy the road is.
Flashcards
Section titled “Flashcards”Eight cards. Click any card to reveal the answer. Use the Print flashcards button to lay out the full set as one card per page for offline review.
Q. What is a random variable?
A number whose value is a numerical outcome of a random process (a die roll, a count, a payoff). Discrete ones have listable values; continuous ones fill a range.
Q. How do you compute the expected value of a discrete random variable?
Multiply each value by its probability and add: E[X] = sum of (value x probability). The probability-weighted average, equal to the plain average only when values are equally likely.
Q. What does the expected value represent, and must it be achievable?
The long-run average if the process were repeated many times. It need not be an achievable outcome: a die’s expected value is 3.5, which never appears on a roll.
Q. How do you use expected value to compare uncertain options?
Compute each option’s expected value; the higher one is the better long-run bet. A game with expected value -$0.40 per play loses money over time even if you sometimes win.
Q. What does the variance of a random variable measure?
The probability-weighted average squared distance of outcomes from the expected value. Its square root (standard deviation) is in original units. More variance means more spread-out, riskier outcomes.
Q. Two random variables have the same expected value. Are they interchangeable?
No. They can differ greatly in variance (risk). Same center, different spread; you usually care about both the expected value and the variance.
Q. How is a loss function an expected value?
Training minimizes the model’s average error over the data, which is the expected value of a loss. ‘Minimize the loss’ means ‘make the expected error small.’
Q. How is expected value used by a learning agent?
The agent maximizes expected total reward and chooses actions by their expected value: the action expected to pay off best over the long run.