Semester 1 · Week 07
Exploratory data analysis
- Ch 9 Exploratory Data Analysis & Visualisation
Chapter 9: Exploratory data analysis
A structured conversation with a dataset.
Notes · slide 2
Time: 50 minutes for one chapter. About 20 on the method, 20 on the worked example, and 10 on the mental model and checks.
Say: Most modelling failures aren't algorithmic. They come from what nobody noticed: an imbalanced target, two near-duplicate features, a column that changed units after a migration. EDA is how you notice.
Key line: EDA isn't a step you do once. You come back to it after every surprising result.
Next: the questions, in order.
Five questions, in order
- What do I have? Shape, types, nulls, duplicates.
- What does each variable look like? Distributions, outliers, skew.
- How do variables relate? Correlations, conditional distributions.
- How do they relate to the target? The most useful for modelling.
- What surprised me? Asked last, once there's context to recognise a surprise.
There's no fixed script. The data decides the next step.
Notes · slide 3
Say: What do I have? What does each variable look like? How do they relate? How do they relate to the target? What surprised me?
Say: The last one comes last on purpose. You need the first four answered before you can recognise a real surprise.
Key line: there's no fixed script. A strange distribution sends you back to the source. An unexpected correlation becomes a hypothesis to test.
Ask: "Which question matters most for modelling?" Listen for: the fourth, relationships with the target.
Next: one variable at a time.
Univariate: one variable at a time
- Central tendency: mean and median. If they differ, it's skewed.
- Spread: standard deviation and IQR. Near zero means near constant.
- Shape: bell, skewed, bimodal, or uniform.
- Outliers: errors, or rare informative cases.
For categories: frequencies, cardinality, and rare levels.
Notes · slide 4
Say: For numbers: centre, spread, shape, and outliers. Mean far from median means skew. Spread near zero means the column is nearly constant and gives a model little to use. For categories: how many levels, whether one dominates, and which levels are too rare to learn from.
Ask: "A free-text job title column has 4,000 unique values. What's the issue?" Listen for: cardinality. It needs grouping or a different encoding.
Next: two variables at a time.
Bivariate: pick the chart by type
| Variables | Chart | Summary |
|---|---|---|
| Numeric vs numeric | Scatter | Pearson or Spearman |
| Numeric vs category | Box or violin | Group means |
| Category vs category | Cross-tab, stacked bars | Proportions |
Always plot every variable against the target.
Notes · slide 5
Say: The variable types choose the chart. Two numbers: a scatter, with Pearson for straight lines or Spearman for any steady rise or fall. A number against a category: box or violin plots. Two categories: a cross-tab.
Say: Boxplots hide two-humped shapes. Pair them with a histogram.
Key line: plot every feature against the target. If its distribution doesn't change across target values, it's a weak candidate, however important the customer thinks it is.
Next: many variables at once.
Multivariate
- Pairplot: every pair of numeric variables at once, coloured by a category.
- Correlation heatmap: all pairwise correlations at a glance.
- Holding one variable fixed can reveal effects the marginal view hides.
Notes · slide 6
Say: A pairplot draws every pair of numeric variables at once, coloured by a category. A correlation heatmap shows every pairwise correlation. Two features above about 0.95 are close to redundant.
Say: Holding one variable fixed can reveal what the overall view hides. The Titanic example shows this in a few minutes.
Next: why you can't skip the plots.
Same statistics, different data
Four datasets built to share:
- mean x≈11.07, mean y≈9.69
- standard deviations 5.35 and 3.70
- correlation r≈0.73
Plotted, they look nothing alike. That's Anscombe's point, rebuilt from scratch. Always visualise.
Notes · slide 7
Say: The chapter builds four datasets from scratch so that they share the same means, standard deviations, and correlation, to two decimal places. That's Anscombe's 1973 point, rebuilt.
Do: show only these numbers first. Ask the room to describe the data. Then go to the plots.
Key line: always visualise, even when the summary numbers look informative.
Next: the plots.
Four datasets, one set of statistics

