Logistic Regression
The linear predictor can take any real value, while a probability must stay between 0 and 1. A link function connects these two scales.
Linearity¶
The equations below define the link and convert the linear predictor back to a probability.

Classifying a new observation :
Interpreting Coefficients¶
Odds are not probabilities¶
An odds ratio multiplies the odds, not the probability. If , the odds are . Doubling those odds gives 0.5, so the new probability is , not 0.4.
For a change of units in , the odds ratio is , holding the other predictors fixed. This interpretation assumes that enters without interactions or nonlinear terms. With an interaction, its effect also depends on the interacting variable.
For a simple linear predictor, the probability slope is
The same coefficient therefore produces different probability changes at different starting probabilities. The intercept gives the log-odds when all predictors are zero; that baseline may be outside the observed data unless the predictors have been centered.
Estimation¶
The likelihood is maximized over the coefficients by Maximum Likelihood, where , and where is 0 or 1, and is a vector.
Properties of MLE¶
| Property | Meaning |
|---|---|
| Consistency | Under regularity conditions, estimates converge to the true parameter as the sample size grows: . |
| Asymptotic normality | In large samples, the estimator has an approximately normal sampling distribution under regularity conditions. |
| Efficiency | MLE is asymptotically efficient under regularity conditions; this is not a universal finite-sample guarantee. |
| Invariance | If is an MLE of , then is an MLE of . |
An unbiased estimator satisfies : across repeated samples, its average equals the true parameter. This is a separate property; an MLE need not be unbiased in a finite sample.
From likelihood to loss¶
Each observation contributes if and if . Taking logs turns the product into
Maximizing this expression is equivalent to minimizing log loss, . A confident wrong prediction receives a large penalty. Predicting for an observation with contributes , compared with at .
Separation¶
If a predictor or combination of predictors perfectly separates the classes, increasingly large coefficients can keep improving the unpenalized likelihood. A finite MLE may not exist. Large standard errors and extreme fitted probabilities can be symptoms of this problem.
Regularization limits coefficient growth. It is also useful with many correlated predictors. Approximate normal inference for the unpenalized MLE needs a sufficiently informative sample and regularity conditions; it is not an exact finite-sample result.
Usage
Logistic regression is less prone to overfitting.
Due to linearity making the fit highly inflexible, with no penalty tuning parameter in the unregularized formulation.
Cannot bend or wiggle to fit noise.
With only raw predictors, captures a linear log-odds relationship; derived features and interactions allow richer patterns.
Excels at explaining how individual variables relate to the outcome.
Use for binary outcomes and if we want to capture probabilities.
Suggested dataset size is approximately medium.
Simple, stable, and well-regularized. Hence performs well on real classification problems.
Has low variance, so does not overfit easily.
Since logistic regression models () are linear in features, and the decision boundary cannot adapt too much to random noise. Cannot bend to fit small fluctuations.
Can produce useful probability estimates when the model is appropriate; calibration should still be checked.
Limitations
When the data relationship is highly nonlinear, with complex interactions and nonlinear boundaries.
Instead, explore gradient boosting or random forest.
High-dimensional sparse data needs regularization; regularized logistic regression can work well in this setting.
When classes are extremely imbalanced.
Can still use logistic regression, but needs a proper class weighing and threshold tuning.
This is because the model is trained to minimize log loss, not to treat both classes equally.
When there is a class majorly dominating the other, logistic regression model can predict everything as major class and still achieve higher accuracy.
Class weighing assigns higher penalty to mistakes on minority class.
LASSO Regression¶
Regularization¶
Criterion¶
Criterion: MSE + Penalty.
Least squares estimator: , where RSS is the Residual Sum Squares, and is .
The Least Square Estimator finds the coefficients that minimize the sum of squared errors between observed and predicted values.
Hence, for Least Squares Estimator.
L2 Ridge Regression¶
L2 penalty is defined as:
is the L2 or Euclidean norm of coefficients.
This penalty favours smaller squared coefficients; strongly penalizes large coefficients.
No penalty when all coefficients equal zero.
Dividing by can be skipped.
Can be simplified to:
Ridge uses the squared L2 norm from the start. Removing a square root from only the penalty would change the objective and generally its minimizer.
With regularization parameter that decides on how large a penalty should be,
Coefficients do not shrink to zero. When variables are highly correlated, L2 regulazation performs better.
Methods for the best ¶
Estimate via cross validation.
Find the ’s in the linear model that minimize the criterion above.
Rely on AIC or BIC.
Different Notation¶
Can also be written as...
Here, errors are minimized subject to a constraint.
: constraint on total coefficient size.
For every , there exists some .
For every , there exists some .
If there are two -variables, then .
L1 LASSO Regression¶
When we don’t want to penalize large coefficients as strongly.
Here, coefficients are shrinked to zero. Used for variable selection.
Whether lasso or ridge predicts better depends on the data; compare them using validation error.
Large means selecting fewer variables.
Different Notation¶
: constraint on total coefficient size.
If there are two -variables, then .

Every corners of the diamond correspond to one of and being 0.
| Property | L1 (Lasso) | L2 (Ridge) |
|---|---|---|
| Penalty | ||
| Feature selection | Yes (sets some coefficients to 0) | No (keeps all features) |
| Sparsity | Produces sparse models | No sparsity |
| Correlated features | Tends to pick one | Distributes weights across them |
| Stability | Less stable | More stable |
| Best use case | High-dimensional, few relevant vars | Many relevant, correlated features |
| Interpretability | High | Moderate |
Regularized Logistic Regression¶
From the regularization criterion above, replace with .
Instead of RSS minimization, likelihood must be maximized. (Or, minimize the negative likelihood.)
Sometimes, is included by taking into account the different scales of -variables.
Because, if left as is, assigns smaller coefficient to features with large scales. To make this fair across all features, apply variance-weighted penalty.
In this case, no need to standardize -variables.
Keeping the penalty convention consistent¶
A convenient convention is average negative log-likelihood plus a penalty:
where for lasso and for ridge. The intercept is usually left unpenalized. Factors such as and change the numerical meaning of , so compare formulas before comparing penalty values.
Standardize continuous predictors before applying a common penalty. Otherwise, changing a variable from metres to centimetres changes the coefficient size and therefore its penalty, even though the underlying information is unchanged. Choose using validation data or cross-validation, with scaling estimated within each training fold.
Lasso can set coefficients exactly to zero; ridge usually shrinks them continuously. Neither gives a universal prediction advantage. With correlated predictors, several different lasso selections may give similar predictions, so selection alone should not be treated as evidence that one variable is uniquely important.
SVM Regularization¶
SVM tries to maximize the margin between classes while allowing some errors ().
SVM is another regularized optimization problem with a different loss function.
Loss function: Measure of how wrong the model’s predictions are. Smaller the better.
.
Find a boundary, , that can make correct classifications with a large margin.
We are minimizng the loss and penalty added together.
Loss: . This is hinge loss.
; True label classes are either encoded as -1 or +1.
In SVM, +1 refers to one class, and -1 refers to other class.
| Case | Value |
|---|---|
| Correct and far away | 0 |
| Correct but close | small penalty |
| Wrong | large penalty |