Data, examples, features and labels
Before a model can learn anything, it needs data. Data is a pile of examples. Each example has clues and, often, an answer. Learning to tell the clues from the answer is the first skill.
Learning starts with examples.
Think of a pile of flashcards. The front shows some clues. The back shows the answer. You get better by going through the pile.
A model can learn from a pile of examples in a loosely similar way. It is only an analogy: a model does not read or remember cards like a person.
This lesson names four things, in this order:
- Example: one card.
- Feature: a clue on the front.
- Label: the answer on the back.
- New case: a card whose back is still blank.
In our table, an example is one row.
Our running story is a fruit-packing machine. A camera notes the colour, shape and size of each fruit. A worker then writes down which fruit it is.
| Colour | Shape | Size | Fruit |
|---|---|---|---|
| Yellow | Long | Medium | Banana |
| Red | Round | Small | Cherry |
| Yellow | Oval | Medium | Lemon |
| Green | Round | Small | Grape |
| Orange | Round | Medium | Orange |
In this table, each row is one example: one fruit that was seen and named. Examples are not always rows. In other projects an example might be a photo or a sentence.
- Colour: Red
- Shape: Round
- Size: Small
Fruit: Cherry
Features are the clues.
A feature is a piece of information about an example that the model uses as a clue. It is usually known when the model has to make a guess. Features are sometimes called inputs.
In our table, Colour, Shape and Size describe a fruit before anyone names it. We use them as clues, so they are the features. Notice that features are columns in this table. With photos or text, features can be less tidy, such as the values of the pixels in a photo.
- Colour: Red
- Shape: Round
- Size: Small
Fruit: Cherry
The label is the answer.
The label is the answer we want for an example. It is also called the target. An example that has clues and an answer is a labeled example.
Our goal is to name the fruit. So in this table the Fruit column holds the labels, and the label for the Cherry row is “Cherry”.
- Colour: Red
- Shape: Round
- Size: Small
Fruit: Cherry
The goal decides the label.
Whether a column is a clue or the answer depends on what we want to find out. That is the goal.
Goal A is to name the fruit, so Fruit is the label. Goal B is to guess a fruit’s size, so Size becomes the label and Fruit becomes a clue. It is the same table with a different goal.
For these exercises, choose exactly one column as the label and treat every other column as a feature.
Try it in this order:
- Read the goal.
- Choose the one column that holds the answer and mark it Label.
- Mark every other column as a Feature.
- Switch goals and do it again. Notice which columns changed roles.
Goal A: the packing machine should name each fruit.
| Colour | Shape | Size | Fruit |
|---|---|---|---|
| Yellow | Long | Medium | Banana |
| Red | Round | Small | Cherry |
| Yellow | Oval | Medium | Lemon |
| Green | Round | Small | Grape |
| Orange | Round | Medium | Orange |
The table and both goals are invented for teaching. Your answers for each goal are kept when you switch goals. The rules here are simplifications: pick exactly one label, and treat every other column as a clue. Real projects can be looser than this.
A new case to guess has no label yet.
A new fruit arrives. The camera gives its clues, but nobody has named it. It has features and no label. That is an unlabeled example, or new case.
Guessing the missing label from the clues is the job we want a model to do after it has learned from labeled examples.
| Colour | Shape | Size | Fruit |
|---|---|---|---|
| Yellow | Long | Medium | Banana |
| Red | Round | Small | Cherry |
| Yellow | Oval | Medium | Lemon |
| Green | Round | Small | Grape |
| Orange | Round | Medium | Orange |
| Yellow | Long | Small | ? |
Recap from lesson 1: rules are written by hand, while in this lesson’s examples learning uses examples that come with answers. The practice rule below is hand-written. It is only here so the exercise has one clear answer. It is not how a model learns.
Where this picture is too tidy.
- Labels can be wrong. People write many labels. Wrong labels can lead a model to learn misleading patterns.
- Five rows are unlikely to be enough. Real projects usually need many more examples.
- Some clues do not help. A clue that has little to do with the answer adds little.
- Names and shapes vary. You will also see “inputs” and “target”, and data that is not a neat table.
- Not all data has labels. Some data has clues only. Later lessons cover how that is used.
Check your understanding.
Take this with you.
In our fruit table, each row is one example. Features are the clues the model uses. The label is the answer we want. Which column is the label depends on the goal, and a new case to guess has clues but no label yet.