Z-Scores
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 11 of 64.
A student scored 78 in chemistry and 85 in history. Which is better? Measure each score in its own class's std:
That distance is the z-score, z = (x - mean) / std. Chemistry: (78 - 70) / 4 is 2.0. History: (85 - 80) / 10 is 0.5. The 78 wins.
On a whole array, a negative z means below the mean:
temps = np.array([12, 15, 9, 18, 16])
print(np.round((temps - temps.mean()) / temps.std(), 2))This prints:
[-0.63 0.32 -1.58 1.26 0.63]Z-scores share one scale, mean 0 and std 1, whatever the unit. Age and income then weigh alike in a model, however big their numbers.
Challenge
EasyAn arcade's puzzle and racing games score on very different scales. puzzle and racing hold 12 regulars' scores on each. A newcomer played both: the program reads their puzzle score, then their racing score.
- Print each score's z-score against its game, rounded to 2 decimals (use
.std()). - Print which result is more impressive.
For the input 790 and 16900:
Puzzle z: 1.45
Racing z: 2.0
More impressive: RacingTry it yourself
import numpy as np
puzzle = np.array([640, 720, 580, 810, 690, 750, 600, 700, 660, 730, 620, 780])
racing = np.array([12400, 15800, 13900, 11200, 16500, 14100,
12800, 15100, 13300, 14700, 12100, 14600])
p = int(input())
r = 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