How do you show that the negative log-likelihood of logistic regression is convex in the weights ?
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 , where is the data matrix with rows , and . For any vector , , because each diagonal entry is positive. A Hessian that is positive semidefinite everywhere means the function is convex.
Steps
- Write , where is the sigmoid and are the labels.
- Use to get .
- Differentiate again: .
- Show for all , so is convex. This matters because every local minimum of a convex function is a global one.
- Remark that it is strictly convex only if has full column rank. On linearly separable data, no finite minimiser exists ().
Common mistakes
- Arguing convexity from the sigmoid itself. The sigmoid is not convex.
- Sign errors in the gradient.
- Claiming a unique finite minimiser always exists.
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 is . Compute it for and . Which matrix is invertible, and what does the determinant tell you about its columns?
Next in Linear algebra and optimisation: What are for a square matrix and , and how do you derive them?