Same means, variances, correlation, and fitted line. Only the plot shows the difference.
Notes · slide 8
Say: A is a real straight line. B is a curve that happens to give the same correlation. C is a near-perfect line with one point dragged away. D is barely a relationship: points stacked at one x, plus one far point that creates the whole correlation.
Ask: "Which of these suits a linear model?" Listen for: only A.
Key line: a summary table reports the same four rows for all of them. Only the chart tells them apart.
Next: when to stop.
How much EDA is enough?
Enough to answer:
- Are there quality problems to clean?
- Which features look promising?
- Are there feature engineering opportunities?
- Does the target behave as expected?
Going further risks data snooping: tuning your choices to data the model should never see. Split before deep EDA.
Notes · slide 9
Say: Enough to answer four questions. Are there quality problems? Which features look promising? Are there feature engineering ideas? Does the target behave as expected?
Say: Go further and you risk data snooping. If you explore the test set too, your later choices quietly fit data the model should never see.
Key line: split before deep EDA.
Ask: "What's wrong with exploring the full dataset before splitting?" Listen for: patterns you find there may not hold on new data.
Next: what EDA should produce.
The output is a list, not a chart
The most valuable result of EDA is a written list of:
- hypotheses
- surprises
- leads to follow up
- modelling decisions the data suggests
Notes · slide 10
Say: The deliverable is a written list: hypotheses, surprises, leads to follow, and the modelling decisions the data suggests. Write them as you go, not from memory at the end.
Say: That list connects EDA to feature engineering in Chapter 14.
Lab: learners make many charts and few findings. Insist on one sentence per chart.
Next: the worked example.
Worked example: Titanic, inspection
891 passengers.
agemissing for 19.9%. Needs imputing.deckmissing for 77.2%. Close to unusable raw.embarkedmissing in 2 rows. Safe to drop.- Only 38.4% survived. Moderate imbalance, so accuracy alone misleads.
Notes · slide 11
Say: 891 passengers. Age is missing for 19.9%, so it needs filling. Deck is missing for 77.2%, so it's close to unusable as it stands. Embarked is missing in 2 rows: safe to drop.
Say: Only 38.4% survived. A moderate imbalance, not extreme. Still enough that accuracy alone would mislead, as in Chapter 2.
Ask: "Would you fill deck or drop it?" Listen for: either, with a reason. A was-missing flag is a fair middle ground.
Next: the signals.
Worked example: Titanic, signals
fareis heavily right-skewed (skewness 4.79). A log transform is coming in Chapter 14.- Women survived at 74.2%, men at 18.9%. The strongest single predictor.
- Survival by class: 63.0%, 47.3%, 24.2%.
agecorrelates with survival at only −0.08.
Notes · slide 12
Say: Fare is heavily right-skewed. A few expensive tickets stretch the tail. That's the reason for a log transform in Chapter 14. Age is close to symmetric.
Say: Women survived at 74.2%, men at 18.9%: a 55-point gap. Class shows a gradient: 63.0%, 47.3%, 24.2%. Age correlates with survival at only −0.08.
Ask: "So is age useless?" Let them commit before the next slide.
Next: the hidden effect.
Worked example: the hidden effect
- Age looks weak on its own.
- Split age by class and survival, and a "children first" effect appears in first and second class.
- It's invisible in the marginal correlation.
That's what multivariate analysis is for.
Notes · slide 13
Say: Age looks weak overall. Split by class and survival, and a children-first effect appears in first and second class. The overall correlation averages it away.
Key line: a weak marginal correlation doesn't mean a weak feature. Hold another variable fixed and look again.
Say: This echoes week 2's penguins: the relationship inside groups differed from the relationship overall.
Next: the write-up.
Worked example: the write-up
The notebook ends with five points, not a chart. Among them:
- Target imbalance needs imbalance-aware metrics.
- Sex is the strongest predictor.
- Class interacts with sex. They don't act independently.
Notes · slide 14
Say: The notebook ends with five written points. Use imbalance-aware metrics. Sex is the strongest predictor. Class interacts with sex. Fare needs a log transform. Fill age by class median and add a was-missing flag.
Key line: that summary, not any single chart, is what EDA hands to feature engineering.
Next: the chapter in one idea.
Mental model
EDA is journalism for datasets.
- Gather evidence. Follow leads. Be surprised.
- Then write it up so someone can make a decision.
- That someone is often future you, building the model.
Notes · slide 15
Say: EDA is journalism for datasets. Gather evidence, follow leads, be surprised. Then write it up so someone can decide. That someone is often you, a week later, building the model.
Next: check yourself.
Check yourself
- Mean income is far above the median. What does that tell you, and what would you plot?
- Why split before doing detailed EDA?
- Two variables have correlation 0. Can they still be related?
- What should an EDA session produce?
Notes · slide 16
Do: pairs, three minutes, then take answers.
Answers: 1. Right skew. Plot a histogram, perhaps on a log scale. 2. To avoid snooping on the test set. 3. Yes. Correlation only sees straight lines. A U-shape scores near zero. 4. A written list of findings, hypotheses, and decisions.
Lab: California housing has capped values. House values and ages pile up at a ceiling. Spotting the cap, and saying what it means for a model, is the main point of the lab.
This week
- Read Chapter 9: Exploratory Data Analysis & Visualisation.
- Take the Chapter 9 quiz.
- Run the notebooks: Chapter 9 (opens in a new tab).
- Optional: the further reading for week 7.
Slide 1 of 17: Exploratory data analysis
Keys: → or Space next · ← back · Home/End · F full screen · N notes. Swipe on touch screens. "Save as PDF" opens the print dialog with one slide per page: choose "Save as PDF" as the printer. "Print handout" adds the speaker notes, in black on white.