The 68-95-99.7 Rule
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 10 of 64.
In normal data, the std tells you what share lies how far from the mean. Coffee pours, mean 250 ml, std 5 ml:
That is the 68-95-99.7 rule. Check it on 10,000 simulated cups: a mask counts those within 1 std.
rng = np.random.default_rng(1)
cups = rng.normal(250, 5, size=10000)
within1 = (cups > 245) & (cups < 255)
print(within1.sum() / cups.size)This prints:
0.6868For the share below any value, stats.norm.cdf(x, mean, std) gives the area left of x: stats.norm.cdf(260, 250, 5) is 0.977.
A pour beyond 3 std happens 3 times in 1,000: rare enough to flag before it reaches a model.
Challenge
EasyA lab ran 5,000 bulbs until they burned out. life holds their hours, and the program reads h. Using the mean and std (np.std) of life, print these shares as percents (1 decimal):
- within 1 std of the mean,
- within 2 std,
- below
h, counted, - below
h, by the normal curve.
For another batch and the input 1100:
Within 1 std: 67.6%
Within 2 std: 95.7%
Below 1100 hours, counted: 10.2%
Below 1100 hours, normal curve: 10.1%Try it yourself
import numpy as np
from scipy import stats
# Don't change the lines below
rng = np.random.default_rng(12)
life = np.round(rng.normal(1200, 100, size=5000))
h = int(input())
# 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