Skip to main content

A model is a function with knobs

A model is not one rule but a whole family of rules, picked out by a few adjustable numbers. Meet two families, the threshold rule and the straight line, and see why no setting of the knobs can rescue a family that is too simple for the data.
ML01.1.3L1 Core25 minIn review

Before this lesson

ML01.1.2 Features, labels and kinds of learning M01.3 Functions and graphs

After this lesson you can

  • Define a model as a family of functions and name its parameters.
  • Work out by hand the answer of a threshold rule and of a line for given parameter values.
  • Find the two parameters of the line that passes through two given examples.
  • Explain why a family can never fit worse than a smaller family it contains, and recognise data that a family is too simple to fit.

In review. The maths and code on this page are checked by automated tests on every change, but an independent reader has not signed it off yet. Spot a mistake or a confusing step? Tell us.

The question

People say “the model” all day long. Is the model the rule “more than 2.5 exclamation marks means spam”? Or is it the bare idea of drawing a cut, before anyone chose 2.5? The difference decides what a learner is allowed to change, and what it never can.

From the last lesson

1. In the table of a dataset, what are the rows and what are the columns?

Show answer

Rows are examples. Columns are features, and one column is the label.

2. What decides whether a supervised task is classification or regression?

Show answer

What the label means. A category gives classification, and a quantity gives regression.

Intuition

A rule that turns an input into an answer is a function. Lesson 1’s rule was a function with one adjustable number inside it, the cut. Change the number and you get a different function of the same shape.

Picture a machine with knobs. Its wiring fixes the shape of what it computes. The knobs choose the particular function. A model is such a machine: a fixed shape with adjustable numbers. The numbers are called parameters, and this lesson calls them knobs as well.

Two panels. The left panel, titled Threshold family, plots the answer y-hat, 0 or 1, against the input x, a count of exclamation marks from 0 to 8. Three vermillion step functions are drawn, each at 0 on the left and jumping to 1 at its cut. The step at c equals 2.5 is thick. The steps at c equals 0.5 and c equals 5.5 are thin and faint. The low level is labelled not spam and the high level spam. A drawn dial is labelled one knob: c. The right panel, titled Line family, plots y-hat against x from 0 to 4. Three vermillion lines are drawn: a thick one labelled w equals 1.4, b equals 0.5, a faint flat one labelled w equals 0, b equals 4, and a faint steep one labelled w equals 2, b equals minus 1. Two drawn dials are labelled two knobs: w, b. A sentence underneath reads: a model is the whole family, a setting of the knobs picks one member.
ML01.1.3-F1

Two models. Left: every member of the threshold family is a step from 0 up to 1, and its one knob \(c\) says where the step is. Right: every member of the line family is a straight line, and its two knobs say how steep it is and how high it starts.

Before any data arrives, a model is all of these functions at once. Learning will pick one of them. It can only pick among the functions the model contains.

Build it up

Step 1. A function gives one answer for each input. We write \({\hat{y} = f(x)}\): put the input \(x\) in, get the answer \(\hat{y}\) out.

Step 2. Put a knob on the function. The threshold rule asks “is \(x > c\)?” and answers 1 for yes, 0 for no. The cut \(c\) is a knob.

A diagram with two rows of three boxes. In each row a blue box holding x equals 4, the input, leads by an arrow to a vermillion box that asks is x greater than c?, which leads to a vermillion answer box. Above the middle box of the first row a drawn dial is labelled knob set to c equals 2.5, and the answer box reads y-hat equals 1: spam. Above the middle box of the second row the dial is turned to a different position and labelled knob set to c equals 5.5, and the answer box reads y-hat equals 0: not spam. A heading reads: same input, same machine, only the knob differs.
ML01.1.3-F2

One input, one machine, two settings of the knob. With \(c = 2.5\) the answer to “is \(4 > c\)?” is yes. With \(c = 5.5\) it is no.

Step 3. All the settings together are a family. There is one threshold rule for \(c = 2.5\), another for \(c = 5.5\), and one for every other number. That whole collection is the threshold family. One setting of the knob picks one member.

Step 4. Meet a second family: the line. For a number as the answer, the simplest useful shape is a straight line, \({\hat{y} = wx + b}\). It has two knobs. The slope \(w\) says how much the answer rises when \(x\) goes up by 1. The intercept \(b\) is the answer at \(x = 0\). Turning \(w\) tilts the line. Turning \(b\) lifts it. Every pair \((w, b)\) is one member.

