Logistic Regression

Volume II, Chapter 4 — Part II. Binary classification via the logistic link function: Bernoulli likelihood, cross-entropy loss derivation, gradient structure, multiclass softmax extension, and the connection to neural network output layers.

Beginner

Table of Contents

  1. Learning Objectives
  2. Prerequisites
  3. Notation
  4. Core Intuition
  5. The Classification Problem
  6. The Logistic Function and Link
  7. Bernoulli Likelihood and Cross-Entropy
  8. Gradient Derivation
  9. The Hessian and Convexity
  10. Decision Boundaries and Geometry
  11. Multiclass Extension: Softmax Regression
  12. Regularized Logistic Regression
  13. Connection to Generalized Linear Models
  14. Worked Examples
  15. Connection to the Broader Curriculum
  16. Common Pitfalls and Misconceptions
  17. Research Perspective
  18. Summary of Takeaways
  19. Exercises

Learning Objectives

After reading this chapter, you should be able to:

  1. Formulate binary classification as estimating P(y=1x)P(y=1 \mid \mathbf{x}) via a linear predictor composed with the logistic sigmoid.
  2. Derive the cross-entropy (logistic) loss from the Bernoulli negative log-likelihood.
  3. Compute the gradient θJ\nabla_{\boldsymbol{\theta}} J and explain its resemblance to the linear regression gradient.
  4. Prove that the logistic loss is strictly convex in θ\boldsymbol{\theta}, guaranteeing a unique global minimum.
  5. Characterize the decision boundary as a hyperplane in feature space.
  6. Extend the framework to KK-class classification via the softmax function.
  7. Explain why linear classification remains linear in feature space even though the link function is nonlinear.

Prerequisites

This chapter builds on:


Notation

  • yi{0,1}y_i \in \lbrace 0, 1 \rbrace or {1,,K}\lbrace 1, \ldots, K \rbrace — Binary or multiclass labels
  • σ(z)=1/(1+ez)\sigma(z) = 1/(1+e^{-z}) — Logistic sigmoid
  • WRK×d\mathbf{W} \in \mathbb{R}^{K \times d} — Multiclass weight matrix
  • p(yx;θ)p(y \mid \mathbf{x}; \boldsymbol{\theta}) — Predicted class probability
  • L(θ)\mathcal{L}(\boldsymbol{\theta}) — Cross-entropy loss

Core Intuition

Linear regression predicts continuous values; logistic regression predicts probabilities for binary (and, by extension, categorical) outcomes. The key insight is separation of concerns:

  1. A linear score z=θTx~z = \boldsymbol{\theta}^T \tilde{\mathbf{x}} captures how strongly the features favor class 1.
  2. A link function σ(z)\sigma(z) maps the score to a valid probability in (0,1)(0, 1).

This template — linear predictor plus link function — defines the class of Generalized Linear Models (GLMs). Logistic regression is the GLM for Bernoulli-distributed responses. Every binary classifier in deep learning (the final sigmoid or softmax layer) is a direct descendant.

The loss function changes from squared error to cross-entropy, which penalizes confident wrong predictions harshly. The gradient takes a remarkably clean form — structurally identical to linear regression but with "residuals" replaced by prediction errors in probability space.

Series context. This is Part II of Chapter 4 (Supervised Learning) in Volume II. It follows Linear Regression and precedes Bayesian Linear Regression.

Logistic Regression

75% acc
σ(z)x₁x₂
w₁
1.50
w₂
1.50
bias
-1.20
Class 0Class 1Boundary
Explore: The decision boundary is where w₁x₁ + w₂x₂ + b = 0. Points with gold rings are misclassified. σ(z) maps the linear score to a probability in [0, 1].

The Classification Problem

Definition 1 (Binary Classification). Given training data {(xi,yi)}i=1N\{(\mathbf{x}_i, y_i)\}_{i=1}^{N} with xiRd\mathbf{x}_i \in \mathbb{R}^d and yi{0,1}y_i \in \{0, 1\}, learn a function that predicts the label of unseen examples.

We model the conditional probability:

