Statistics · medium
Asked in Data Scientist interviews, in the Statistics round.
Check VIF/correlation; drop/combine features, use regularization or PCA.
Multicollinearity is predictors that are nearly linear combinations of each other. The model still predicts fine; what breaks is the coefficients. They become unstable, flip sign between samples, and their standard errors inflate, so any story about which feature matters is unreliable.
Detect it with the variance inflation factor: regress each predictor on the others and compute 1 / (1 - R squared). A VIF above 5 is worth a look, above 10 is a problem. A correlation matrix catches pairs but misses a variable that is predicted by three others together, which is why VIF is the tool.
from statsmodels.stats.outliers_influence import variance_inflation_factor
vif = {col: variance_inflation_factor(X.values, i) for i, col in enumerate(X.columns)}
Handling it depends on why you fitted the model:
Say clearly that it does not bias predictions. A stakeholder asking "does the model still work?" gets a different answer from one asking "does price matter more than distance?".