Probability as Frequency
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 13 of 64.
A spam filter says "90% spam"; a seed packet says "80% sprout". A probability is a long-run share, from 0 (never) to 1 (always). Here are 50 seeds:
rng.random(n) draws decimals from 0 to 1, and 80% of them land below 0.8. So one comparison plants 1000 seeds:
rng = np.random.default_rng(3)
sprouted = rng.random(1000) < 0.8
print(sprouted.sum())
print(sprouted.mean())This prints:
814
0.814The mean of booleans is the share of True: 0.814, near 0.8. By this chapter's end, that trick prices a whole dice stall.
Challenge
MediumA striker scores a penalty with some chance. The program reads the chance (0 to 1), then the number of kicks; the starter makes rng.
- Simulate the kicks: a goal wherever a
rng.randomdraw is below the chance. - Print the goals and the estimated chance, rounded to 3 decimals.
For 0.5 and 10 kicks, a short run that wobbles far from 0.5:
Goals: 3 of 10
Estimated chance: 0.3Try it yourself
import numpy as np
chance = float(input())
kicks = int(input())
# Don't change the line below
rng = np.random.default_rng(21)
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Statistics for ML
1Center and Spread
Mean and MedianPercentiles and QuartilesVariance and StdSample or Population?The Most Common ValueRecap: Delivery Times4Samples and Populations
Population and SampleSample Means VaryThe Sampling DistributionBigger Samples, Less NoiseRecap: Polling a Town2Distributions
Density HistogramsShapes of DataThe Normal CurveThe 68-95-99.7 RuleZ-ScoresRecap: Battery Life3Probability by Simulation
Probability as FrequencyThe Law of Large NumbersSums of DiceExpected ValueConditional ProbabilityRecap: Dice Stall Odds6Relationships
Reading Scatter PlotsCorrelationCorrelation MatrixCorrelation HeatmapsCorrelation Is Not CauseRecap: Ice Cream and SunPractice on your own: Online Python compiler