Chapter 3 of 42 · ~18 min read & lab+60 XP
Chapter 3 · Machine Learning

Datasets, Features, Labels & Exploratory Data Analysis (EDA)

Understand rows, columns, feature types (numerical vs. categorical), target labels, and the 5-minute EDA checklist every ML engineer runs before modeling

What Is It?

A tabular dataset is a table where each row is one observation, input columns are Features (X), the answer column is the Label (y), and Exploratory Data Analysis (EDA) is the systematic inspection of distributions, types, missingness, and correlations before modeling.

Why Is It Required?

Blindly feeding raw CSV files into a model guarantees silent bugs: ID columns masquerading as numbers, target leakage columns, 99% missing columns, or extreme skewness.

Everyday Analogy: Before cooking a meal, you open every container, smell the milk, and check the ingredients — EDA is smelling the milk before you train.
Why ML Engineers & Data Scientists Actually Need This

Garbage in, garbage out — 30 minutes of disciplined EDA beats 30 hours of hyperparameter tuning.

ML / AI Engineer

Catching schema drift, mixed types ('N/A' strings inside numeric columns), and ID leakage during EDA prevents production outages.

Data Scientist

EDA reveals the business story: class imbalance ratios, bimodal customer groups, and high-signal domain features.

Interview & Debug Edge

Live coding & take-home interviews explicitly grade whether you inspect data distributions and missingness before calling .fit().

Step 0 · Test Your Gut Before Any Math!

Which column should almost NEVER be passed raw as a numeric feature into a Linear Regression or Random Forest?

What You Will Master in This Chapter
  • Identify observations (rows), features (X), and targets (y) in any tabular dataset.
  • Classify every feature into Numerical (continuous/discrete), Categorical (nominal/ordinal), Datetime, or Text.
  • Execute a repeatable 5-step EDA checklist: shape/types, missingness, target balance, outliers/skewness, and correlations.
  • Spot 'junk' or 'leaky' columns (like user_id or cancellation_date) during EDA before they ruin your model.
Plain-English Symbol Decoder · Click Any Symbol Before We Begin
1 / 3
NSay aloud:“Number of samples (rows)”
Plain-English Meaning
How many individual examples (users, houses, transactions) are in your dataset.
Everyday Example
N = 50,000 houses.
Story-First Intuition, Visual Diagrams & Interactive Walkthroughs

Before a single equation touches your data, you need to know what every column actually represents. A dataset is not just a matrix of floats — it is a messy record of real-world processes. EDA turns a mysterious CSV into a clear map of feature types, missing gaps, skew, class balance, and potential leakage.

1. The 4 Feature Data Types (Don't Confuse Digits With Numbers!)

Everyday Story First (Zero Math Yet!)

Imagine a spreadsheet of online orders with columns: order_id, price_usd, shirt_size (S/M/L), and country. Two of them look like numbers, two look like text — yet each requires completely different treatment!

Every column in a tabular dataset belongs to one of four families:

  1. Numerical — Continuous: Measurements on a real scale (height_cm, price_usd, temperature). Math like averages and differences makes sense.
  2. Numerical — Discrete: Whole counts (num_clicks, bedrooms).
  3. Categorical — Nominal (No Order): Distinct buckets with no ranking (city, payment_method, zip_code). Needs One-Hot or Target Encoding.
  4. Categorical — Ordinal (Ordered): Categories with a natural rank (S < M < L < XL, Low < Medium < High). Preserving order matters!

2. The 5-Minute Beginner EDA Checklist

Everyday Story First (Zero Math Yet!)

Think of EDA as a pilot's pre-flight checklist: skip one item and you might not notice a missing wheel until takeoff.

Run these 5 checks on every new dataset before writing any modeling code:

  1. Shape & Dtypes: How many rows NN and columns DD? Are numeric columns accidentally stored as strings?
  2. Missing Values & Duplicates: Which columns have NaN? Are there duplicate rows that could leak across train and test?
  3. Target Distribution (yy): For classification, is it balanced (50/50) or imbalanced (99/1)? For regression, is yy heavily right-skewed?
  4. Outliers & Impossible Values: Are there negative ages (age = -5) or sentinel codes like 999999?
  5. Correlations & Leakage Scan: Does any feature correlate 0.990.99 with yy because it was recorded after the event?
Walk Through With Me · Interactive Worked Example

Running the 5-Minute EDA Audit on a Churn Table

You receive customers.csv with 10,000 rows and 8 columns to predict churned (0/1).

1Inspect target balance firstStep 1 / 3

You find 94% churned=0 and 6% churned=1. Immediately you know Accuracy is useless — you will track PR-AUC and Recall.

Teacher's Note: Always check the target distribution before anything else.
“Wait, I'm Confused...” · Teacher Office Hours Q&A

The exact honest questions almost every beginner wonders — answered in plain English without hiding behind jargon.

No! Lock away your test set first and perform all exploratory inspection, threshold discovery, and feature decisions strictly on the training split so you never overfit your intuition to test data.

Interactive Visual Lab
Lab Challenge: Inspect how clean, well-typed features flow through an end-to-end ML pipeline.
Interactive Deep Lab · Production ML Lifecycle Checklist

Activate All 5 Pillars of a Ship-Ready ML Project

Readiness: 40%
Click each missing stage above to complete your end-to-end production ML lifecycle!
Intuition Takeaway: Before training any model, map every column's true data type (numerical, nominal, ordinal, datetime) and run the 5-minute EDA audit: shape, missingness, target balance, impossible outliers, and leakage.
Production NumPy & PyTorch Code Patterns
import numpy as np

# Lightweight 5-Minute EDA Audit (Pure NumPy)
# Columns: [sqft, bedrooms, age_years] | Target: price_k
X = np.array([
    [1200, 2, 15],
    [1850, 3, 8],
    [np.nan, 4, 2],
    [2400, 4, -5],      # impossible negative age!
    [15000, 5, 1],      # extreme outlier!
], dtype=float)
y = np.array([250.0, 380.0, 490.0, 520.0, 3200.0])

names = ["sqft", "bedrooms", "age_years"]
print(f"Dataset shape: N={X.shape[0]} rows, D={X.shape[1]} features")
for j, col in enumerate(names):
    vals = X[:, j]
    n_missing = int(np.isnan(vals).sum())
    clean = vals[~np.isnan(vals)]
    print(f"  {col:10s} | missing={n_missing} | min={clean.min():.1f} | median={np.median(clean):.1f} | max={clean.max():.1f}")
print(f"Target y -> mean={y.mean():.1f}, median={np.median(y):.1f} (mean >> median signals right skew!)")
Common ML Interview Traps & Numerical Pitfalls
Trap #1: Jumping straight into XGBClassifier().fit(X, y) without checking missing values, target skew, or ID columns.
Best Practice: Always narrate your 5-step EDA audit first — interviewers treat disciplined EDA as a top seniority signal.
Trap #2: Treating ordinal categories ('Low', 'Med', 'High') and nominal categories ('Red', 'Blue', 'Green') identically.
Best Practice: Preserve order for ordinal features; use One-Hot or Target encoding for nominal features.
Chapter Mastery Check (+60 XP)
Score: 0 / 1
1You notice a numeric column price has median = $45 and mean = $1,820. What does this immediately tell you during EDA?

Apply What You Learned — Solve Matching Coding Problems