S30 Logo
S30 AI Labwww.thes30.com
Back
#3

EDA Lab + Homework

Easy🐍 Python & DataW1 D4

Before You Start

Required knowledge
Pandas filtering and aggregation; basic descriptive statistics.
Libraries used
Matplotlib, NumPy, pandas
Dataset and source
Embedded 20-row synthetic churn CSV, read with StringIO; includes missing values and a deliberately leaky column.
Expected output
A data-quality and EDA report covering distributions, missingness, class balance, slices, and leakage.

Lesson Videos

Exploratory Data Analysis (EDA) β€” Theory & Concepts

Read this before attempting the exercises. EDA is the first step in any ML project. These notes cover systematic approaches to understanding your data.


1. Why EDA Matters

Before building any model, you must understand your data:

  • ●Distribution of features (normal? skewed? bimodal?)
  • ●Missing values and their patterns (MCAR, MAR, MNAR)
  • ●Outliers that could distort models
  • ●Correlations between features and the target
  • ●Data quality issues (duplicates, inconsistent formats)

Interview Tip: At FAANG, the first question in an ML design interview is often "how would you explore the data?" A structured EDA approach shows maturity.


2. Univariate Analysis

Examine each feature individually:

# Numerical features
df['age'].describe()          # count, mean, std, min, 25%, 50%, 75%, max
df['age'].hist(bins=50)       # distribution shape
df['age'].skew()              # >0 right-skewed, <0 left-skewed

# Categorical features
df['country'].value_counts()           # frequency counts
df['country'].value_counts(normalize=True)  # proportions

What to look for:

  • ●Skewness β€” may need log transform for linear models
  • ●Outliers β€” values beyond 3Οƒ or IQR Γ— 1.5
  • ●Zero-inflated β€” lots of zeros (common in revenue, counts)
  • ●Cardinality β€” how many unique values (affects encoding strategy)

3. Bivariate Analysis

Examine relationships between pairs of features:

# Numerical vs Numerical
df[['age', 'revenue']].corr()                    # Pearson correlation
df.plot.scatter(x='age', y='revenue')            # scatter plot

# Numerical vs Categorical
df.groupby('country')['revenue'].mean()          # mean revenue by country
df.boxplot(column='revenue', by='country')       # distribution comparison

# Categorical vs Categorical
pd.crosstab(df['country'], df['purchased'])      # contingency table

FAANG Gotcha: Pearson correlation only measures linear relationships. Two features can have zero correlation but strong nonlinear dependence.


4. Missing Data Patterns

# Overview
df.isna().sum().sort_values(ascending=False)

# Missing data heatmap pattern
import seaborn as sns
sns.heatmap(df.isna(), cbar=False)

Types of missingness:

  • ●MCAR (Missing Completely At Random) β€” safe to drop
  • ●MAR (Missing At Random) β€” missingness depends on observed data
  • ●MNAR (Missing Not At Random) β€” missingness depends on the missing value itself

Interview Tip: If income is missing more often for low-income users, that's MNAR β€” dropping those rows biases your model.


5. Correlation Analysis

# Full correlation matrix
corr = df.select_dtypes(include='number').corr()
sns.heatmap(corr, annot=True, cmap='coolwarm', center=0)

What to look for:

  • ●High correlation between features (>0.8) β€” multicollinearity, may need to drop one
  • ●Correlation with target β€” features with near-zero correlation may be useless
  • ●Unexpected correlations β€” data leakage red flag

6. Outlier Detection

# IQR method
Q1 = df['revenue'].quantile(0.25)
Q3 = df['revenue'].quantile(0.75)
IQR = Q3 - Q1
outliers = df[(df['revenue'] < Q1 - 1.5*IQR) | (df['revenue'] > Q3 + 1.5*IQR)]

# Z-score method
from scipy import stats
z_scores = np.abs(stats.zscore(df['revenue']))
outliers = df[z_scores > 3]

Key decision: Remove outliers? Cap them (winsorize)? Keep them? Depends on whether they're errors or genuine extreme values.


7. Feature Engineering Insights from EDA

EDA directly informs feature engineering:

EDA FindingFeature Engineering Action
Skewed distributionLog transform
High cardinality categoricalTarget encoding or hash encoding
Missing values with patternAdd "is_missing" binary feature
Date columnExtract day_of_week, month, is_weekend
Two correlated featuresCreate ratio or difference feature

8. Systematic EDA Checklist

  1. ●Shape & types: df.shape, df.dtypes, df.info()
  2. ●Summary stats: df.describe(), df.describe(include='object')
  3. ●Missing values: df.isna().sum(), pattern analysis
  4. ●Distributions: histograms for numerics, value_counts for categoricals
  5. ●Correlations: heatmap, scatter plots for top pairs
  6. ●Target analysis: class balance, target distribution
  7. ●Outliers: IQR or z-score check on key features
  8. ●Duplicates: df.duplicated().sum()

Now you're ready to attempt the exercises. Switch to the Exercise tab and start coding!

Ready to practice?

Python 3 β€” Notebook
0/8 solvedSubstack Notes
1
Dataset & Setup
2

EDA Lab + Homework (Student)

Goal: practice high-signal EDA like you would in a FAANG ML interview or on-call investigation.

Rules:

  • ●Work top-to-bottom
  • ●Don't hardcode outputs
  • ●Prefer concise, high-signal plots

1) Sanity Checks β€” 10 minutes

Loading editor...
2
Data grain + schema

1) Sanity Checks β€” 10 minutes

Task 1.1: Data grain + schema

Loading editor...
3
Missingness + duplicates
1

Task 1.2: Missingness + duplicates

Loading editor...
4
Numeric summaries

2) Distributions + Outliers β€” 15 minutes

Task 2.1: Numeric summaries

Loading editor...
5
Plot 2 high-signal distributions

Task 2.2: Plot 2 high-signal distributions

Loading editor...
6
Label imbalance

3) Target + Slices β€” 15 minutes

Task 3.1: Label imbalance

Loading editor...
7
Slice analysis

Task 3.2: Slice analysis

Loading editor...
8
Identify leakage-prone features

4) Leakage + Time β€” 10 minutes

Task 4.1: Identify leakage-prone features

Loading editor...

Need help? Share feedback