L1 vs L2 in logistic regression — practical differences.
easyAnswer
- Same intuition as in linear regression: L2 (default) shrinks all coefficients smoothly and stabilizes training under multicollinearity; L1 produces sparse coefficients and performs feature selection during training.
- In scikit-learn, use penalty='l1' with the 'liblinear' or 'saga' solver.
- L1 is nice for interpretable, sparse models on wide (many-feature) data; L2 is the default for prediction accuracy.
- Elastic-Net penalty combines both.
Check yourself — multiple choice
- L1 is faster than L2
- L1 gives sparse coefficients (feature selection); L2 gives stable, smoothly shrunk coefficients
- L1 requires a special metric
- L2 gives sparse coefficients
L1 = sparsity. L2 = smooth shrinkage. Elastic-Net = both.
#logistic-regression#regularization
Practise Supervised Learning
215 interview questions in this topic.
Related questions
- What is 'perfect separation' in logistic regression and how do you fix it?
- How do you detect and fix overfitting?
- L1 vs L2 regularization — what's the difference?
- What is the generalization gap and how do you shrink it?
- How do you handle strong multicollinearity in a linear model?
- What's the main risk of polynomial regression?