A product of thousands of chances runs into a problem.
Predict
Multiply the 5,000 orders' chances at the best rate in float64. What comes out?
# each order's chance at the best ratechances = np.where(returned == 1, k / n, 1 - k / n)print(f"product of the {n:,} chances: {np.prod(chances)}")print(f"sum of their logs: {np.log(chances).sum():.1f}")
product of the 5,000 chances: 0.0sum of their logs: -1868.2
The Deep Learning book names the problem: a product over many probabilities is prone to numerical underflow. CS229's notes give the way out: you can maximize any strictly increasing function of the likelihood instead. The log is one, so the best rate doesn't move, and the sum, −1868.2, is an ordinary number.
In the editor, write log_likelihood(p, outcomes). It prints five orders at a 30% rate.
Pick an answer above to see the rest
Instructions
1
Write log_likelihood(p, outcomes): add log p for each 1 and log(1 − p) for each 0.
2
Return float("-inf") if the data is impossible at that p.