Step 5. A family can be too simple. Freeze the slope at \(w = 0\). What is left is \(\hat{y} = b\), a family of flat lines with one knob. Try both families on the four points of this course, inputs \(1, 2, 3, 4\) with labels \(2, 3, 5, 6\).

Two panels, each plotting the same four blue points at (1, 2), (2, 3), (3, 5) and (4, 6). The left panel, titled Too simple: y-hat equals b, shows four faint horizontal lines and one thick vermillion horizontal line at height 4, labelled best setting: b equals 4. Thick purple bars join each point to the thick line and are labelled with the misses 2, 1, minus 1 and minus 2. A note reads misses up to 2. The right panel, titled Flexible enough: y-hat equals w x plus b, shows four faint slanted lines and one thick vermillion line rising through the middle of the points, labelled best: w equals 1.4, b equals 0.5. The purple bars are too short to see clearly. A note reads misses up to 0.3.
ML01.1.3-F3

One dataset, two families. Left: the best flat line still misses by up to 2. Right: once the line may tilt, the best member misses by at most 0.3.

The points rise from left to right, and no flat line can rise. The trouble on the left is not a badly set knob. It is the family. Lesson 4 shows how the best settings in both panels are found.

The formal statement

NoteDefinition: model and parameters

A model is a family of functions

\[ \cmodel{\hat{y}} = f(\cdata{x};\ \cparam{\theta}), \]

where the form of \(f\) is fixed and \(\theta\) (the Greek letter theta) stands for the list of its parameters. Each value of \(\theta\) gives one member of the family.

The input changes from example to example. The parameters do not: once set, the same values are used for every input. The three families of this lesson are the threshold rule, the line and the flat line:

\[ \begin{aligned} f(x;\ \cparam{c}) &= 1 \text{ if } x > \cparam{c}, \text{ else } 0, \\ f(x;\ \cparam{w}, \cparam{b}) &= \cparam{w}\,x + \cparam{b}, \\ f(x;\ \cparam{b}) &= \cparam{b} . \end{aligned} \]

So \(\theta\) is \(c\) for the threshold family, the pair \((w, b)\) for the line and \(b\) for the flat line.

The word “model” is used in two ways. Before training it means the family. After training it often means the one member that was chosen, as in “the model predicts 4.7”. Ask which is meant.

Result 1: a family never fits worse than a family inside it. Every flat line is a line: set \(w = 0\). So the line family contains the flat-line family. Take the best flat line, with knob \(b^\star\). The line with \(w = 0\) and \(b = b^\star\) gives the same answers, so it has the same misses. The best line is at least as good as that one line. So the best line is at least as good as the best flat line. This holds for any way of scoring the misses.

Result 2: two examples fix both knobs of a line. Ask for a line through \((x_1, y_1)\) and \((x_2, y_2)\), where \(x_1 \neq x_2\). That is two conditions:

\[ w x_1 + b = y_1, \qquad w x_2 + b = y_2 . \]

Subtract the first from the second. The \(b\) cancels:

\[ \begin{aligned} w\,(x_2 - x_1) &= y_2 - y_1, \\ w &= \frac{y_2 - y_1}{x_2 - x_1} . \end{aligned} \]

The second line divides both sides by \({x_2 - x_1}\), which is allowed because \(x_1 \neq x_2\). Put this \(w\) into the first condition to get \({b = y_1 - w x_1}\). There is exactly one such line.

Result 3: so a line cannot promise to hit a third example. The line through \((1, 2)\) and \((2, 3)\) has \({w = (3 - 2)/(2 - 1) = 1}\) and \({b = 2 - 1 \cdot 1 = 1}\). At \(x = 3\) it answers \({1 \cdot 3 + 1 = 4}\), but the label is 5. No line passes through all four points. Every member of the line family misses somewhere, and the best one can do is miss by little.

Go deeper: counting what a family is able to say

Give the threshold family the eight messages of lesson 1, with counts \(0, 1, 2, 3, 4, 5, 6, 8\). A rule assigns each message a 0 or a 1, so there are \(2^8 = 256\) possible sets of answers. How many can the family produce?

A cut flags the messages above it. As the cut slides from left to right it passes the eight counts one at a time, and the flagged set shrinks by one message each time. That gives the full set, then 7 messages, 6, and so on down to none: 9 sets of answers out of 256.

A family is simple when it can say few things. That is its weakness, since the truth may not be among the 9. It is also its strength, since 9 candidates are easy to choose between with little data. Exercise 3 counts a richer family, and module ML01.8 weighs the two sides.

Worked example

