Lesson 11 of 15

The Perceptron

The Perceptron

The perceptron is the simplest neural network unit — a single binary classifier. It computes a weighted sum of its inputs and fires (outputs 1) if the sum exceeds a threshold:

y^={1if wx+b>00otherwise\hat{y} = \begin{cases} 1 & \text{if } \mathbf{w} \cdot \mathbf{x} + b > 0 \\ 0 & \text{otherwise} \end{cases}

Learning Rule

The perceptron learning rule updates the weights whenever a prediction is wrong:

error=ytruey^\text{error} = y_{\text{true}} - \hat{y}

wiwi+αerrorxiiw_i \leftarrow w_i + \alpha \cdot \text{error} \cdot x_i \qquad \forall i

bb+αerrorb \leftarrow b + \alpha \cdot \text{error}

where α\alpha is the learning rate.

  • If the prediction is correct: error = 0, no update
  • If the true label is 1 but we predicted 0: error = +1, weights increase
  • If the true label is 0 but we predicted 1: error = −1, weights decrease

Historical Note

Rosenblatt's 1958 perceptron was the first trainable neural model. Minsky & Papert (1969) showed it cannot learn XOR — motivating multi-layer networks.

Your Task

Implement:

  • perceptron_output(x, w, b) → 1 if dot(x,w)+b > 0 else 0
  • perceptron_update(w, b, x, y_true, lr) → (new_w, new_b)
Python runtime loading...
Loading...
Click "Run" to execute your code.