Skip to main content
Core Pattern · Interactive Simeasy•DECEMBER 2026•15 MIN

Logistic Regression: Log-Odds Geometry, Cross-Entropy & IRLS

Deep-dive into binary Logistic Regression: how linear logits map to calibrated probabilities via the sigmoid, why Binary Cross-Entropy is convex, and how second-order IRLS (Newton-Raphson) outpaces Gradient Descent.

discriminative classifierlog-oddsbinary cross-entropyl2 regularizationirls newton-raphsonclassical mllinear modelsoptimizationcalibration

1. Problem & Discriminative Framing

Logistic Regression is the canonical discriminative binary classifier. Rather than modeling how features x are generated within each class (as Naive Bayes does), it models the conditional posterior P(y = 1 | x) directly:

z = w · x + b
P(y = 1 | x) = σ(z) = 1 / (1 + exp(-z))

Notice that both Naive Bayes and Logistic Regression produce a linear decision boundary w · x + b = 0. The difference is how w and b are chosen:

  • Naive Bayes sets w_j = log(P(x_j | 1) / P(x_j | 0)) by counting each feature independently.
  • Logistic Regression optimizes (w, b) jointly to maximize conditional likelihood Π_i P(y_i | x_i), automatically splitting weight across correlated features instead of double-counting them.

2. Scoring & Decision Boundary Geometry

The linear score z = w_1 x_1 + w_2 x_2 + b is the signed distance (scaled by ||w||) from the hyperplane w · x + b = 0:

  • z = 0 corresponds to σ(0) = 0.50 (the decision boundary).
  • z = +1.10 corresponds to σ(1.10) = 0.75.
  • z = -1.10 corresponds to σ(-1.10) = 0.25.

Interactive 2D Decision Boundary & Point Inspector

Adjust w₁, w₂, b, and L2 penalty λ, or click any data point to see its exact logit z, probability σ(z), and Binary Cross-Entropy loss contribution.

LOADING LOGISTIC REGRESSION DECISION BOUNDARY...

3. From Log-Odds to Probabilities

Why use the sigmoid σ(z) instead of a linear threshold? Because inverting p = σ(z) yields the log-odds (logit):

log [ p / (1 - p) ] = w · x + b

Every +1 unit increase in z multiplies the odds p / (1 - p) by e ≈ 2.718. Because σ(z) maps (-∞, +∞) smoothly into (0, 1), predictions are naturally calibrated probabilities (when the model is well-specified and regularized).

LOADING LOGISTIC REGRESSION SIGMOID & LOG-ODDS...

4. Inference & Regularization

At inference time, computing z = w · x + b takes O(d) time:

  • For a hard label, z ≥ 0 is equivalent to σ(z) ≥ 0.5—you don't even need exp() unless you want calibrated probabilities or a custom precision/recall threshold.
  • Why L2 regularization (λ/2 ||w||^2) matters on separable data: In the "Clean Margin" preset, if λ = 0, any separating hyperplane can scale w → ∞ to drive σ(z) → 1 and 0, making BCE approach 0 with infinite weights. Adding λ > 0 keeps ||w|| finite and prevents overconfident predictions.

5. Training & Optimization: IRLS (Newton-Raphson) vs. Gradient Descent

Minimizing regularized Binary Cross-Entropy:

L(w, b) = -(1/N) Σ_i [ y_i log p_i + (1 - y_i) log(1 - p_i) ] + (λ / 2) ||w||^2

Because L(w, b) is strictly convex (when λ > 0), it has a unique global minimum. Its gradient and Hessian are:

∇L = (1/N) X^T (p - y) + λ w
H  = (1/N) X^T S X + λ I,    where S = diag( p_i (1 - p_i) )
  • Gradient Descent (1st-order): Steps w ← w - η ∇L. When features have different scales ("Scale Skew"), the loss contours form a narrow valley and GD zig-zags slowly.
  • IRLS / Newton-Raphson (2nd-order): Solves w ← w - H^{-1} ∇L. Multiplying by H^{-1} rescales every direction by its local curvature p_i(1 - p_i), jumping to the minimum in ~4–6 iterations! (For very high-dimensional d, L-BFGS approximates H^{-1} in O(m·d) instead of O(d^3).)

Interactive GD vs. IRLS Comparison

Step through "Scale Skew" and watch IRLS collapse the gradient norm ||∇L|| in just a handful of steps while Gradient Descent crawls.

LOADING LOGISTIC REGRESSION IRLS VS GD...

6. Comparison & Failure Modes

AspectLogistic RegressionNaive BayesLinear-Chain CRF
OutputSingle label y ∈ {0, 1}Single label y ∈ CSequence (y_1, ..., y_T)
ObjectiveBinary Cross-EntropyJoint P(x, y) MLESequence NLL (log Z(x) - score)
Correlated featuresHandled cleanlyDouble-countedHandled cleanly
Non-linear boundariesNeeds feature crosses / kernelsNeeds feature engineeringNeeds neural emissions (BiLSTM/Transformer)

Common Failure Modes

  • Non-linearly separable data: A single hyperplane cannot solve XOR or circular boundaries without feature engineering (polynomials, splines, tree leaves) or switching to kernels/trees/MLPs.
  • Multicollinearity without L2: Highly correlated features can cause large oscillating weights of opposite signs unless λ > 0 stabilizes H.
  • Unscaled features in GD: Without standardization or second-order curvature (IRLS / L-BFGS), step sizes are bottlenecked by the largest feature scale.

Related Lab Entries