🗂️
AI🚀 Ages 7-10Beginner 6 min read

Teaching a Computer to Sort

A hands-on primary lesson on teaching a computer to sort: labels, training examples, features and why good data makes better sorting.

Key takeaways

  • Sorting means putting things into groups, like apples and oranges
  • We teach a computer by showing it many labelled examples
  • The computer learns features, the clues that tell groups apart
  • Messy or unfair examples lead to wrong sorting, so good data matters

What does it mean to sort?

To sort means to put things into groups.

Imagine a basket of fruit. You could sort it into apples in one bowl and oranges in another. You just sorted by type!

Computers can sort too. They can sort emails into "junk" and "not junk", or photos into "cat" and "dog". But first, we have to teach them.

Teaching with examples

A computer does not start out knowing what an apple is. So we show it examples.

We give it lots of fruit pictures, and each one has a label: "this is an apple", "this is an orange". The labels tell the truth about each example.

These labelled examples are called training data. The more good examples we give, the better the computer learns. This is the heart of Machine Learning.

Learning the clues (features)

As the computer looks at the examples, it learns the clues that tell the groups apart. These clues are called features.

For apples and oranges, helpful features might be:

  • Colour: green or red, versus orange.
  • Shape: round or a little flat.
  • Skin: smooth or bumpy.

The computer spots these patterns by itself, the way you learned in What Is a Pattern?.

Sorting something new

Now comes the test. We show the computer a new fruit it has never seen.

It checks the features: "This is orange and bumpy... that matches the orange group." So it sorts it into oranges.

If it sees something tricky, like a green orange, it might guess wrong. That is normal.

Good data makes good sorting

Here is the most important part. The examples must be good.

If we only show the computer red apples, it might think a green apple is not an apple at all. If our examples are messy, mislabelled, or unfair, the computer learns the wrong patterns and sorts things wrongly.

So people must choose fair, clear, varied examples. And we should always check the computer's sorting, because it can make mistakes. Learn more in Using AI Safely and Responsibly.

Try it with code

Teaching a computer to sort is done with code. If you want to build a sorter one day, begin with Coding.

Quick quiz

Test yourself and earn XP

What does it mean to sort?

How do we teach a computer to sort?

What is a feature?

What happens if we use messy or unfair examples?

FAQ

No. The computer is not thinking. It is matching new things to patterns it learned from examples. If the examples were good, the sorting is usually good. If not, it makes mistakes.