Exploratory Data Analysis
Docs: pandas group by Β· Missing data Β· Visualization Β· Real data: AI4I 2020 Predictive Maintenance, UCI Bike Sharing
Overviewβ
EDA is hypothesis generation with a deadline. Every plot either changes a decision downstream or gets deleted. Timebox it: a day on a new problem, half a day on a familiar one. The output is a half-page decision log, not the notebook. The failure people hit is tourism: a 200-cell notebook with no decisions in it, and a broken label discovered in week three.
Key conceptsβ
Decisions at a glanceβ
| Question | Look at | You're hunting for | #1 failure mode |
|---|---|---|---|
| Is the target sane? | Base rate, label counts over time | Impossible labels, base-rate jumps | Modelling a broken label for two weeks |
| What shape is each feature? | Histograms, log scale for counts and hours | Skew, bimodality, impossible values | Trusting describe() means on skewed data |
| Where are the gaps? | Missingness rate and pattern per column | Structure in what's missing | Treating all gaps as random noise |
| Which machines fail? | Failure rate by segment | Segments with 3Γ the base rate | Reporting one global rate |
| What predicts too well? | Feature-vs-target separation | Leaks disguised as signal | Celebrating instead of auditing |
| Is the data stable? | Distributions by month | Shifts, pipeline changes, regime breaks | Training across an undetected break |
Start with the targetβ
Ten minutes on the label beats ten hours on the features. "Failed" is not a fact of nature. It's a definition from the framing stage plus a join between the CMMS and the ERP, and it inherits their bugs.
| Check | On the plant data | Decision it drives |
|---|---|---|
| Base rate | 3% | Metric (PR-AUC, never accuracy), imbalance handling, stakeholder expectations |
| Base rate by month | 2.7β3.3%, stable | None needed. A month at 8% would mean a data bug or a real event, and either changes the project |
| Label sanity | 14 machines marked failed logged output after their breakdown date | Trace the broken ERP join before modelling. Fourteen rows won't move the model; the join might |
Distributions, one feature at a timeβ
describe() lies on skewed data. The mean of load_cycles_30d is 41,000; the median is 3,400. Plot every feature, on a log scale for counts and hours.
Figure L1-1: The same column, plotted raw and on a log scale. Only the log view shows two populations.
| Feature | What the histogram showed | Handed to |
|---|---|---|
load_cycles_30d | A wall at zero, then bimodal on a log scale: single-shift vs 24/7 lines | A segment hypothesis, and a transform decision |
machine_age_days | Three negative values. Impossible, so an ERP bug | Outlier handling: fix at source |
| 24/7 tail | Real data, the plant's most critical assets | A note so nobody "cleans" it later |
EDA finds the shape. Fixes are preprocessing decisions. Keep the two jobs separate and hand findings across in writing.
Missingness has a patternβ
Don't just count the gaps. Ask which machines have them, and whether the target differs.
| Column | Missing | Which machines | Failure rate missing vs present | Verdict |
|---|---|---|---|---|
vibration_rms_30d | 0.3% | Scattered across March: a sensor-gateway outage | No difference | Random. Ignorable |
oil_analysis_score | 11% | Every machine installed in the last 90 days | 8% vs 2.7% | Structure. The gap predicts failure (infant mortality on the bathtub curve) |
The mechanism taxonomy (MCAR/MAR/MNAR) and the imputation menu live on the preprocessing page. EDA's job is the diagnosis.
Segments: which machines actually failβ
One global failure rate hides the different fleets inside the plant. The segment table is the most useful EDA artifact for the maintenance planners.
Figure L1-2: Failure rate by segment. Orange segments fail above the 3% base rate, blue below.
Each bar is a hypothesis for the feature page and a slice for sign-off. The bars are also sanity anchors. When a model scores a freshly serviced single-shift pump at 0.9, one of you is wrong, and it's probably the model.
Relationships and the leak scanβ
In EDA, "wow" and "uh-oh" are the same signal. A feature that separates classes beautifully is a leak until proven otherwise.
Figure L1-3: Each feature's distribution split by outcome. Blue is machines that ran, orange is machines that failed. Overlap is what real signal looks like; a clean split is a leak until its lineage is traced.
| Scan | On the plant data | Verdict |
|---|---|---|
| Feature vs target | Most features correlate weakly (|r| under 0.2) | Normal. Real signal on hard problems is diffuse |
| Feature vs target | avg_vibration_last_30d separates failures almost perfectly | β The AUC 0.99 leakage bug. Trace its lineage before it nears a model |
| Feature vs feature | Vibration windows correlate at 0.9+ | Previews the Ridge/ElasticNet decision |
For any suspicious feature, ask three things: where the column came from, when it's computed, and whether it could know the future.
Stability over timeβ
Anything that shifted during the training window will shift again after you ship. Plot key feature medians and the base rate by month.
| Finding | What it is | Where it goes |
|---|---|---|
vibration_rms_30d dips in March | The gateway outage again | Drift monitor list |
| Load drifts upward | Order volume growing | Drift monitors |
| A regime break (line upgrade, new shift pattern) | Training rows from two different worlds | An argument for the time-based split |
The deliverable: a decision logβ
Nobody reads your notebook. They read your conclusions. Every row ties a finding to a decision and an owner page.
| Finding | Decision | Owner page |
|---|---|---|
| Base rate 3%, stable by month | PR-AUC as metric, scale_pos_weight β 32 | Training |
load_cycles_30d bimodal, log-normal | log1p transform for linear models | Preprocessing |
oil_analysis_score missing = new installs, 8% failure | Impute + indicator, never drop | Preprocessing |
avg_vibration_last_30d separates too well | Leak. Rebuild from raw sensor events | Preprocessing |
| 24/7 duty 5.5%, first 90 days 8% | Feature hypotheses + evaluation slices | Features, Training |
| 3 negative ages, 14 label conflicts | Fix at source before training | Data owners |
If a plot doesn't produce a row here, it was tourism.
Gotchasβ
- Starting with features. A broken label wastes everything downstream. Audit the target first.
- Reading means off
describe(). Skewed columns hide their shape. Plot histograms on a log scale. - Counting missing values without grouping. The rate hides the pattern. Split the failure rate by missing vs present.
- Celebrating a perfect separator. It's usually a leak. Trace the column's lineage before it reaches a model.
- Fixing data inside EDA. Fixes made in the notebook don't reach production. Log the finding; preprocessing owns the fix.
Scenario questionsβ
Q1 β You have one day of EDA on a new failure dataset. What do you look at first?
Model answer
- Clarify: how is "failed" defined, and which systems produce the label?
- Observe: the base rate (3%), the base rate by month (stable 2.7β3.3%), and any impossible labels (14 machines producing output after breakdown).
- Hypothesise: the label join with the ERP is the likeliest source of trouble.
- Fix: trace and fix the join before any feature work.
- Prevent: the label audit is the first row of every decision log. The trade-off is an hour less on features.
Q2 β β One feature separates failed machines almost perfectly. Your manager is thrilled. What do you do?
Model answer
- Clarify: where does the column come from, and when is it computed?
- Observe:
avg_vibration_last_30dcomes from a dashboard query, computed at query time, not at the snapshot date. - Hypothesise: the window crosses the breakdown, so the feature sees the outcome.
- Fix: mark it as a leak in the decision log; preprocessing rebuilds it from raw events.
- Prevent: a standing leak scan where every suspicious separator gets its lineage traced. The trade-off is telling the manager the good news isn't real.
Q3 β
β
oil_analysis_score is missing for 11% of rows. A colleague proposes dropping them. Your view?
Model answer
- Clarify: which machines are missing it?
- Observe: all of them were installed in the last 90 days. They fail at 8% vs 2.7%.
- Hypothesise: the gap encodes machine newness. It isn't random noise.
- Fix: keep the rows; preprocessing imputes and adds a missing-indicator.
- Prevent: every gappy column gets the missing-vs-present failure split. The trade-off is two more groupbys per column.
Q4 β β β The base rate is 3% every month except April, which is 8%. How do you proceed?
Model answer
- Clarify: did anything change in April: plant, data pipeline, label definition?
- Observe: check whether the spike sits in one site or segment, and whether the label join or a source system changed.
- Hypothesise: a data bug (duplicated failure records, a changed join) or a real event (heatwave, a bad parts batch).
- Fix: a bug gets fixed at source. A real event gets documented and the training window or validation split reconsidered.
- Prevent: base rate by month is a standing check, and later a production monitor. The trade-off is delaying modelling until April is explained.
Summaryβ
- Target first. Base rate, stability, label sanity. A broken label wastes everything downstream.
- Plot, don't describe. Means lie on skewed data. Histograms don't.
- Ask which machines, not how many. Missingness and failure rates by segment, never just overall.
- Run the leak scan. Any feature that separates too well gets its lineage traced before it touches a model.
- Ship a decision log. Half a page of finding β decision β owner. The notebook is scaffolding.
Next β Data Preprocessing