Box Plots by Group
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 41 of 64.
Two groups differ: is it real, or luck? This chapter ends with the picture that answers it:
It starts with a look. A pottery studio timed its two kilns. Give ax.boxplot a list of groups, and their names:
gas = np.array([6.5, 7, 7.5, 8, 7, 6.5, 8.5, 7.5])
electric = np.array([9, 10.5, 11, 9.5, 12, 10, 10.5, 15])
fig, ax = plt.subplots()
ax.boxplot([gas, electric], tick_labels=["Gas", "Electric"])
ax.set_ylabel("Hours")
plt.show()The boxes do not even overlap: gas fires faster. For a model, a feature whose boxes barely overlap helps tell the groups apart.
Challenge
MediumA ski resort timed 36 rides on its three lifts. lifts.csv has lift (Red, Green or Blue) and minutes; the starter loads it and sets up the chart.
- Loop over
namesand collect each lift's minutes in a list. - Draw one box per lift, named with
tick_labels=. - Show the chart.
It prints nothing; Coddy describes each box. Two other lifts look like this:
Try it yourself
import pandas as pd
import matplotlib.pyplot as plt
lifts = pd.read_csv("lifts.csv")
names = ["Red", "Green", "Blue"]
# Don't change the lines below
fig, ax = plt.subplots()
ax.set_title("Lift Times")
ax.set_xlabel("Lift")
ax.set_ylabel("Minutes")
# 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 Life8Comparing Groups
Box Plots by GroupDifference in MeansCould It Be Chance?P-ValuesThe t-TestRecap: A/B Test3Probability 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