2.1.15Data Preprocessing & Feature Engineering

Correlation analysis and multicollinearity

2,746 words12 min readdifficulty · medium1 backlinks

Overview

Correlation analysis examines the statistical relationship between features, while multicollinearity occurs when predictor variables are highly correlated with each other. Both are critical for feature selection and model interpretability.

Figure — Correlation analysis and multicollinearity

Core Concepts


Derivation: Why Correlation Measures Linear Dependence

Start from first principles: We want a measure that:

  1. Is symmetric: measure(X,Y)=measure(Y,X)\text{measure}(X,Y) = \text{measure}(Y,X)
  2. Is scale-invariant: doubling XX's units shouldn't change the relationship strength
  3. Captures "co-movement": when XX is above its mean, YY tends to be above/below its mean

Step 1: Measure co-movement with covariance: Cov(X,Y)=E[(XμX)(YμY)]=E[XY]E[X]E[Y]\text{Cov}(X,Y) = E[(X - \mu_X)(Y - \mu_Y)] = E[XY] - E[X]E[Y]

Why this step? (XμX)(X - \mu_X) is positive when XX is above average, negative when below. Their product (XμX)(YμY)(X - \mu_X)(Y - \mu_Y) is:

  • Positive when both are above/below average (same direction)
  • Negative when one is above, one below (opposite direction)

Averaging this product gives the "typical co-movement."

Step 2: Make it scale-invariant by normalizing: r=Cov(X,Y)σXσYr = \frac{\text{Cov}(X,Y)}{\sigma_X \sigma_Y}

Why this step? Covariance has units of (X-units)×(Y-units)(X\text{-units}) \times (Y\text{-units}). Dividing by both standard deviations removes units and bounds rr to [1,1][-1, 1] (by Cauchy-Schwarz inequality).

Proof of bounds: By Cauchy-Schwarz, Cov(X,Y)σXσY|\text{Cov}(X,Y)| \leq \sigma_X \sigma_Y, so r1|r| \leq 1. Equality holds when Y=aX+bY = aX + b (perfect linear relationship).


Measuring Multicollinearity


Methods and Examples


Common Pitfalls


Detection Workflow

Yes

No

Yes

No

Yes

No

Compute Correlation Matrix

High pairwise abs r over 0.8?

Flag feature pairs

Calculate VIF for each feature

VIF over 10?

Multicollinearity detected

Check Condition Number

Remediation: Drop/Combine/PCA/Regularize

kappa over 30?

No severe multicollinearity

Step-by-step:

  1. Pairwise check: Compute rij|r_{ij}| for all feature pairs. Flag if >0.8> 0.8.
  2. VIF check: For each feature, regress on others, compute VIF. Flag if >10> 10.
  3. Global check: Compute κ(X)\kappa(X) (condition number of the design matrix). If >30> 30, matrix is ill-conditioned.
  4. Action: Drop one feature from each correlated pair, or use PCA, or apply L2 regularization.

Remediation Strategies

  1. Drop one feature from each highly correlated pair (keeps X1X_1, drops X2X_2 if r12=0.95r_{12} = 0.95)
  2. Combine features: Create Xnew=X1+X2X_{\text{new}} = X_1 + X_2 (e.g., "total_rooms = bedrooms + bathrooms")
  3. Principal Component Analysis (PCA): Transform to uncorrelated components
  4. Regularization: Use Ridge (L2L_2 penalty) or Lasso (L1L_1, also does selection)
  5. Domain knowledge: Keep the feature with clearer causal interpretation

Connections

  • Covariance Matrix: Correlation is normalized covariance
  • Feature Selection: Correlation is one criterion for dropping features
  • Principal Component Analysis (PCA): Transforms correlated features to orthogonal components
  • Ridge Regression: Handles multicollinearity via L2L_2 penalty
  • Lasso Regression: Does feature selection under multicollinearity
  • Linear Regression Assumptions: Multicollinearity violates "no perfect colinearity" assumption
  • Variance-Bias Tradeoff: High VIF inflates variance of coefficient estimates
  • Condition Number: Matrix theory perspective on multicollinearity

Recall Explain to a 12-Year-Old

Imagine you're trying to figure out what makes a video game fun by looking at different features: graphics quality, sound quality, story depth, and number of explosions.

Correlation is like asking: "Do games with better graphics also tend to have better sound?" If yes, they're correlated. You measure this with a number from -1 to 1:

  • 1 means: Better graphics ALWAYS means better sound (perfect match)
  • 0 means: Graphics and sound have nothing to do with each other
  • -1 means: Better graphics ALWAYS means worse sound (opposite)

Multicollinearity is when two features are so similar that using both is like counting the same thing twice. Example: "graphics quality" and "texture resolution" are almost the same thing! If you include both, your analysis gets confused—it can't tell which one really matters because they always move together.

Why is this bad? Imagine you're trying to figure out if graphics or story makes games fun. If graphics and story always improve together in your data, you can't separate their effects. It's like trying to figure out if flour or sugar makes cake tasty when you always add them together—you can't tell!

The fix: Drop one of the similar features (just keep graphics, drop texture resolution), or combine them into one "visual quality" score.


Flashcards

What does a correlation coefficient of -0.85 between features X and Y indicate?
Strong negative linear relationship: as X increases, Y tends to decrease proportionally. The features are highly corre

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, correlation analysis ka core idea ye hai ki hum check karte hain do features ek doosre ke saath kitna related hain. Jaise ghar ki price predict karni ho, toh "square footage" aur "number of rooms" — dono naturally connected hain, kyunki bade ghar mein zyada rooms hote hain. Yahi cheez Pearson correlation coefficient rr measure karta hai, jo -1 se +1 ke beech rehta hai. Formula bas covariance (dono features saath mein kitna vary karte hain) ko unki individual standard deviations se divide karta hai, taaki result unit-free ho jaye aur alag-alag feature pairs compare kar sako. Simple intuition: jab X apne average se upar hota hai aur Y bhi upar jaata hai, toh positive correlation; opposite direction mein negative.

Ab multicollinearity kya hai? Ye tab hota hai jab tumhare predictor variables aapas mein hi bahut zyada correlated ho jaate hain. Problem ye hai ki agar tum dono redundant features model mein daal do, toh model confuse ho jaata hai — coefficients unstable ho jaate hain, chhoti si data change pe wildly badal jaate hain, aur sign tak flip ho jaata hai. Interpretability bhi khatam — price area se badhta hai ya rooms se, ye clear nahi rehta. Technically, jab XTXX^TX matrix nearly singular ho jaata hai, toh uska inverse compute karna hi mushkil ho jaata hai, aur high R2R^2 hone ke baawajood individual coefficients insignificant nikalte hain.

Isko detect karne ke liye hum VIF (Variance Inflation Factor) use karte hain, jiska formula hai VIFj=11Rj2\text{VIF}_j = \frac{1}{1 - R_j^2}. Yahaan Rj2R_j^2 tab milta hai jab tum ek feature ko baaki saare features pe regress karo — agar wo easily predict ho jaata hai (high Rj2R_j^2), toh VIF bada ho jaata hai, matlab wo feature redundant hai. Ye sab why-matters isliye hai kyunki feature selection karte time tumhe pehle hi redundancy pakadni hoti hai, warna model unstable ban jaayega aur uske results par bharosa nahi kar paoge. Toh clean, non-redundant features chunna ek accha aur samajhne-laayak model banane ka pehla step hai.

Go deeper — visual, from zero

Test yourself — Data Preprocessing & Feature Engineering

Connections