How do you show that the negative log-likelihood of logistic regression is convex in the weights w?

Linear algebra and optimisation, Convexity
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can compute a Hessian (the matrix of second derivatives) and recognise a positive semidefinite matrix.

Key idea

The Hessian is X⊤SX, where X is the data matrix with rows xi⊤, σi=σ(w⊤xi) and S=diag⁡(σi(1−σi)). For any vector v, v⊤X⊤SXv=∑isi(xi⊤v)2≥0, because each diagonal entry si is positive. A Hessian that is positive semidefinite everywhere means the function is convex.

Steps

  1. Write ℓ(w)=−∑i[yilog⁡σ(w⊤xi)+(1−yi)log⁡(1−σ(w⊤xi))], where σ is the sigmoid and yi∈{0,1} are the labels.
  2. Use σ′(z)=σ(z)(1−σ(z)) to get ∇ℓ=∑i(σi−yi) xi=X⊤(σ−y).
  3. Differentiate again: ∇2ℓ=∑iσi(1−σi) xixi⊤=X⊤SX.
  4. Show v⊤∇2ℓ v≥0 for all v, so ℓ is convex. This matters because every local minimum of a convex function is a global one.
  5. Remark that it is strictly convex only if X has full column rank. On linearly separable data, no finite minimiser exists (∥w∥→∞).

Common mistakes

How long your answer should be

Half a page; 3–4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Linear algebra and optimisation: The determinant of (abcd) is ad−bc. Compute it for A=(3162) and B=(3122). Which matrix is invertible, and what does the determinant tell you about its columns?
Next in Linear algebra and optimisation: What are ∇x (x⊤Ax) for a square matrix A and ∇x ∥Ax−b∥2, and how do you derive them?