Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-104

Perceptron Update Step

Problem

Perform one perceptron update. Predict 1 when b + w . x >= 0, else 0. If the prediction is correct, return [list(w), b] unchanged; otherwise update w_j += lr * (y - pred) * x_j and b += lr * (y - pred).

Return [new_w, new_b].

Hint

Only misclassified points move the decision boundary.

Test cases

case 1
in: [[1,2],1,[0,0],0,0.5]
expected: [[0,0],0]
case 2
in: [[1,2],0,[0,0],0,0.5]
expected: [[-0.5,-1],-0.5]
case 3
in: [[1,-1],1,[1,1],-0.5,0.1]
expected: [[1.1,0.9],-0.4]
case 4
in: [[0,0],0,[1,1],0,0.1]
expected: [[1,1],-0.1]
Starter codePython
def perceptron_update(x, y, w, b, lr):
    # Returns [new_w, new_b]
    # Your code here
    pass

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