P(y=1x;θ)=hθ(x),P(y=0x;θ)=1hθ(x).(1)P(y = 1 \mid \mathbf{x}; \boldsymbol{\theta}) = h_{\boldsymbol{\theta}}(\mathbf{x}), \quad P(y = 0 \mid \mathbf{x}; \boldsymbol{\theta}) = 1 - h_{\boldsymbol{\theta}}(\mathbf{x}). \tag{1}

The prediction task reduces to estimating hθ(x)h_{\boldsymbol{\theta}}(\mathbf{x}) and thresholding (typically at 12\frac{1}{2}).

Definition 2 (Linear Score). The logit input (linear predictor) is

z=θTx~=θ0+j=1dθjxj.(2)z = \boldsymbol{\theta}^T \tilde{\mathbf{x}} = \theta_0 + \sum_{j=1}^{d} \theta_j x_j. \tag{2}

We require a function h:R(0,1)h: \mathbb{R} \to (0,1) such that hθ(x)=h(z)h_{\boldsymbol{\theta}}(\mathbf{x}) = h(z).


Definition 3 (Logistic Sigmoid). The logistic function (sigmoid) is

σ(z)=11+ez=ez1+ez.(3)\sigma(z) = \frac{1}{1 + e^{-z}} = \frac{e^z}{1 + e^z}. \tag{3}

Proposition 1 (Properties of σ\sigma). The logistic function satisfies:

  1. σ(z)(0,1)\sigma(z) \in (0, 1) for all zRz \in \mathbb{R}
  2. σ(z)=1σ(z)\sigma(-z) = 1 - \sigma(z) (symmetry)
  3. σ(z)=σ(z)(1σ(z))\sigma'(z) = \sigma(z)(1 - \sigma(z)) (derivative in terms of itself)
  4. limzσ(z)=1\lim_{z \to \infty} \sigma(z) = 1, limzσ(z)=0\lim_{z \to -\infty} \sigma(z) = 0

Proof of (3). By the quotient rule:

σ(z)=ez(1+ez)ezez(1+ez)2=ez(1+ez)2=σ(z)11+ez=σ(z)(1σ(z)).\sigma'(z) = \frac{e^z(1+e^z) - e^z \cdot e^z}{(1+e^z)^2} = \frac{e^z}{(1+e^z)^2} = \sigma(z) \cdot \frac{1}{1+e^z} = \sigma(z)(1-\sigma(z)). \quad \blacksquare

Definition 4 (Log-Odds / Logit). The logit is the inverse of the logistic function:

logit(p)=logp1p=z.(4)\text{logit}(p) = \log\frac{p}{1-p} = z. \tag{4}

Logistic regression models log-odds as linear in features:

logP(y=1x)P(y=0x)=θTx~.(5)\log\frac{P(y=1 \mid \mathbf{x})}{P(y=0 \mid \mathbf{x})} = \boldsymbol{\theta}^T \tilde{\mathbf{x}}. \tag{5}

Important equation. Equation (5) is the defining property of logistic regression: the log-odds are an affine function of features. This is why the model is "linear" despite predicting nonlinear probabilities.


Bernoulli Likelihood and Cross-Entropy

Definition 5 (Bernoulli Distribution). For y{0,1}y \in \{0, 1\}, the Bernoulli PMF can be written compactly as

P(yx;θ)=hθ(x)y(1hθ(x))1y.(6)P(y \mid \mathbf{x}; \boldsymbol{\theta}) = h_{\boldsymbol{\theta}}(\mathbf{x})^y \cdot (1 - h_{\boldsymbol{\theta}}(\mathbf{x}))^{1-y}. \tag{6}

Proposition 2 (Negative Log-Likelihood). The negative log-likelihood for a single observation is

logP(yx;θ)=yloghθ(x)(1y)log(1hθ(x)).(7)-\log P(y \mid \mathbf{x}; \boldsymbol{\theta}) = -y \log h_{\boldsymbol{\theta}}(\mathbf{x}) - (1-y)\log(1 - h_{\boldsymbol{\theta}}(\mathbf{x})). \tag{7}

