Chapter 3

Logistic regression

Logistic regression maps an affine score to a class probability. Its decision boundary is a hyperplane in the features supplied to it. Nonlinear input features can therefore give a nonlinear boundary in the original coordinates.

3.1 Probability, odds and threshold

Use labels y∈{0,1}y\in\{0,1\}, a feature vector x\mathbf x, weights w\mathbf w, intercept bb, and score z=w⊤x+bz=\mathbf w^\top\mathbf x+b. The score is dimensionless; if a raw feature has units, its weight has reciprocal units.

A unit increase in feature xjx_j, holding others fixed, multiplies the odds by ewje^{w_j}. It does not add wjw_j to the probability. With false-positive cost cFP>0c_{\rm FP}>0, false-negative cost cFN>0c_{\rm FN}>0 and zero correct-decision cost, the minimum expected-cost threshold is τ=cFP/(cFP+cFN)\tau=c_{\rm FP}/(c_{\rm FP}+c_{\rm FN}) for calibrated posterior probabilities.

3.2 Likelihood and optimisation

Let pi=σ(w⊤xi+b)p_i=\sigma(\mathbf w^\top\mathbf x_i+b) and let X\mathbf X contain the feature rows. Observations are conditionally independent in the likelihood. Below, y,p\mathbf y,\mathbf p collect labels and probabilities.

The Hessian is positive semidefinite, so the objective is convex. This does not guarantee a finite unregularised optimum: on strictly separable data, scaling a separating score can drive the loss towards zero with unbounded coefficients. Positive regularisation prevents that weight divergence; degeneracies involving an unpenalised intercept still require care, for example a training set containing only one class.

Last-minute recall

  • Sigmoid returns a probability, not a numerical regression target.
  • The affine score equals log odds.
  • A probability threshold other than one-half shifts the boundary.
  • The cross-entropy score derivative is p−yp-y.
  • Convexity does not imply a finite unregularised solution on separable data.

Revise offline: the whole Machine Learning handbook as one PDF

42 pages · 1.8 MBFree to read online. Sign in to download the PDF.We save the handbook, version and request time in My downloads. Privacy policy

All chapters · Corrections