Perform one linear-SVM subgradient step on the weights w. The objective is 21∥w∥2+reg∑imax(0,1−yiw⋅xi) with labels in {−1,+1} and no bias. Examples whose margin yiw⋅xi is at least 1 contribute nothing to the hinge part.
Implement solve(X, y, w, lr, reg).
Returns. Return the updated weights w−lr⋅g as a NumPy array, where g=w−reg∑i:yiw⋅xi<1yixi. The input w is not modified.
Example 1
Input:
solve([[1.0, 0.0], [0.0, 1.0]], [1, -1], [0.0, 0.0], 0.1, 1.0)
Output:
[0.1, -0.1]
Example 2
Input:
solve([[2.0, 0.0]], [1], [1.0, 0.0], 0.1, 1.0)
Output:
[0.9, 0.0]
No results yet
Run your code to check it against the examples, or submit to run every test.