Premium problem133. Logistic Loss and Gradient, Vectorized

Medium Locked

Given X (n, d), binary labels y (n,) and weights w (d,), return (loss, grad):

  • loss is the mean logistic loss, grad its (d,) gradient
  • no loops
  • must not overflow when |X @ w| is around 800

Input

X =
[[ 1.  2.]
 [ 3.  4.]
 [-1.  0.]]
y = [1. 0. 1.]
w = [ 0.5  -0.25]

Output

(0.8804337163067194, array([0.66327911, 0.49661244]))

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)