Skip to content
DeepForgeby svx
All problems
EasyOptimizationop-097

Perceptron Update

Problem

Apply one perceptron update.

If y * (w dot x) <= 0 the point is misclassified, so return w + lr * y * x elementwise. Otherwise return w unchanged.

Hint

Only update on a mistake; a prediction exactly on the boundary counts as a mistake.

Test cases

case 1
in: [[0,0],[1,2],1,0.5]
expected: [0.5,1]
case 2
in: [[1,1],[1,1],1,0.1]
expected: [1,1]
case 3
in: [[0.5,-0.5],[1,1],-1,0.2]
expected: [0.3,-0.7]
case 4
in: [[1,2],[1,1],1,0.5]
expected: [1,2]
Starter codePython
def perceptron_update(w, x, y, lr):
    # Your code here
    pass

4 test cases · run your code against them in the editor