1. Exploratory Data Analysis (EDA)

Intuition: Before writing a single line of model code, look at your data. EDA helps you understand distributions, spot outliers, find relationships between features, and form hypotheses about which models might work.

1.1 Key EDA Tasks

TaskWhat to doPython / pandas call
Shape & typesRows, columns, dtypesdf.shape, df.dtypes, df.info()
Summary statsMean, std, min, max, quartilesdf.describe()
Missing valuesCount & % per columndf.isnull().sum()
Unique valuesCardinality of categoricalsdf['col'].nunique(), df['col'].value_counts()
DistributionHistograms, box plotsdf['col'].hist(), df.boxplot()
CorrelationPearson / Spearman heatmapdf.corr(), sns.heatmap(df.corr())
PairplotsFeature-to-feature scattersns.pairplot(df)
Class balanceFor classification targetsdf['target'].value_counts(normalize=True)

1.2 Mathematical Foundations of EDA

When inspecting distributions and relationships, rely on these formal mathematical metrics:

A. Covariance and Correlation

  • Covariance: Measures the joint variability of two variables and .
  • Pearson Correlation (): The normalized covariance, measuring linear correlation (bounded between -1 and +1).
  • Spearman Rank Correlation (): Non-parametric measure of monotonic relationships. It computes Pearson correlation on the rank values of and , making it robust to outliers. (where )

B. Distribution Shape Metrics

  • Skewness: Measures the asymmetry of the distribution about its mean. Normal distribution has a skewness of 0.
    • : Right-skewed (long tail on the right, e.g., income). Often requires log transform.
    • : Left-skewed (long tail on the left).
  • Kurtosis: Measures the “tailedness” of the distribution. Normal distribution has a kurtosis of 3 (or excess kurtosis of 0).
    • : Leptokurtic (heavy tails, more prone to outliers).
    • : Platykurtic (light tails).

C. Variance Inflation Factor (VIF)

Used to detect Multicollinearity (when a feature can be linearly predicted by other features). (where is the of regressing feature on all other features)

  • VIF < 5: Low multicollinearity.
  • VIF > 10: Severe multicollinearity; consider dropping feature or applying PCA.

1.3 What to look for

  • Skewness — highly skewed features may need log-transform before training.
  • Outliers — IQR fences: values below or above are suspected outliers.
  • Target leakage — a feature that encodes the answer (e.g., loan_approved predicting default) — drop it.