The perceptron is the simplest learning neuron: it fires (outputs 1) when a weighted sum of its inputs passes zero, and it learns by nudging its weights only when it gets a sample wrong.
Implement perceptron_train(X, y, lr=1.0, epochs=100). Sweep the samples in order each epoch; whenever the prediction 1 if w @ x + b > 0 else 0 is wrong, move the weights and bias towards the correct answer. Stop early after an epoch with no mistakes.
X has shape (n_samples, n_features); y holds labels in {0, 1}.w = 0 and b = 0.0; process samples in the given order, updating immediately after each mistake.(w, b) where w is a float array and b a Python float.X or y.Open one at a time. Each gives away a little more than the last.
The error for a sample is y - prediction, which is 0 (correct), +1 (should have fired) or -1 (should not have).
The update is w += lr * error * x and b += lr * error; a correct sample has error 0 and changes nothing.
No results yet
Run your code to check it against the examples, or submit to run every test.