g↗genai/ learner
AI foundations / Lesson 03

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.

Concept + interactive labBeginner friendly

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:

  1. Example: one card.
  2. Feature: a clue on the front.
  3. Label: the answer on the back.
  4. New case: a card whose back is still blank.
Key idea: features and labels are not the same thing. Features are what we know. The label is what we want to find out.

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.

Fruit-crate scanner (toy data, invented for this lesson)
ColourShapeSizeFruit
YellowLongMediumBanana
RedRoundSmallCherry
YellowOvalMediumLemon
GreenRoundSmallGrape
OrangeRoundMediumOrange

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.

Front: clues (features)
  • Colour: Red
  • Shape: Round
  • Size: Small
Back: answer (label)

Fruit: Cherry

One card is one example. This is the Cherry row of the table, drawn as a flashcard.
PRACTICE
Quick practice: How many examples does the table above hold?

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.

Front: clues (features)
  • Colour: Red
  • Shape: Round
  • Size: Small
Back: answer (label)

Fruit: Cherry

One card is one example. This is the Cherry row of the table, drawn as a flashcard.
PRACTICE
Quick practice: Which sentence describes a feature?

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”.

Front: clues (features)
  • Colour: Red
  • Shape: Round
  • Size: Small
Back: answer (label)

Fruit: Cherry

One card is one example. This is the Cherry row of the table, drawn as a flashcard.
PRACTICE
Quick practice: The goal is to name the fruit. In the Cherry row (Red, Round, Small, Cherry), which value is the label?

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.

In the running example:

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:

  1. Read the goal.
  2. Choose the one column that holds the answer and mark it Label.
  3. Mark every other column as a Feature.
  4. Switch goals and do it again. Notice which columns changed roles.
Tap the label and the featuresPRACTICE
Pick a goal

Goal A: the packing machine should name each fruit.

Same table for both goals
ColourShapeSizeFruit
YellowLongMediumBanana
RedRoundSmallCherry
YellowOvalMediumLemon
GreenRoundSmallGrape
OrangeRoundMediumOrange
  1. Column: Colour
  2. Column: Shape
  3. Column: Size
  4. Column: Fruit
0 of 4 correct for this goal

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.

Fruit-crate scanner (toy data, invented for this lesson)
ColourShapeSizeFruit
YellowLongMediumBanana
RedRoundSmallCherry
YellowOvalMediumLemon
GreenRoundSmallGrape
OrangeRoundMediumOrange
YellowLongSmall?

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.

PRACTICE
Quick practice: Practice rule: for each row in the table, count one point for every clue (Colour, Shape or Size) that matches the new fruit. The row with the most points gives the guess. What is the guess for the new fruit (Yellow, Long, Small)?

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.
✎ Try it yourselfKnowledge check · Practice only

Check your understanding.

A school app keeps a table with one row per student and three columns: Hours slept, Ate breakfast (yes or no) and Arrived late (yes or no). The app records sleep and breakfast, then predicts whether the student will arrive late. Which column is the label?
THE TAKEAWAY

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.