Substituting hθ(x)=σ(θTx~)h_{\boldsymbol{\theta}}(\mathbf{x}) = \sigma(\boldsymbol{\theta}^T \tilde{\mathbf{x}}), this is the binary cross-entropy between the true label yy and predicted probability p^=σ(θTx~)\hat{p} = \sigma(\boldsymbol{\theta}^T \tilde{\mathbf{x}}).

Definition 6 (Empirical Cross-Entropy Loss). Over NN i.i.d. observations:

J(θ)=1Ni=1N[yilogp^i+(1yi)log(1p^i)],(8)J(\boldsymbol{\theta}) = -\frac{1}{N}\sum_{i=1}^{N}\left[y_i \log \hat{p}_i + (1 - y_i)\log(1 - \hat{p}_i)\right], \tag{8}

where p^i=σ(θTx~i)\hat{p}_i = \sigma(\boldsymbol{\theta}^T \tilde{\mathbf{x}}_i).

Theorem 1 (Cross-Entropy vs. Squared Error). For probability estimation, cross-entropy is the proper scoring rule derived from maximum likelihood. Using squared error (yp^)2(y - \hat{p})^2 on binary labels yields a non-convex loss in θ\boldsymbol{\theta} and is theoretically unjustified.

Proof sketch. Squared error on p^=σ(z)\hat{p} = \sigma(z) gives d2dz2(yσ(z))2\frac{d^2}{dz^2}(y - \sigma(z))^2 which can be negative for certain (y,z)(y, z) pairs, violating convexity. Cross-entropy's Hessian is positive semidefinite (Theorem 3 below). \blacksquare


Gradient Derivation

We derive the gradient of (8) in complete detail.

Theorem 2 (Logistic Regression Gradient). The gradient of the average cross-entropy loss is

θJ=1NXT(p^y),(9)\nabla_{\boldsymbol{\theta}} J = \frac{1}{N}\mathbf{X}^T(\hat{\mathbf{p}} - \mathbf{y}), \tag{9}

where p^=(p^1,,p^N)T\hat{\mathbf{p}} = (\hat{p}_1, \ldots, \hat{p}_N)^T with p^i=σ(θTx~i)\hat{p}_i = \sigma(\boldsymbol{\theta}^T \tilde{\mathbf{x}}_i), and X\mathbf{X} is the design matrix.

Proof. For a single sample, the loss is i=yilogp^i(1yi)log(1p^i)\ell_i = -y_i \log \hat{p}_i - (1-y_i)\log(1-\hat{p}_i). By the chain rule:

iθj=ip^ip^iziziθj,(10)\frac{\partial \ell_i}{\partial \theta_j} = \frac{\partial \ell_i}{\partial \hat{p}_i} \cdot \frac{\partial \hat{p}_i}{\partial z_i} \cdot \frac{\partial z_i}{\partial \theta_j}, \tag{10}

where zi=θTx~iz_i = \boldsymbol{\theta}^T \tilde{\mathbf{x}}_i.

Step 1: ip^i=yip^i+1yi1p^i\frac{\partial \ell_i}{\partial \hat{p}_i} = -\frac{y_i}{\hat{p}_i} + \frac{1-y_i}{1-\hat{p}_i}.

Step 2: p^izi=p^i(1p^i)\frac{\partial \hat{p}_i}{\partial z_i} = \hat{p}_i(1-\hat{p}_i) by Proposition 1.

Step 3: ziθj=x~ij\frac{\partial z_i}{\partial \theta_j} = \tilde{x}_{ij}.

Combining:

iθj=(yip^i+1yi1p^i)p^i(1p^i)=yi(1p^i)+(1yi)p^i=p^iyi.(11)\frac{\partial \ell_i}{\partial \theta_j} = \left(-\frac{y_i}{\hat{p}_i} + \frac{1-y_i}{1-\hat{p}_i}\right)\hat{p}_i(1-\hat{p}_i) = -y_i(1-\hat{p}_i) + (1-y_i)\hat{p}_i = \hat{p}_i - y_i. \tag{11}

The simplification in (11) is the hallmark of exponential-family GLMs: the gradient equals the prediction error. Averaging over NN samples and stacking into matrix form gives (9). \blacksquare

