Statistics ยท medium

How do you detect and handle multicollinearity?

Asked in Data Scientist interviews, in the Statistics round.

Short answer

Check VIF and correlations, then drop or combine features, or use regularization or PCA.

How to answer it

Definition

Two or more predictors carrying much the same information. The model can still predict well; what breaks is the interpretation of individual coefficients, because the data cannot separate their contributions.

How to detect it

# 1. correlation matrix: catches pairwise collinearity only
X.corr()

# 2. VIF: catches a variable explained by a COMBINATION of others
from statsmodels.stats.outliers_influence import variance_inflation_factor
[variance_inflation_factor(X.values, i) for i in range(X.shape[1])]
VIF = 1 / (1 - R2_i)      R2_i from regressing predictor i on all the rest

VIF  1      uncorrelated with the others
VIF  5      often flagged
VIF 10+     usually treated as a problem

The symptom

A high R-squared with individually insignificant coefficients, or a coefficient whose sign flips when you add another variable. That combination is close to diagnostic.

Handling it

Key points

FAQ

The 30-second answer

Multicollinearity is when predictors carry overlapping information, so the model cannot attribute effect between them. I detect it with a correlation matrix for pairs and VIF for the cases where one variable is explained by a combination of several, which a pairwise correlation will not show. Above about five is worth a look and above ten usually needs action.
The symptom I watch for is a good overall R-squared with individually insignificant coefficients, or a sign that flips when another variable is added.
How I handle it depends on the goal. If I only need predictions I might do nothing, because it does not hurt accuracy. If I need to interpret coefficients I would drop one, combine them into an index, or use ridge, which shares weight between correlated predictors rather than letting them fight.

In the interview

Practice this for real