Machine learning 1

Step 1 of 5

One nudge

The whole learning rule, by hand

Why this matters. Spam filters, fraud alerts and the photo app that finds faces all grew from this idea: instead of a person writing the rule, the computer learns its own rule from labelled examples. Here you watch it learn to sort emails, one mistake at a time.

Same emails as Linear algebra 2: each one is a point (links, exclamation marks), and a line with weight arrow w and number b gives it a score w·x + b. Spam should score above 0, not spam below.

The computer does not know w and b. It starts with a bad line and fixes it one mistake at a time, with one rule. If an email is on the wrong side: for spam, add the email to w and add 1 to b. For not spam, subtract the email from w and subtract 1 from b. If it is already on the right side, change nothing.

That is the entire learning algorithm. Apply it to three emails, in order, and set the line after each one.

123

Email 1 is at (2, 4) and it is spam, so its score should be above 0.

Line before (w = (1, -1), b = 0): score = 1·2 + (-1)·4 + 0 = -2 → wrong side

Set the line after this email:

w₁1
w₂-1
b0

Dashed: the line before. Solid: your line after. x = links, y = exclamation marks.

Sign in to save your progress.