7 · Case study: Red Wine Quality EDA
Walk through a complete six-step EDA on a wine-quality dataset — shape, target distribution, feature histograms, boxplots, correlation heatmap, hypothesis generation.
A complete EDA pass on a wine-quality dataset — from `df.info()` to feature distributions to target correlation in one notebook.
Without this:
Without practicing a full EDA on a representative dataset, the steps from previous lessons stay abstract; this lesson cements them as a routine.
This is the first real EDA you'll write from scratch. Previous lessons built each technique in isolation — missing values, outliers, encoding. Now we run all six steps in sequence on a single dataset.
The Red Wine Quality dataset is a classic starting point: 10 physicochemical features (acidity, pH, alcohol, sulphates…) and a quality score from a blind tasting panel (3–8). It is small enough to understand row-by-row, rich enough to reveal every EDA pattern that matters.
The six-step EDA checklist:
- Shape, types, missing — understand what you have before touching anything
- Target distribution — know your label's range and class balance before training
- Feature distributions — histograms per feature reveal skewness, modes, outliers
- Feature–target relationships — boxplots of each feature per quality grade
- Feature–feature correlations — heatmap to catch multicollinearity and proxies
- Hypothesis generation — write down 2–3 educated guesses that modelling will test
Run every step in order. Never skip step 1.
Python (in browser)
Step 1 — `df.info()` reveals dtypes and non-null counts; `df.describe()` gives the five-number summary for every numeric column. No missing values here — real wine datasets also happen to be clean.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Step 2 — target distribution. The majority of wines cluster at quality 5–6. Knowing this before training prevents a false sense of accuracy from a 'predict the most common class' baseline.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Step 3 — histograms for 6 of the 9 numeric features arranged in a 2×3 grid. Skewness > 1 (check chlorides, residual_sugar) flags right-tailed distributions that may need log-transformation before a linear model.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Step 5 — correlation heatmap. Features at ρ > 0.7 with another feature signal potential multicollinearity. The `alcohol–quality` correlation is the dataset's headline finding: higher alcohol tends to mean higher quality.
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Python (in browser)
Step 4 — boxplots of `alcohol` per quality grade. The median rises from grade 3 to grade 7, confirming the hypothesis: higher-quality wines tend to have higher alcohol. This is the input to Step 6 (hypothesis generation).
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
The six-step EDA checklist as a reusable code comment block. Paste this at the top of every new notebook and work through each step before writing `model.fit()`.
When the correlation heatmap shows two features at ρ = 0.95 with each other, what's the risk for a linear model?
- A complete EDA always follows the six-step sequence: shape/types/missing → target distribution → feature histograms → feature–target relationships → feature–feature correlations → hypothesis generation.
- `df.info()` + `df.describe()` + `df.isna().sum()` is the minimum Step 1 trio — never open a new dataset without running all three.
- The correlation heatmap's primary job is to find (a) features that correlate with the target (candidates for the model) and (b) pairs of features that correlate with each other (multicollinearity risk for linear models).
- EDA output is a set of explicit, falsifiable hypotheses — not a model. Write them down before running `model.fit()`.
Every Kaggle-style ML notebook opens with this exact six-step EDA. The hypotheses generated here pre-select features and inform model choice (linear → drop collinear; tree → keep all).
If you remove it: Skipping EDA means choosing features by guesswork; the result is a model that performs worse than a baseline of 'predict the mean'.