Important equation. Equation (9) mirrors linear regression's gradient 1NXT(Xθy)\frac{1}{N}\mathbf{X}^T(\mathbf{X}\boldsymbol{\theta} - \mathbf{y}), with predictions p^i\hat{p}_i replacing linear predictions. This structural unity is why both models are solved by the same gradient descent machinery.

Corollary 1 (Gradient Descent Update).

θt+1=θtα1NXT(p^ty).(12)\boldsymbol{\theta}_{t+1} = \boldsymbol{\theta}_t - \alpha \cdot \frac{1}{N}\mathbf{X}^T(\hat{\mathbf{p}}_t - \mathbf{y}). \tag{12}

Unlike linear regression, no closed-form solution exists — θ\boldsymbol{\theta} appears nonlinearly inside σ\sigma.


The Hessian and Convexity

Theorem 3 (Strict Convexity). The logistic loss J(θ)J(\boldsymbol{\theta}) is strictly convex in θ\boldsymbol{\theta} when X\mathbf{X} has full column rank. The Hessian is

H=θ2J=1NXTWX,(13)\mathbf{H} = \nabla^2_{\boldsymbol{\theta}} J = \frac{1}{N}\mathbf{X}^T \mathbf{W} \mathbf{X}, \tag{13}

where W=diag(p^1(1p^1),,p^N(1p^N))\mathbf{W} = \text{diag}(\hat{p}_1(1-\hat{p}_1), \ldots, \hat{p}_N(1-\hat{p}_N)) is a positive diagonal matrix.

Proof. From (11), θi=(p^iyi)x~i\nabla_{\boldsymbol{\theta}} \ell_i = (\hat{p}_i - y_i)\tilde{\mathbf{x}}_i. Differentiating with respect to θ\boldsymbol{\theta}:

θ2i=p^izix~ix~iT=p^i(1p^i)x~ix~iT.(14)\nabla^2_{\boldsymbol{\theta}} \ell_i = \frac{\partial \hat{p}_i}{\partial z_i}\tilde{\mathbf{x}}_i \tilde{\mathbf{x}}_i^T = \hat{p}_i(1-\hat{p}_i)\tilde{\mathbf{x}}_i \tilde{\mathbf{x}}_i^T. \tag{14}

Since p^i(1p^i)>0\hat{p}_i(1-\hat{p}_i) > 0 for p^i(0,1)\hat{p}_i \in (0,1), each 2i\nabla^2 \ell_i is positive semidefinite. Summing: H=1NXTWX0\mathbf{H} = \frac{1}{N}\mathbf{X}^T \mathbf{W} \mathbf{X} \succcurlyeq \mathbf{0}. Strict positive definiteness holds when X\mathbf{X} has full column rank and at least one p^i{0,1}\hat{p}_i \notin \{0, 1\}. \blacksquare

Consequence. Gradient descent (with appropriate step size) converges to the unique global minimum. Newton's method, using H1\mathbf{H}^{-1}, converges quadratically near the optimum — the basis of Iteratively Reweighted Least Squares (IRLS).

Proposition 3 (IRLS). Newton's update for logistic regression is equivalent to solving a weighted least-squares problem at each iteration:

θt+1=(XTWtX)1XTWtz~t,(15)\boldsymbol{\theta}_{t+1} = \left(\mathbf{X}^T \mathbf{W}_t \mathbf{X}\right)^{-1}\mathbf{X}^T \mathbf{W}_t \tilde{\mathbf{z}}_t, \tag{15}

where Wt\mathbf{W}_t depends on current predictions and z~t\tilde{\mathbf{z}}_t is a "working response."


Decision Boundaries and Geometry

Definition 7 (Decision Boundary). The decision boundary is the set of points where P(y=1x)=12P(y=1 \mid \mathbf{x}) = \frac{1}{2}, equivalently where θTx~=0\boldsymbol{\theta}^T \tilde{\mathbf{x}} = 0 (since σ(0)=12\sigma(0) = \frac{1}{2}).

