Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Machine Learning Notes
Topic #507

EDA for Machine Learning

EDA is only useful if its findings actually change what you do next. This note is the bridge — a direct map from common things you'll discover during exploration to the concrete preprocessing and modeling decisions each one should trigger.

The Decision Table

What EDA RevealsWhat to Actually Do
Numeric feature is strongly right-skewedUse median imputation for gaps; consider a log transform; prefer robust scaling over standardization
Feature has many outliers (boxplot/IQR)Decide: cap (winsorize), remove, transform, or switch to a tree-based model that's naturally robust to them — see Outlier Treatment
Two features highly correlated (r > 0.9)Drop one, combine them, or apply regularization/PCA to handle the resulting multicollinearity
High-cardinality categorical featureAvoid one-hot encoding; use frequency or target encoding instead
Class imbalance in the targetUse stratify=y in your split; consider class weights or SMOTE; avoid plain accuracy as your evaluation metric
A feature shows almost no linear correlation with the targetDon't drop it yet — check for a non-linear relationship visually, or let a tree-based model's feature importance judge it
Missing values cluster in a specific subgroupInvestigate whether missingness is MAR/MNAR before choosing an imputation strategy — see Missing Values
Bimodal numeric distributionLook for a hidden categorical variable that explains the two groups — it may deserve to become its own feature

A Full Worked Example — From EDA Finding to Pipeline Step

import pandas as pd
import numpy as np

df = pd.read_csv("loans.csv")

# EDA step: check skew of a key numeric feature
print(df["annual_income"].skew())    # e.g. 4.2 -- strongly right-skewed

# EDA step: check target balance
print(df["defaulted"].value_counts(normalize=True))   # e.g. 0: 0.93, 1: 0.07 -- imbalanced

# EDA step: check correlation between two candidate features
print(df[["loan_amount", "annual_income"]].corr())      # e.g. 0.85 -- fairly high

# ---- Decisions this EDA directly justifies ----
# 1. annual_income is skewed -> log-transform it, and use RobustScaler, not StandardScaler
df["log_income"] = np.log1p(df["annual_income"])

# 2. defaulted is imbalanced -> stratify the split, and don't trust plain accuracy later
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
    df.drop(columns=["defaulted"]), df["defaulted"], test_size=0.2, stratify=df["defaulted"], random_state=42
)

# 3. loan_amount and annual_income are fairly correlated -> keep an eye on this for a linear model,
#    or don't worry about it at all if using a tree-based model (which handles correlated features fine)

Notice that every line of "action" code traces back directly to a specific number or chart from the EDA step above it — this traceability is the actual point of doing EDA at all, not visualization for its own sake.

A Simple Discipline: Write Down the "So What"

For every chart or statistic you produce during EDA, force yourself to write one sentence answering "so what does this mean for my preprocessing or model choice?" If you can't answer that sentence, either the analysis wasn't actually useful, or you haven't finished thinking it through yet — both are worth noticing before you move on.

Practical Use Cases

  • Justifying preprocessing choices in a project write-up or interview, rather than picking them by habit
  • Prioritizing which features are worth the effort of careful feature engineering
  • Setting realistic expectations for evaluation — e.g. knowing upfront that plain accuracy will be misleading on an imbalanced target

Common Mistakes

  • Producing dozens of EDA charts that never translate into an actual preprocessing or modeling decision — impressive-looking, low-value work.
  • Making a preprocessing decision (like dropping a "low-correlation" feature) based on a linear correlation number alone, without checking for a non-linear relationship first.
  • Doing this analysis on the full dataset instead of the training set only — see Data Leakage.

Interview Relevance

Q: "How does EDA actually influence your modeling choices, concretely?" A strong answer gives specific pairs — e.g. "I found the target was imbalanced, so I stratified my split and used F1 instead of accuracy" — rather than a vague "EDA helps me understand the data" without a concrete decision attached.

Practice Question

Your EDA reveals: (a) a numeric feature with 15% missing values concentrated among customers who churned, and (b) two categorical features that are almost always identical for each row. For each finding, state the specific action you'd take.

Want to practice turning EDA into real modeling decisions? CodingNow's Data Science course works through this exact EDA-to-pipeline process on real project datasets.

Related ML Notes

Want to go beyond the notes?

Join CodingNow's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →