Wine Chemistry
Part of the Statistics for ML section of Coddy's Machine Learning journey. Lesson 63 of 64.
A wine importer tested 178 wines from three grape cultivars, 13 chemical readings each: load_wine. Before a model learns the cultivars, the lab hunts for instrument slips.
The readings live on very different rulers, so no single outlier rule fits them all. Standardized, every reading counts standard deviations from its mean.
On that ruler, more than 3 away, on either side, earns a second look. A box per cultivar then shows where each one typically sits.
Challenge
HardThe program reads a feature's name.
- Store its z-scores in
df["z"], using the pandas.std(). - Print how many wines lie beyond 3, either side, then each one in table order: index, reading and z.
- Print each cultivar's mean z.
- Draw one box of z-scores per cultivar, named with
wine.target_names, the feature as title andz-scoreas y label.
Round to 2 decimals. For color_intensity, it prints:
Outliers in color_intensity: 1
Wine 158: 13.0 (z = 3.43)
class_0: 0.2
class_1: -0.85
class_2: 1.01and draws:
Then Coddy describes your boxes.
Try it yourself
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_wine
feature = input()
wine = load_wine(as_frame=True)
df = wine.frame
# 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