Proposition 4. The decision boundary of logistic regression is a hyperplane in Rd\mathbb{R}^d (or an affine hyperplane if the bias is included in x~\tilde{\mathbf{x}}).

Proof. θTx~=0\boldsymbol{\theta}^T \tilde{\mathbf{x}} = 0 defines a hyperplane with normal vector θ\boldsymbol{\theta}. \blacksquare

Interpretation. Logistic regression is a linear classifier — it can only separate classes with a linear boundary in the original feature space. Nonlinear boundaries require feature transformations (polynomial features, kernels) or deeper models.

Definition 8 (Margin and Confidence). The magnitude θTx~|\boldsymbol{\theta}^T \tilde{\mathbf{x}}| measures distance from the boundary in log-odds space. Large positive zz implies high confidence in class 1; large negative zz implies high confidence in class 0.


Multiclass Extension: Softmax Regression

Definition 9 (Multinomial Logistic / Softmax Regression). For KK classes, assign a parameter vector θkRd+1\boldsymbol{\theta}_k \in \mathbb{R}^{d+1} to each class. The softmax function gives class probabilities:

P(y=kx;Θ)=exp(θkTx~)j=1Kexp(θjTx~)=softmax(ΘTx~)k,(16)P(y = k \mid \mathbf{x}; \boldsymbol{\Theta}) = \frac{\exp(\boldsymbol{\theta}_k^T \tilde{\mathbf{x}})}{\sum_{j=1}^{K}\exp(\boldsymbol{\theta}_j^T \tilde{\mathbf{x}})} = \text{softmax}(\boldsymbol{\Theta}^T \tilde{\mathbf{x}})_k, \tag{16}

where Θ=[θ1θK]R(d+1)×K\boldsymbol{\Theta} = [\boldsymbol{\theta}_1 | \cdots | \boldsymbol{\theta}_K] \in \mathbb{R}^{(d+1) \times K}.

Proposition 5 (Softmax Properties). (i) P(y=k)(0,1)P(y=k) \in (0,1) and kP(y=k)=1\sum_k P(y=k) = 1; (ii) Softmax is invariant to adding a constant to all logits; (iii) Binary logistic regression is softmax with K=2K=2.

Definition 10 (Categorical Cross-Entropy). With one-hot labels yi{0,1}K\mathbf{y}_i \in \{0,1\}^K:

J(Θ)=1Ni=1Nk=1Kyiklogp^ik.(17)J(\boldsymbol{\Theta}) = -\frac{1}{N}\sum_{i=1}^{N}\sum_{k=1}^{K} y_{ik} \log \hat{p}_{ik}. \tag{17}

Theorem 4 (Softmax Gradient). The gradient with respect to class-kk parameters is

θkJ=1Ni=1N(p^ikyik)x~i.(18)\nabla_{\boldsymbol{\theta}_k} J = \frac{1}{N}\sum_{i=1}^{N}(\hat{p}_{ik} - y_{ik})\tilde{\mathbf{x}}_i. \tag{18}

The same "prediction minus target" structure persists. This is the loss function used in the output layer of every multi-class neural network.


Regularized Logistic Regression

Definition 11 (L2-Regularized Logistic Regression).

Jreg(θ)=1Ni=1N[yilogp^i+(1yi)log(1p^i)]+λθ1:d22.(19)J_{\text{reg}}(\boldsymbol{\theta}) = -\frac{1}{N}\sum_{i=1}^{N}\left[y_i \log \hat{p}_i + (1-y_i)\log(1-\hat{p}_i)\right] + \lambda \|\boldsymbol{\theta}_{1:d}\|_2^2. \tag{19}

The regularized problem remains convex. The gradient becomes:

θJreg=1NXT(p^y)+2λDθ,(20)\nabla_{\boldsymbol{\theta}} J_{\text{reg}} = \frac{1}{N}\mathbf{X}^T(\hat{\mathbf{p}} - \mathbf{y}) + 2\lambda \mathbf{D}\boldsymbol{\theta}, \tag{20}

where D=diag(0,1,,1)\mathbf{D} = \text{diag}(0, 1, \ldots, 1) excludes the bias.

