Write the logistic regression loss function
Company: Apple
Role: Data Scientist
Category: Statistics & Math
Difficulty: Easy
Interview Round: Technical Screen
## Logistic Regression Loss
Consider binary logistic regression.
- Dataset: \(\{(\mathbf{x}_i, y_i)\}_{i=1}^n\)
- Labels: \(y_i \in \{0,1\}\)
- Model: \(p_i = P(y_i=1\mid \mathbf{x}_i) = \sigma(\mathbf{w}^\top \mathbf{x}_i + b)\), where \(\sigma(z)=\frac{1}{1+e^{-z}}\).
### Question
1. Write the per-example loss.
2. Write the total loss over \(n\) examples (average or sum).
3. (Optional) Write the L2-regularized objective.
Quick Answer: This question evaluates understanding of logistic regression loss formulation and L2 regularization, focusing on the binary probabilistic model and the per-example and aggregated objective (binary logistic/cross-entropy) used during training.