Set the knobs of a line by hand, so that it passes through the first and last of the four points.

The two examples are \((1, 2)\) and \((4, 6)\). By Result 2,

\[ \begin{aligned} w &= \frac{6 - 2}{4 - 1} = \frac{4}{3}, \\ b &= 2 - \frac{4}{3} \cdot 1 = \frac{2}{3} . \end{aligned} \]

A plot of the four blue points (1, 2), (2, 3), (3, 5) and (4, 6) with a vermillion line through the first and the last, labelled y-hat equals four thirds x plus two thirds. Notes marked passes through point at those two points. A dashed orange right-angled triangle under the line is labelled run 4 minus 1 equals 3 along its base and rise 6 minus 2 equals 4 along its side, with w equals 4 over 3. An orange dot where the line meets x equals 0 is labelled b equals 2 minus four thirds times 1 equals two thirds. Short purple bars join the two middle points to the line, labelled plus one third at x equals 2 and minus one third at x equals 3.
ML01.1.3-F4

Rise over run gives the slope. The first example then gives the intercept. The two examples in the middle are missed by a third each.

Now run all four inputs through this member, and take each answer minus its label.

\(x\) Answer \({\hat{y} = \tfrac{4}{3}x + \tfrac{2}{3}}\) Label \(y\) Miss \({\hat{y} - y}\)
1 \({\tfrac{4}{3} + \tfrac{2}{3} = 2}\) 2 \(0\)
2 \({\tfrac{8}{3} + \tfrac{2}{3} = \tfrac{10}{3}}\) 3 \({+\tfrac{1}{3}}\)
3 \({\tfrac{12}{3} + \tfrac{2}{3} = \tfrac{14}{3}}\) 5 \({-\tfrac{1}{3}}\)
4 \({\tfrac{16}{3} + \tfrac{2}{3} = 6}\) 6 \(0\)

Compare it with three other members, each a different setting of the same two knobs. Each row lists the misses at \(x = 1, 2, 3, 4\) in turn. The code below prints the answers too.

\((w, b)\) Misses Largest miss
\((0,\ 4)\) \(2\), \(1\), \(-1\), \(-2\) \(2\)
\((1,\ 0)\) \(-1\), \(-1\), \(-2\), \(-2\) \(2\)
\((\tfrac{4}{3},\ \tfrac{2}{3})\) \(0\), \(\tfrac{1}{3}\), \({-\tfrac{1}{3}}\), \(0\) \(\tfrac{1}{3}\)
\((1.4,\ 0.5)\) \(-0.1\), \(0.3\), \(-0.3\), \(0.1\) \(0.3\)

Four members of one family, four different fits. The first row is a flat line, which shows again that the line family contains the flat lines. To say which member is best we need a way to score the misses. That is the subject of lesson 4.

Code

From scratch, a family is a function that takes the input and the knobs.

def threshold_rule(x, c):
    """One member of the threshold family: 1 when x is above the cut c, else 0."""
    return 1 if x > c else 0

def line(x, w, b):
    """One member of the line family."""
    return w * x + b

print("input 4, cut 2.5 and cut 5.5:", threshold_rule(4, 2.5), threshold_rule(4, 5.5))
xs, ys = [1, 2, 3, 4], [2, 3, 5, 6]
for w, b in [(0, 4), (1, 0), (1.4, 0.5)]:
    answers = [round(line(x, w, b), 2) for x in xs]
    misses = [round(a - y, 2) for a, y in zip(answers, ys)]
    print(f"w = {w}, b = {b}: answers {answers}, misses {misses}")
input 4, cut 2.5 and cut 5.5: 1 0
w = 0, b = 4: answers [4, 4, 4, 4], misses [2, 1, -1, -2]
w = 1, b = 0: answers [1, 2, 3, 4], misses [-1, -1, -2, -2]
w = 1.4, b = 0.5: answers [1.9, 3.3, 4.7, 6.1], misses [-0.1, 0.3, -0.3, 0.1]

Result 2 as code, with exact fractions so that nothing is rounded.

from fractions import Fraction

def through(p, q):
    """The knobs (w, b) of the line through two points with different inputs."""
    (x1, y1), (x2, y2) = p, q
    w = Fraction(y2 - y1, x2 - x1)      # rise over run
    b = y1 - w * x1                     # so that the line passes through the first point
    return w, b

w, b = through((1, 2), (4, 6))
print("w =", w, " b =", b)
print("answers:", [str(line(x, w, b)) for x in xs])
print("misses: ", [str(line(x, w, b) - y) for x, y in zip(xs, ys)])
w = 4/3  b = 2/3
answers: ['2', '10/3', '14/3', '6']
misses:  ['0', '1/3', '-1/3', '0']

