← All Posts
Machine Learning · Regression · Logistic Regression · Logistic Track

Logistic Regression: Overview and Roadmap

Logistic regression estimates the probability of a binary outcome, such as pass or fail. It first computes a linear score and then converts that score into a probability:

$$\Pr(Y=1\mid x)=\sigma(z),\qquad z=\beta_0+\sum_{j=1}^{d}\beta_j x_j=\beta^\top\tilde{x},\qquad \sigma(z)=\frac{1}{1+e^{-z}},$$

The augmented row $\tilde x=(1,x_1,\dots,x_d)^\top$ includes the intercept. The score $z$ can be any real number. The sigmoid $\sigma(z)$ maps it into the range $0$ to $1$.

SymbolMeaning
$n$number of data rows
$d$number of predictors, not counting the intercept
$x_i,\ \tilde{x}_i$row $i$ before and after adding the leading $1$
$y_i\in\{0,1\}$binary label for row $i$
$z_i=\beta^\top\tilde{x}_i$unbounded linear score
$p_i=\sigma(z_i)$predicted probability of class $1$
$\beta$coefficient vector including intercept $\beta_0$
Logistic regression augmented design matrix An n by d plus one matrix with a leading column of ones for the intercept, followed by predictor columns x1 through xd. X~ = n x (d + 1) bias x1x2...xd 1x11x12...x1d 1x21x22...x2d :::...: 1xn1xn2...xnd intercept / bias column d predictor columns
Each row $\tilde{x}_i=(1,x_{i1},\ldots,x_{id})$ includes the same leading $1$. Multiplication by $(\beta_0,\beta_1,\ldots,\beta_d)^\top$ therefore adds the intercept before the sigmoid is applied.

The Bernoulli Model and the Logit Link

A binary label follows a Bernoulli distribution with probability $p$. Its mean is $p$ and its variance is $p(1-p)$. Logistic regression connects this probability to the linear score through the logit:

$$\operatorname{logit}(p)=\ln\frac{p}{1-p}=z,$$

The inverse link is the sigmoid, $p=\sigma(z)$. The Bernoulli variance changes with $p$, so unequal outcome variance is built into the model rather than treated as a violation. Probit and complementary log-log are alternative links, but logit is common because coefficients have a simple odds-ratio interpretation and the training objective is convex.

Probability Versus Decision

The model outputs a probability, not a class label. A threshold $t$ creates the label: predict class $1$ when $p_i\ge t$. Changing the threshold changes decisions but does not change the fitted probabilities.

This separation matters when error costs or class balance change. The same probability model can use a high-recall threshold or a high-precision threshold without retraining. Accuracy alone can hide this tradeoff.

Failure mode. A model tuned only to maximize accuracy on imbalanced data can collapse to a constant prediction. On a population that is five percent positive, always predicting the negative class scores ninety-five percent accuracy and zero recall. The probability layer would still rank the positives above the negatives; the failure is entirely in the decision rule and the metric, not in the fit.

Three Separate Questions

Target: which probability or coefficient is the analysis trying to estimate, and for which population?

Training: which coefficients minimize Bernoulli log-loss? Gradient descent, Newton's method, or IRLS can solve this convex problem.

Evaluation: do the probabilities rank cases well, match observed frequencies, and support useful decisions at the chosen threshold? Ranking, calibration, and decision cost are different properties.

Relationship to Linear Regression

Both models use the score $z=\beta^\top\tilde x$. Linear regression returns the score as a continuous prediction and minimizes squared error. Logistic regression converts the score to a probability and minimizes log-loss. Linear coefficients use outcome units; logistic coefficients use log-odds units.

Newton's method for logistic regression can be written as a weighted least-squares update:

$$\beta^{+}=\big(X^\top W X\big)^{-1}X^\top W\,\xi,\qquad \xi_i=z_i+\frac{y_i-p_i}{p_i(1-p_i)},\qquad W=\operatorname{diag}\big(p_i(1-p_i)\big),$$

The working response $\xi$ and weights $W$ change after every iteration. This is IRLS. The same design-matrix and conditioning issues from linear regression still matter.

AspectLinear regressionLogistic regression
Outcomecontinuous $y\in\mathbb{R}$binary $y\in\{0,1\}$
Linkidentity, $\mathbb{E}[y\mid x]=z$logit, $\ln\frac{p}{1-p}=z$
Losssquared errornegative Bernoulli log-likelihood (log-loss)
Varianceconstant $\sigma^2$ (assumed)mean-linked $p(1-p)$
Solutionclosed-form normal equationsiterative, no closed form
Gradient residual$\hat y_i-y_i$$p_i-y_i$
Coefficient unitsunits of $y$ per unit of $x_j$log-odds per unit of $x_j$

Both gradients use a residual times a feature. Linear regression uses $\hat y_i-y_i$; logistic regression uses $p_i-y_i$. The sigmoid removes the closed form, so logistic training needs iteration.

From Labels to Decisions

The animation uses eight study-hour rows. It fits the coefficients, converts scores into probabilities, applies a threshold, and reports the resulting metrics.

▶ Score, Probability, Threshold, and Metrics

Every value is computed from the eight rows. Each step reveals one stage of the fitted classifier.

The fitted 0.5 boundary is $2.25$ study hours. Two rows fall on the wrong side, so training accuracy is six of eight and average log-loss is $0.3129$.

Assumptions, Counterexamples, and Edge Cases

Roadmap for This Track

The ten published chapters move from probability and interpretation through fitting, optimization, regularization, multiclass models, thresholds, metrics, calibration, and production use.

The matching implementation series, built from scratch in standard-library C++ with an explicit fit, predict, and evaluate lifecycle, is the published overview at From Scratch · C++ · Logistic Regression, which covers the stable sigmoid and log-loss primitives, the gradient and Hessian, solver choices, separation, thresholds, softmax, and a deterministic numerical smoke test. Its implementation sequence is represented by the planned stubs for sigmoid, log-loss, and gradients, Newton and IRLS, regularized logistic regression, and multiclass softmax. The theory pages link to the relevant overview sections and matching stubs rather than repeating full programs.