Proposition 6 (L1 Regularization). L1 penalty λθ1:d1\lambda\|\boldsymbol{\theta}_{1:d}\|_1 produces sparse models — some feature coefficients are exactly zero, performing feature selection. The loss remains convex but is non-differentiable at zero.


Connection to Generalized Linear Models

Definition 12 (GLM). A Generalized Linear Model specifies:

  1. Linear predictor: η=θTx~\eta = \boldsymbol{\theta}^T \tilde{\mathbf{x}}
  2. Link function: g(μ)=ηg(\mu) = \eta, where μ=E[yx]\mu = \mathbb{E}[y \mid \mathbf{x}]
  3. Exponential family distribution for yy

For logistic regression: g=logitg = \text{logit}, μ=P(y=1)\mu = P(y=1), yBernoulli(μ)y \sim \text{Bernoulli}(\mu).

For linear regression: g=identityg = \text{identity}, μ=θTx~\mu = \boldsymbol{\theta}^T \tilde{\mathbf{x}}, yN(μ,σ2)y \sim \mathcal{N}(\mu, \sigma^2).

The GLM framework unifies the gradient structure: i=(yiμi)x~i\nabla \ell_i = (y_i - \mu_i)\tilde{\mathbf{x}}_i for all exponential-family GLMs with canonical link.


Worked Examples

Example 1: Single-Feature Classification

Suppose xiR\mathbf{x}_i \in \mathbb{R} (one feature) and we fit p^=σ(θ0+θ1x)\hat{p} = \sigma(\theta_0 + \theta_1 x). The decision boundary is at x=θ0/θ1x^* = -\theta_0/\theta_1. If θ1>0\theta_1 > 0, larger xx increases P(y=1)P(y=1).

Example 2: Gradient at Perfect Separation

When data are linearly separable, the MLE θ^\hat{\boldsymbol{\theta}} does not exist — θ\|\boldsymbol{\theta}\| \to \infty drives p^i0\hat{p}_i \to 0 or 11 for all ii. Regularization is essential to obtain finite parameter estimates.

Example 3: Softmax with Three Classes

For K=3K=3, logits z1=2z_1 = 2, z2=1z_2 = 1, z3=0z_3 = 0:

p^1=e2e2+e1+e00.665,p^20.245,p^30.090.(21)\hat{p}_1 = \frac{e^2}{e^2+e^1+e^0} \approx 0.665, \quad \hat{p}_2 \approx 0.245, \quad \hat{p}_3 \approx 0.090. \tag{21}

The softmax amplifies differences — class 1 dominates despite modest logit separation.


Connection to the Broader Curriculum

  • Sigmoid link — Output activation of binary classifiers
  • Cross-entropy loss — Standard classification loss
  • Softmax — Multi-class output layer
  • Linear decision boundary — Last layer before activation; deeper layers learn features
  • IRLS / Newton — Second-order optimization methods
  • Regularization — Weight decay in all neural networks

Backpropagation extends the gradient computation in (18) through hidden layers. Self-Attention uses softmax over a different axis — attention weights over tokens rather than class probabilities.


Common Pitfalls and Misconceptions

Pitfall 1: Using squared error for classification. MSE on binary labels is theoretically improper and practically non-convex in θ\boldsymbol{\theta}. Always use cross-entropy for probabilistic classification.

Pitfall 2: Interpreting coefficients as causal effects. θj\theta_j is the change in log-odds per unit change in xjx_j, holding other features fixed. This is an associational, not causal, statement unless additional assumptions hold.

Pitfall 3: Ignoring class imbalance. When P(y=1)0.5P(y=1) \ll 0.5, the classifier can achieve high accuracy by always predicting 0. Use balanced metrics (F1, AUC-ROC) and consider class-weighted loss.

Pitfall 4: Assuming nonlinear boundaries. Logistic regression with raw features produces only linear boundaries. Nonlinear problems require feature engineering or deeper architectures.

Pitfall 5: Perfect separation without regularization. Linearly separable data causes the MLE to diverge. Always apply regularization or use a Bayesian treatment (Bayesian Linear Regression extends naturally to classification).

