Features & Classification

A free sample lesson from AI Basics

The idea

Sorting each new arrival into the bin labeled with its true category, based on reading off its measurable features first.

What it actually is

Features are the individual pieces of information describing something (legs, sound, habitat), and a label is the category assigned based on those features. Classification is deciding a label from features - real ML learns the rules for this from data; here, we write the rules by hand.

How you write it

if feature1 == value1 and feature2 == value2:
    label = ...

A worked example

legs = 8
if legs == 8:
    label = "spider"
elif legs == 4:
    label = "mammal or reptile"
else:
    label = "unknown"
print(label)

legs is the FEATURE - one piece of information about the creature. Based on that single feature, the program assigns a LABEL - the category "spider" - the same core idea a real image classifier uses, just with far more features and learned rules instead of hand-written ones.

legs = 2
sound = "quack"
if legs == 2 and sound == "quack":
    label = "duck"
elif legs == 4:
    label = "mammal or reptile"
else:
    label = "unknown"
print(label)

This time TWO features (legs AND sound) combine to reach a more specific label - real classification almost always uses many features together, not just one.

Mistakes children actually make

Mistake 1: using or when you meant and - legs == 2 or sound == "quack" would also match a 2-legged bird that doesn't quack, or ANY animal that happens to quack regardless of legs - far too loose. Mistake 2: forgetting a catch-all else - without one, a creature that doesn't match any rule gets no label assigned at all. Mistake 3: comparing a feature to the wrong type - legs == "8" (a string) will never match legs == 8 (a number), even though they look the same when printed - features need to be compared using the same type they're stored as.

Then they try it

In the app this lesson continues with the animated explanation, spoken aloud, and then the practice: Classify: if legs == 6 and habitat == "hive", label = "bee". elif legs == 8, label = "spider". else, label = "unknown". Print the label for legs = 6, habitat = "hive". The editor runs your child’s real code and checks the result, with their coding buddy reacting to what they wrote.

Try it free