What does the gradient of the log-loss look like for logistic regression, and why is its form considered elegant?
Quick Overview
Asks for the gradient of the log-loss in logistic regression and an explanation of why its form is so clean compared with other losses. Tests chain-rule derivation, vectorized gradient formulas, and how the sigmoid output pairs with cross-entropy during training.
What does the gradient of the log-loss look like for logistic regression, and why is its form considered elegant?
Role: Data Scientist
Category: Machine Learning
Difficulty: medium
Interview Round: Other
What does the gradient of the log-loss look like for logistic regression, and why is its form considered elegant?
Assume binary labels $y_i \in \{0, 1\}$ and predicted probabilities $p_i = \sigma(w^\top x_i)$.
```hint Chain rule
Write the loss for one sample as a function of $z = w^\top x$ and differentiate through $p = \sigma(z)$. Express $\sigma'(z)$ in terms of $p$.
```
```hint Compare with OLS
Write down the gradient of the squared-error loss for linear regression and put the two results side by side.
```
### What a Strong Answer Covers
- The gradient in per-sample form and in vectorized matrix form, with each term named.
- A derivation through the chain rule showing how the sigmoid's derivative interacts with the derivative of the log-loss.
- The comparison with the linear regression gradient and what the shared form means for each update.
- Practical consequences: vectorized implementation, how much a single sample can move the weights, and what changes if squared error is used with a sigmoid.
### Follow-up Questions
- What is the Hessian of the log-loss, and what does it tell you about convexity and Newton's method?
- Why does a sigmoid output trained with squared error learn slowly when the model is confidently wrong?
- What happens to the gradient and the weights on linearly separable data, and how does L2 regularization change the gradient?
- How does the gradient generalize to softmax regression with cross-entropy loss?
Overview: Asks for the gradient of the log-loss in logistic regression and an explanation of why its form is so clean compared with other losses. Tests chain-rule derivation, vectorized gradient formulas, and how the sigmoid output pairs with cross-entropy during training.
What does the gradient of the log-loss look like for logistic regression, and why is its form considered elegant?
General
Nov 24, 2026
mediumData ScientistOtherMachine Learning
0
0
What does the gradient of the log-loss look like for logistic regression, and why is its form considered elegant?
Assume binary labels yi∈{0,1} and predicted probabilities pi=σ(w⊤xi).
What a Strong Answer Covers Guidance
The gradient in per-sample form and in vectorized matrix form, with each term named.
A derivation through the chain rule showing how the sigmoid's derivative interacts with the derivative of the log-loss.
The comparison with the linear regression gradient and what the shared form means for each update.
Practical consequences: vectorized implementation, how much a single sample can move the weights, and what changes if squared error is used with a sigmoid.
Follow-up Questions Guidance
What is the Hessian of the log-loss, and what does it tell you about convexity and Newton's method?
Why does a sigmoid output trained with squared error learn slowly when the model is confidently wrong?
What happens to the gradient and the weights on linearly separable data, and how does L2 regularization change the gradient?
How does the gradient generalize to softmax regression with cross-entropy loss?