In scikit-learn, each family is a class. Calling fit sets the knobs from the data, and they can be read off afterwards. How fit chooses them is the business of lesson 4.

import numpy as np
from sklearn.dummy import DummyRegressor
from sklearn.linear_model import LinearRegression

X = np.array(xs).reshape(-1, 1)                 # one row per example, one feature column
flat = DummyRegressor(strategy="mean").fit(X, ys)
straight = LinearRegression().fit(X, ys)
print("flat-line family: b =", flat.constant_[0, 0])
print("line family:      w =", round(straight.coef_[0], 4), " b =", round(straight.intercept_, 4))
for name, fitted in [("flat line", flat), ("line", straight)]:
    print(f"largest miss of the {name}: {np.abs(fitted.predict(X) - ys).max():.2f}")
flat-line family: b = 4.0
line family:      w = 1.4  b = 0.5
largest miss of the flat line: 2.00
largest miss of the line: 0.30

The library returns the two best settings drawn in the figure of Step 5: \(b = 4\) for the flat line, and \(w = 1.4\), \(b = 0.5\) for the line.

Explore

This module’s interactive, Rule versus learner, is in lesson 1. Its slider for the cut is the knob of the threshold family. Slide it from one end to the other and you see every way a member of the family can split the counts from 0 to 10. The bars underneath show how each one fares.

Pitfalls

Two number lines of room temperature, each from 14 to 28 degrees Celsius with eight rooms. Blue circles, labelled not comfortable, sit at 14, 16, 18, 26 and 28. Sky-blue squares, labelled comfortable, sit at 20, 22 and 24. The left panel, marked with a cross and titled One cut, any setting, has a single vermillion cut at c equals 19 with everything to its right tinted. The circles at 26 and 28 are ringed in purple, with the note 2 mistakes. The right panel, marked with a tick and titled Two cuts, has vermillion cuts at a equals 19 and b equals 25, with only the band between them tinted. Nothing is ringed, and the note reads no mistakes.
ML01.1.3-F5

Wrong beside right. The comfortable rooms sit in the middle. One cut can separate left from right, but not middle from ends. A family with two cuts can.

“The fit is poor, so the knob needs more tuning.”

Eight rooms were measured: comfortable at 20, 22 and 24 degrees, not comfortable at 14, 16, 18, 26 and 28. The family “comfortable when the temperature is above \(c\)” makes 2 mistakes at its best setting, \(c = 19\). No amount of tuning helps, because the family is too simple. Change the family to “comfortable when between \(a\) and \(b\)”, and \(a = 19\), \(b = 25\) makes none.

“The input is one of the knobs.”

The input \(x\) belongs to the example and changes with every message. The knobs belong to the model. Once set, they stay the same for every example. Learning adjusts knobs, never inputs.

“More knobs are always better.”

A cubic curve has four knobs, and one setting of them passes through all four points with no miss at all. At the new input \(x = 5\) that curve answers 4, lower than the label at \(x = 4\), while the line \({1.4x + 0.5}\) answers 7.5. A perfect fit to the examples is not the goal. Good answers for new inputs are. Module ML01.8 is about that tension.

Check yourself

Recall

1. In one sentence, what is a model?

Show answer

A family of functions of one fixed form, with parameters that pick out one member.

2. Name the parameters of the threshold family and of the line family.

Show answer

The threshold family has one, the cut \(c\). The line family has two, the slope \(w\) and the intercept \(b\).

3. What does turning a knob change: the input, the form of the function, or the member in use?

Show answer

The member in use. The form is fixed by the model, and the input comes from the example.

4. Why can the best line never fit worse than the best flat line?

Show answer

Every flat line is a line with \(w = 0\). So the best flat line is itself one of the lines, and the best line is at least as good as it.

5. How many examples fix both knobs of a line, and what must be true of them?

Show answer

Two, with different inputs. Then \({w = (y_2 - y_1)/(x_2 - x_1)}\) and \({b = y_1 - w x_1}\).

Exercises

1. ★ (a) Give the answers of the threshold rule with \(c = 3.5\) for the inputs \(1, 3, 4, 8\). (b) For the line with \(w = 0.5\) and \(b = 2\), find the answers and the misses on the four points.

Show solution

(a) Only 4 and 8 are above 3.5, so the answers are \(0, 0, 1, 1\).

