The Simplest Model That Learns
More Than One Input
Last timeThe Answer Without Any Steps
Several inputs need one knob each and nothing else changes, but each knob now means the effect of its input with the others held still, which is not what most people read it as.
One knob each
A house has a size, a number of bedrooms, an age and a distance from the
station. The model that uses all four is the obvious one.
- the four inputs of one house: size, bedrooms, age, distance
- one knob per input
- the offset, still the prediction when every input is zero
Everything from the earlier lessons carries over without amendment. The score
is the same average of squared errors. Each knob has its own slope, computed
exactly as before except that the error is weighted by that knob's own input.
The step is the same line. The stopping rule is the same.
- the knob belonging to input j
- input j of example i
- the error on example i, which is the same for every knob
rows = [ # size, bedrooms, age, km from station, price in thousands
[52, 1, 40, 0.4, 196], [61, 2, 12, 1.1, 230], [75, 2, 35, 0.6, 265],
[80, 3, 8, 2.2, 290], [94, 3, 25, 0.9, 330], [110, 4, 60, 1.5, 385]]
w, b, step = [0.0, 0.0, 0.0, 0.0], 0.0, 0.0001
for t in range(20000):
errs = [sum(wj * x for wj, x in zip(w, r[:4])) + b - r[4] for r in rows]
n = len(errs)
for j in range(4):
w[j] -= step * 2 * sum(e * r[j] for e, r in zip(errs, rows)) / n
b -= step * 2 * sum(errs) / n
print("knobs", [round(v, 3) for v in w], "offset", round(b, 2))
print("the loop is the lesson three loop with one extra line of its own")What a knob now means
This is where the trouble starts, and it is the kind of trouble that produces
confident wrong statements rather than error messages.
In the single input model the slope was the effect of size on price, and that
was both what it computed and what people read it as. With several inputs the
knob on size is the effect of size on price with the bedrooms, the age and the
distance held still. Those are different quantities, and in most data they
differ substantially, because bigger houses tend to have more bedrooms and the
data contains almost no pairs of houses that differ in size alone.
The lesson stops here
5 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents