How do you derive the log-likelihood, the gradient and the Hessian of binary logistic regression, show that the log-likelihood is concave, and carry out one Newton step from w=0 on the data x=(1,2,−1), y=(1,1,0) (one feature, no intercept)?

Supervised learning, Logistic regression
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

The standard MLE derivation, the identity ∇=X⊤(y−p), why there is no closed form, and a numerical Newton step.

Key idea

With pi=σ(w⊤xi), the gradient is X⊤(y−p) and the Hessian is −X⊤SX where S=diag⁡(pi(1−pi)). Since S⪰0 the log-likelihood is concave. Newton's method is w←w+(X⊤SX)−1X⊤(y−p).

Steps

  1. Model: P(yi=1∣xi)=pi=σ(w⊤xi) with σ(a)=1/(1+e−a), so P(yi∣xi)=piyi(1−pi)1−yi.
  2. Log-likelihood: ℓ(w)=∑i[yilog⁡pi+(1−yi)log⁡(1−pi)].
  3. Use σ′(a)=σ(a)(1−σ(a)). Then ∂ℓ/∂w=∑i(yipi−1−yi1−pi)pi(1−pi)xi=∑i(yi−pi)xi=X⊤(y−p). The pi(1−pi) cancels the denominators.
  4. Differentiate again: ∇2ℓ=−∑ipi(1−pi) xixi⊤=−X⊤SX. For any v, v⊤X⊤SXv=∑isi(xi⊤v)2≥0, so ℓ is concave and any stationary point is a global maximum.
  5. Setting the gradient to zero has no closed form because pi depends on w non-linearly, so use Newton's method (also called IRLS, iteratively reweighted least squares).
  6. Numerical step: at w=0 all pi=0.5. Gradient =∑(yi−0.5)xi=0.5(1)+0.5(2)+(−0.5)(−1)=2. Hessian =−0.25(1+4+1)=−1.5.
  7. Newton update: w1=0−(−1.5)−1⋅2=4/3≈1.333. The positive weight is sensible since larger x goes with y=1.

Common mistakes

How long your answer should be

One page; 7–8 minutes.

Last checked on 4 December 2026.

Read this

Previous in Supervised learning: Fit a straight line (intercept and slope) to the three points (x,y)=(0,1),(1,3),(2,2). What are the hat matrix diagonal entries h11,h22,h33, do they sum to 2, and what is the residual vector?
Next in Supervised learning: For ridge regression, define the effective degrees of freedom df⁡(λ)=tr⁡(X(X⊤X+λI)−1X⊤) and express it with the singular values dj of X. If X has singular values 4,2,1 and λ=4, what are df⁡ and the shrinkage factor on each direction?