The Most Common Value
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 5 of 64.
T-shirt sizes are labels: there is no mean of M and XL. A category column's center is its mode, the most common value:
.mode() finds it:
sizes = pd.Series(["M", "L", "M", "S", "XL", "M", "L", "S"])
print(sizes.mode()[0])This prints:
MValues can tie, so .mode() returns a Series of every winner, sorted. [0] takes the first.
The mode fills gaps in a category column. It is also the simplest model of all: always guess the most common class.
Challenge
EasyA ski shop wants to know what to keep in stock. rentals.csv logs 30 rentals with the columns item, boot_size, level and days.
- For each column, in order, print its name, its mode, and how many rentals have that value.
- Then compare the mean of
days, rounded to 1 decimal, with its mode.
For a shorter log of 8 rentals:
item: snowboard (5 of 8)
boot_size: 42 (4 of 8)
level: beginner (5 of 8)
days: 1 (4 of 8)
Days rented, mean vs mode: 2.8 vs 1No rental lasts 2.8 days: the mode is a value that really happens.
Try it yourself
import pandas as pd
rentals = pd.read_csv("rentals.csv")
# 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