Regularized Logistic Regression

Machine Learning
Introduced by
Tibshirani, R. (lasso); Hoerl & Kennard (ridge); Zou & Hastie (elastic net)
Year
1996–2005
Type
Penalized classification model
Family
Machine learning

What does it do?

Regularized logistic regression extends standard logistic regression by adding an L1 (lasso), L2 (ridge), or elastic net penalty to the log-likelihood, which shrinks coefficients toward zero and reduces overfitting.

It is a common choice for binary classification when probabilistic outputs are needed and the feature space is large or strongly correlated.

The intuition behind the method

Standard logistic regression maximizes the probability of observed class labels. In high-dimensional settings — many features, few observations, or correlated predictors — the estimated coefficients can blow up or fluctuate wildly, causing poor generalization. Regularization constrains the coefficient magnitudes by adding a penalty that grows with coefficient size, trading a small amount of training-set fit for much better generalization. L1 penalty drives some coefficients exactly to zero (automatic feature selection), L2 penalty shrinks all coefficients smoothly without zeroing them, and elastic net blends both behaviors.

History

Tibshirani's 1996 lasso paper proposed an L1-constrained least squares estimator for linear models that sets some coefficients exactly to zero; the paper notes that the idea extends briefly to generalized regression models, including logistic regression. Ridge (L2) penalization predates the lasso and is the basis of the L2 option described above. The elastic net, which combines the L1 and L2 penalties to address the lasso's behaviour with grouped correlated features, is a later development. Implementations appear in scikit-learn, glmnet (R), and LIBLINEAR.

When to use it

Use regularized logistic regression for binary classification when you need probabilistic outputs with coefficients that show the direction and relative size of shrunken log-odds effects, when the number of features is large relative to the sample size, or when predictors are correlated. It is a reasonable baseline in clinical prediction, text classification with bag-of-words features, and high-dimensional biomarker studies. Choose L1 when automatic feature selection is needed, L2 for stable coefficient estimation when many predictors matter, and elastic net when features arrive in correlated groups. Avoid it when the outcome–feature relationship is strongly nonlinear or involves interaction effects that the additive log-odds form cannot represent; tree ensembles or kernel methods may then be more appropriate.

Limitations and considerations

  • Assumes a linear relationship between features and log-odds; cannot capture nonlinear or interaction effects without manual feature engineering.
  • Requires the outcome to be categorical; continuous outcomes need linear (not logistic) regression.
  • Performance degrades when relevant features strongly interact, since the model is additive in log-odds.
  • Optimal lambda must be selected by cross-validation, adding computation and a tuning step.
  • With strongly imbalanced classes, fitted probabilities can favour the majority class unless the loss is reweighted or the decision threshold is adjusted.
  • Penalized coefficients are biased toward zero, and standard errors, confidence intervals and p-values are not provided by default; valid inference requires separate methods such as the bootstrap or post-selection inference.
  • Under perfect or quasi-complete separation, unpenalized estimates diverge; penalization keeps them finite, but the estimates can depend strongly on lambda.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Models class probabilities directly through the sigmoid link, and coefficients show the direction and relative size of shrunken effects on the log-odds, which makes them easier to inspect than many black-box classifiers.
  • L1 penalty performs automatic feature selection, yielding sparse models that are easy to report.
  • Handles high-dimensional feature spaces (p >> n) through coefficient shrinkage, which limits the variance of the estimates.
  • Elastic net penalty handles correlated feature groups better than lasso alone, spreading weight across related predictors.
  • Fitting uses iterative solvers that remain practical on large tabular datasets, so it is often a useful fast baseline before more complex models are tried.

Applications

  • Clinical risk scores and diagnostic classifiers from high-dimensional biomarker panels.
  • Text classification with bag-of-words or TF-IDF features, where L1 produces interpretable sparse word weights.
  • Genomics and proteomics where the number of features vastly exceeds the sample size.
  • Credit scoring and fraud detection requiring probability outputs for threshold-based decisions.
  • Baseline classification benchmark before evaluating more complex ensemble or deep learning models.

How it works

How it works

1

A linear combination of features predicts the log-odds of the positive class. The sigmoid function converts log-odds to a probability between 0 and 1, making output directly interpretable as class probability.

Formula
\log\frac{p}{1-p} = \mathbf{x}^\top\boldsymbol{\beta}
2

