All problems
Pegasos SVM Step
Problem
Take one Pegasos stochastic subgradient step for an SVM.
First shrink w by the factor (1 - eta * lam). If y * (w dot x) < 1, also add eta * y * x. Return the new weight vector.
Hint
The loss is the hinge function max(0, 1 - y * (w dot x)).
Test cases
case 1
in: [[0,0],[1,2],1,0.1,0.1]
expected: [0.1,0.2]
case 2
in: [[1,1],[1,1],1,0.1,0.5]
expected: [0.95,0.95]
case 3
in: [[0.5,-0.5],[1,2],-1,0.2,0.1]
expected: [0.39,-0.69]
Starter codePython
def pegasos_step(w, x, y, lam, eta):
# Your code here
pass3 test cases · run your code against them in the editor