Pitfall 6: Confusing σ(z)\sigma'(z) with the gradient. The derivative of the sigmoid appears in backpropagation through hidden layers, but the gradient of the loss with respect to θ\boldsymbol{\theta} simplifies to p^y\hat{\mathbf{p}} - \mathbf{y} at the output layer.


Research Perspective

Logistic regression originated with the work of Barnard (1949) and Cox (1958) on binary response models. The GLM framework (Nelder & Wedderburn, 1972) placed logistic regression within a unified statistical theory.

In machine learning, logistic regression remains the baseline for:

  • Calibration studies: assessing whether predicted probabilities match observed frequencies
  • Interpretable models in medicine, finance, and policy
  • Neural network output layers: the final softmax-with-cross-entropy layer is softmax regression over learned features

Modern research on calibration in deep learning (Guo et al., 2017) shows that large neural networks are often miscalibrated despite high accuracy — temperature scaling, a single-parameter adjustment of the softmax logits, connects directly to the logistic framework.

The logistic loss also appears in contrastive learning and recommendation systems as a pairwise ranking objective, demonstrating the breadth of this simple model.


Summary of Takeaways

  • Logistic sigmoidσ(z)=1/(1+ez)\sigma(z) = 1/(1+e^{-z}) — Maps scores to probabilities
  • Log-odds linearitylogit(p)=θTx~\text{logit}(p) = \boldsymbol{\theta}^T\tilde{\mathbf{x}} — Defining GLM property
  • Cross-entropyylogp^(1y)log(1p^)-y\log\hat{p} - (1-y)\log(1-\hat{p}) — Proper Bernoulli loss
  • Gradient1NXT(p^y)\frac{1}{N}\mathbf{X}^T(\hat{\mathbf{p}} - \mathbf{y}) — Same structure as linear regression
  • Hessian1NXTWX\frac{1}{N}\mathbf{X}^T\mathbf{W}\mathbf{X} — Strict convexity
  • Decision boundaryθTx~=0\boldsymbol{\theta}^T\tilde{\mathbf{x}} = 0 — Linear hyperplane
  • Softmaxezk/jezje^{z_k}/\sum_j e^{z_j} — Multiclass extension

Next article: Bayesian Linear Regression → — where we place a prior on θ\boldsymbol{\theta} and derive the posterior predictive distribution.


Exercises

Exercise 1 (Sigmoid properties). Prove all four properties in Proposition 1. In particular, verify σ(z)=σ(z)(1σ(z))\sigma'(z) = \sigma(z)(1-\sigma(z)) by direct differentiation.

Exercise 2 (Gradient). Derive (11) step by step without skipping algebraic simplification. Show each intermediate expression.

Exercise 3 (Hessian). Verify (14) by differentiating (11). Confirm that H\mathbf{H} is positive semidefinite for any θ\boldsymbol{\theta}.

Exercise 4 (Decision boundary). For θ=(1,2,3)T\boldsymbol{\theta} = (1, -2, 3)^T and features (1,x1,x2)(1, x_1, x_2), find the equation of the decision boundary in the (x1,x2)(x_1, x_2) plane. Sketch the regions where P(y=1)>12P(y=1) > \frac{1}{2}.

Exercise 5 (Softmax). Prove that softmax(z)=softmax(z+c1)\text{softmax}(\mathbf{z}) = \text{softmax}(\mathbf{z} + c\mathbf{1}) for any scalar cc. Why does this imply identifiability issues for Θ\boldsymbol{\Theta}?

Exercise 6 (Separation). Construct a 2D dataset with two points labeled 0 and two labeled 1 that is linearly separable. Show that the cross-entropy loss can be driven arbitrarily close to zero by scaling θ\boldsymbol{\theta}.

Exercise 7 (Multiclass gradient). Derive (18) by applying the chain rule to (17). Show that the gradient for each class has the same "prediction minus target" form.

Exercise 8 (Connection). Show that binary logistic regression with K=2K=2 and constraint θ1=0\boldsymbol{\theta}_1 = \mathbf{0} reduces to standard binary logistic regression. Explain the redundancy in the KK-class parameterization.