The optimization objective is the negative log-likelihood (cross-entropy) plus a penalty term. The penalty scales with the coefficient magnitudes, controlled by the hyperparameter lambda (strength) and alpha (L1/L2 mix). A larger lambda imposes heavier shrinkage; alpha=1 gives pure lasso, alpha=0 gives pure ridge. The penalty is applied to the slope coefficients only; the intercept is not penalized.

Formula
\mathcal{L}(\boldsymbol{\beta}) = -\ell(\boldsymbol{\beta}) + \lambda\left[\alpha\|\boldsymbol{\beta}\|_1 + \tfrac{1-\alpha}{2}\|\boldsymbol{\beta}\|_2^2\right]
3

The penalty determines the behaviour of the fitted model. L1 (lasso) sets some coefficients exactly to zero, so it suits selecting a subset of features. L2 (ridge) shrinks all coefficients without zeroing them and is often preferred when many features are expected to contribute, especially under collinearity. Elastic net (alpha between 0 and 1) combines both; it is often used when correlated features arrive in groups, where lasso alone may keep one member of a group and drop the others.

4

The penalized logistic objective has no closed-form solution and is minimized iteratively, using methods such as coordinate descent or other gradient-based and Newton-type updates. Which penalties a given solver supports varies by implementation (for example, scikit-learn's liblinear and saga solvers differ in their penalty support), so check the solver documentation. The strength lambda is usually chosen by cross-validation over a logarithmic grid, and features should be standardized first so the penalty is applied consistently.

5

Predicted probabilities are converted to class labels using a decision threshold, typically 0.5 by default. In imbalanced settings the threshold should be tuned to balance precision and recall according to the application's cost structure.

Formula
\hat{y} = \mathbf{1}[\hat{p} \ge t]

Common pitfalls

  • Fitting without standardizing features: the penalty treats all coefficients equally, so features on different scales receive unequal shrinkage, distorting the solution.
  • Using the default threshold of 0.5 without checking calibration and class balance, which silently degrades recall on the minority class.
  • Reporting only accuracy instead of AUC, F1, and calibration metrics, masking poor minority-class performance.
  • Skipping cross-validation for lambda selection and instead evaluating on training data, leading to overfitted models.
  • Interpreting lasso-selected coefficients as causal without accounting for omitted-variable bias and the instability of variable selection among correlated predictors.
  • Ignoring separation in small or high-dimensional datasets; check for it and report how the estimates change across lambda values.

Frequently asked questions

How do I choose between L1, L2, and elastic net?

Use L1 when you believe only a subset of features are relevant and you want automatic selection. Use L2 when all features likely contribute or predictors are highly correlated, since ridge distributes weight across correlated groups. Use elastic net when you need sparsity but also have blocks of correlated features; tune alpha together with lambda using k-fold cross-validation over a grid.

Must I standardize features before fitting?

Yes, in general. The penalty treats all coefficients equally, and a feature measured on a large numeric scale needs a small coefficient, so it is penalized less than a feature on a small scale unless the features are standardized. Center and scale each feature to zero mean and unit variance before fitting, and apply the same transformation to test data.

How is lambda chosen?

Lambda is a hyperparameter selected by cross-validation, typically k-fold (k=5 or 10) over a logarithmic grid. In R's glmnet, cv.glmnet automates this. In scikit-learn, LogisticRegressionCV or GridSearchCV can tune the inverse regularization strength C; C is approximately 1/lambda, but the correspondence depends on how the loss is scaled, so check the documentation of the specific implementation before reading one as the other. Nested cross-validation is only needed when you also report an unbiased estimate of generalization performance.

Does regularized logistic regression give calibrated probabilities?

The sigmoid models class probabilities directly, so outputs are often a reasonable starting point. However, shrinkage pulls coefficients toward zero, which can move predicted probabilities toward the base rate implied by the intercept (unless the intercept is also penalized). Check calibration on held-out data, and use Platt scaling or isotonic regression to recalibrate if needed.

How do I handle class imbalance?

Set class_weight='balanced' (scikit-learn) so minority class observations receive higher loss weight, or manually resample the training set. Also tune the decision threshold using the precision-recall curve rather than fixing it at 0.5.

Related methods

Sources

  1. Tibshirani, R. (1996). Regression shrinkage and selection via the lasso. Journal of the Royal Statistical Society: Series B, 58(1), 267–288.

    Open DOI reference
  2. Hastie, T., Tibshirani, R., & Friedman, J. (2009). The Elements of Statistical Learning (2nd ed., Ch. 4, 18). Springer.

    ISBN: 978-0-387-84857-0