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
| Task | What to do | Python / pandas call |
|---|---|---|
| Shape & types | Rows, columns, dtypes | df.shape, df.dtypes, df.info() |
| Summary stats | Mean, std, min, max, quartiles | df.describe() |
| Missing values | Count & % per column | df.isnull().sum() |
| Unique values | Cardinality of categoricals | df['col'].nunique(), df['col'].value_counts() |
| Distribution | Histograms, box plots | df['col'].hist(), df.boxplot() |
| Correlation | Pearson / Spearman heatmap | df.corr(), sns.heatmap(df.corr()) |
| Pairplots | Feature-to-feature scatter | sns.pairplot(df) |
| Class balance | For classification targets | df['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_approvedpredictingdefault) — drop it.