ViewWiki

Lesson 1 of 4

Learning a line.

About 25 minutes · 5 practice questions

Learning from data in its simplest form: a model with two parameters, the best-fit line as what the computer learns, a prediction for a new point, the error, one outlier, and data with nothing to learn.

Step 1 of 5 · A model

Step 1 of 5

A model

Machine learning is a way of writing software without writing the rule: instead of telling the computer what to do, you give it examples, and it finds a rule that fits them itself. That rule is called a model, and the numbers that set it are called parameters.

The simplest model is a line, y^=a+bx\hat y = a + bx⁠, with two parameters: the intercept aa⁠ and the slope bb⁠. On the board are twenty measurements made by a rule the computer does not know, with noise. To learn is to choose aa⁠ and bb⁠ so that the line passes as close to the points as it can: the best-fit line, which minimises the sum of the squared distances. Predict, and then Look inside will show what the computer learned.

To the question

Step 2 of 5

Predicting

A model that has learned is useful when it answers new questions. The board has no measurement at x=10x = 10⁠, but the line has an answer.

To the question

Step 3 of 5

The error

How wrong is the model? Its error is the spread of the points about the line, ∑(y−y^)2n\sqrt{\dfrac{\sum (y - \hat y)^2}{n}}⁠, roughly a point’s typical distance from the line. In the real world you do not choose the noise, but you can collect more accurate data.

To the question

Step 4 of 5

Bad data

A model is only as good as its data. Real measurements sometimes hold a mistake: a faulty instrument, a mistyped digit. Predict what one such measurement will do.

To the question

Step 5 of 5

Nothing to learn

Look inside now shows the mean and the spread about it, 0.80.8⁠. Guessing the mean is the simplest model there is, with no xx⁠ at all. The question is whether a line does any better.

To the question

Interactive scene

Loading the interactive version…

Each step sets up the Scene for you, and a control marked “fixed” stays put for that step.

To the experiment

Practice · Predict, then look

The twenty measurements were made by a rule in which yy⁠ rises by 0.60.6⁠ for each 11⁠ of xx⁠, plus noise. A computer will find their best-fit line, the line that fits them best. What will its slope be?

To the experiment

Practice · Calculate

The board shows the learned line, y^=1.90+0.62x\hat y = 1.90 + 0.62x⁠. What does it predict for yy⁠ in a new measurement at x=10x = 10⁠?

To the experiment

Practice · Reach the target

The model’s error is the spread of the points about the line. Change Noise until the error is below 0.50.5⁠, and press Check.

To the experiment

Practice · Predict, then look

We will add one bad measurement to the data, far below the rule, near the right-hand end. What will happen to the slope of the learned line?

To the experiment

Practice · Predict, then look

Now xx⁠ and yy⁠ are unrelated: the rule’s slope is 00⁠, and the points are scattered about the mean with a spread of 0.80.8⁠. Will the line the computer learns predict yy⁠ much better than guessing the mean?