(b) The answers are \({0.5 \cdot 1 + 2 = 2.5}\), then \(3\), \(3.5\) and \(4\). The misses are \({2.5 - 2 = 0.5}\), \({3 - 3 = 0}\), \({3.5 - 5 = -1.5}\) and \({4 - 6 = -2}\). The largest miss is 2.

2. ★★ Find the line through the two middle points, \((2, 3)\) and \((3, 5)\). What does it answer at \(x = 1\) and at \(x = 4\), and by how much does it miss there?

Show solution

\({w = (5 - 3)/(3 - 2) = 2}\) and \({b = 3 - 2 \cdot 2 = -1}\), so \({\hat{y} = 2x - 1}\).

At \(x = 1\) it answers \(1\), a miss of \({1 - 2 = -1}\). At \(x = 4\) it answers \(7\), a miss of \({7 - 6 = +1}\). It hits the middle exactly and misses both ends by 1. Compare the worked example, which hit the ends and missed the middle by a third.

3. ★★★ Take the family “comfortable when \({a < x < b}\)” and the eight temperatures \(14, 16, \dots, 28\). (a) How many different sets of answers can this family give on them? (b) How many can the one-cut family “comfortable when \(x > c\)” give? (c) Does either family contain the other, as far as these eight rooms can tell?

Show solution

(a) The rooms answered “comfortable” are those strictly between \(a\) and \(b\). On a number line that is always a run of neighbouring rooms, or no room at all. Count the runs by length: 8 runs of one room, 7 of two, and so on down to 1 run of all eight. That is

\[ \begin{aligned} & 8 + 7 + 6 + 5 \\ & \quad + 4 + 3 + 2 + 1 = 36 . \end{aligned} \]

With the empty set, 37.

(b) The rooms above a cut are the warmest \(k\) rooms, for \(k = 0, 1, \dots, 8\). That is 9 sets.

(c) Each of those 9 sets is either empty or a run that ends at the warmest room, so it is among the 37: take \(a = c\) and any \(b\) above 28. On these rooms the two-cut family can do everything the one-cut family can, and 28 things more. Neither comes close to the \(2^8 = 256\) sets that are possible in principle.

Summary card

A model is a family of functions. Its parameters pick one member.

The anchor figure again: on the left three step functions of the threshold family with the cut at 0.5, 2.5 and 5.5, on the right three members of the line family, with drawn dials for the one knob c and the two knobs w and b.
ML01.1.3-F1

One shape, many settings.

  • Model. \({\hat{y} = f(x; \theta)}\), with the form of \(f\) fixed and the parameters \(\theta\) free.
  • Threshold family. \({\hat{y} = 1}\) if \(x > c\), else \(0\). One parameter, \(c\).
  • Line family. \({\hat{y} = wx + b}\). Two parameters: slope \(w\) and intercept \(b\).
  • Two examples fix a line. \({w = (y_2 - y_1)/(x_2 - x_1)}\) and \({b = y_1 - w x_1}\).
  • Too simple. If no member fits, tuning cannot help. Change the family.

Sources and next steps

Sources. Each was opened and checked against this lesson on 12 November 2026.

  • Simon J. D. Prince, Understanding Deep Learning, MIT Press, 2023 (free PDF, dated 8 February 2026). Section 2.1 says a model “represents a family of different relations between the input and the output” and that the choice of parameters determines the particular relation. Section 2.2.1 and Figure 2.1 apply this to the line: the parameters determine the member of the family.
  • Tengyu Ma and Andrew Ng, CS229 Lecture Notes, Stanford University. Chapter 1 (page 9) introduces the parameters, also called weights, as “parameterizing the space of linear functions”, after noting that we must decide how to represent the functions a learner may choose from.
  • Marc Peter Deisenroth, A. Aldo Faisal and Cheng Soon Ong, Mathematics for Machine Learning, Cambridge University Press, 2020 (free PDF). Section 8.1.2 defines a predictor as a function from features to an output. Section 8.2.1 asks what set of functions the predictor may come from, and writes it as \(f(\cdot, \theta)\) with parameters \(\theta\), the letter used here.
  • scikit-learn, LinearRegression and DummyRegressor. The first documents coef_ and intercept_. The second, with strategy="mean", always predicts the mean of the training targets and stores it in constant_.

Next. ML01.1.4 Learning is choosing the knobs gives the misses a score and turns “find the best member” into a search.

This lesson unlocks

ML01.1.4 Learning is choosing the knobs

Your progress is saved in this browser only. No account, no tracking.
Back to top