Skip to main content

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​

QuestionLook atYou're hunting for#1 failure mode
Is the target sane?Base rate, label counts over timeImpossible labels, base-rate jumpsModelling a broken label for two weeks
What shape is each feature?Histograms, log scale for counts and hoursSkew, bimodality, impossible valuesTrusting describe() means on skewed data
Where are the gaps?Missingness rate and pattern per columnStructure in what's missingTreating all gaps as random noise
Which machines fail?Failure rate by segmentSegments with 3Γ— the base rateReporting one global rate
What predicts too well?Feature-vs-target separationLeaks disguised as signalCelebrating instead of auditing
Is the data stable?Distributions by monthShifts, pipeline changes, regime breaksTraining 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.

CheckOn the plant dataDecision it drives
Base rate3%Metric (PR-AUC, never accuracy), imbalance handling, stakeholder expectations
Base rate by month2.7–3.3%, stableNone needed. A month at 8% would mean a data bug or a real event, and either changes the project
Label sanity14 machines marked failed logged output after their breakdown dateTrace 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.

raw load_cycles_30dlog(1 + load_cycles_30d)median 3,400mean 41,000single-shift24/7 lines0 β†’ 2.1M cycleslog scalemachines

Figure L1-1: The same column, plotted raw and on a log scale. Only the log view shows two populations.

FeatureWhat the histogram showedHanded to
load_cycles_30dA wall at zero, then bimodal on a log scale: single-shift vs 24/7 linesA segment hypothesis, and a transform decision
machine_age_daysThree negative values. Impossible, so an ERP bugOutlier handling: fix at source
24/7 tailReal data, the plant's most critical assetsA 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.

ColumnMissingWhich machinesFailure rate missing vs presentVerdict
vibration_rms_30d0.3%Scattered across March: a sensor-gateway outageNo differenceRandom. Ignorable
oil_analysis_score11%Every machine installed in the last 90 days8% 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.

First 90 days8%24/7 duty5.5%Single shift1.5%Pumps1.2%base rate 3%

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.

vibration_trend: overlapavg_vibration_last_30d: clean splitranfailedfailed β‰ˆ 0ranreal signal: keeptoo good: trace lineage

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.

ScanOn the plant dataVerdict
Feature vs targetMost features correlate weakly (|r| under 0.2)Normal. Real signal on hard problems is diffuse
Feature vs targetavg_vibration_last_30d separates failures almost perfectly❌ The AUC 0.99 leakage bug. Trace its lineage before it nears a model
Feature vs featureVibration 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.

FindingWhat it isWhere it goes
vibration_rms_30d dips in MarchThe gateway outage againDrift monitor list
Load drifts upwardOrder volume growingDrift monitors
A regime break (line upgrade, new shift pattern)Training rows from two different worldsAn 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.

FindingDecisionOwner page
Base rate 3%, stable by monthPR-AUC as metric, scale_pos_weight β‰ˆ 32Training
load_cycles_30d bimodal, log-normallog1p transform for linear modelsPreprocessing
oil_analysis_score missing = new installs, 8% failureImpute + indicator, never dropPreprocessing
avg_vibration_last_30d separates too wellLeak. Rebuild from raw sensor eventsPreprocessing
24/7 duty 5.5%, first 90 days 8%Feature hypotheses + evaluation slicesFeatures, Training
3 negative ages, 14 label conflictsFix at source before trainingData 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_30d comes 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