The lesson introduces the workings of a simple machine learning algorithm and model. For older students, it can serve as preparation for Identifying Quadrilaterals; in this case, do not skip the explanation of the tree-building algorithm (see Conclusion). The computer-based part can be omitted if desired, but it doesn’t take much time or require extensive knowledge of artificial intelligence from the teacher.
For younger students, the activity may be engaging because it involves recognizing characteristics and dividing objects into subsets.
In the first part, students disover rules to determine the professions of gnomes based on their appearance.
Divide the students into groups of four or five.
Show the students pictures of the gnomes Albie and Garak: Albie is a miner, and Garak is a tailor. (The material also includes pictures of Clive, Percy, Hugo, Teddy, Cedric and Rufus. Don’t showing them yet; their turn will come later.) Then, introduce Basil and Elroy. The question is: what are Basil and Elroy?
This is difficult to say. And it gets trickier: gnomes are not just miners and tailors but also gardeners and builders. Luckily, we can identify their professions based on their appearance.
Divide the students into groups. Each group receives a set of cards. For most gnomes, their profession is written on the card. The students’ task is to determine the professions of Basil, Otto, Monty, Elroy, Alfie, and Finnian.
They will likely try to find a gnome that looks exactly like Elroy, for example. But there isn’t one. Instead, there are rules - shared characteristics that help distinguish, for instance, gardeners from miners.
Once the groups have determined the professions of these six gnomes, we go through them one by one, asking about his profession. Groups would usually agree. If they don’t - or even if they do - they should explain why they assigned each gnome to a particular profession.
You can write the results (the names and professions of the gnomes, or multiple possible professions if applicable) on the board for potential later use.
In this next part we will formally write the rules.
Encourage the students to formulate the rules for determining professions. We expect something like this:
The rules may vary, but make sure they are ultimately clear and accurate. Write them on the board if needed. Review whether their rules are unambiguous and correctly classify the gnomes with known professions.
The rules should not include shoe, belt, or beard color, nor the shape of the mouth or hat, as these features have been deliberately distributed among the gnomes in a way that does not help determine their profession.
Next, we guide the students toward the idea of a classification tree. We do this by selecting one of the images without showing it to them. For this we use the additional large images (Clive, Percy, Hugo and others), or the small cards. Their task is to determine the gnome’s profession. If they ask for the name, we don’t reveal it, but they can ask about its characteristics.
They will most likely start by asking about the lamp or shovel. Once they learn whether the gnome has it, they will move on to the next feature, continuing until they determine the profession, after which we show them the image.
We repeat the exercise with a few more gnomes. To start, we can use a miner, as they are the easiest to identify, but we must also include a builder and a tailor.
Once their questioning process becomes “consolidated” and follows a clear pattern, we ask the students if they could create a “recipe” for determining a profession — essentially, a set of instructions for asking questions.
They will probably say that we should first ask whether the gnome has a lamp or a shovel. If they start with the buckle, it won’t be very helpful, as they will still need to find out whether the gnome has a lamp or a shovel, regardless of the answer about the buckle. They have likely already learned that the buckle is a poor starting point when they were asking about specific gnomes; if not, we remind them and guide them toward starting with the lamp or shovel, e.g. by letting them ask only two questions about each gnome. (This excludes one of the two trees below, but it’s better than to start with a belt buckle.)
We briefly write down their first question (e.g., “lamp”). Then, they must account for both possible answers — “yes” and “no.” We draw two lines downward from “lamp,” labeling them “no” and “yes,” and under each line, we write the next question.
The final result will likely be one of the two trees below. Once we begin with either the lamp or the shovel, the logical next steps for classification become clear.
The tree drawn on the board serves as a key for determining the profession of any new gnome we might encounter in the forest. (That is, if we weren’t in a classroom but out in a forest, and if there were gnomes there.) We can demonstrate this by taking one of the gnomes (for example, one of the larger images), putting it at the top of the tree and then slide it down following the appropriate paths.
From the gnome images, we have extracted a general pattern, a rule. The individual images are no longer necessary, as the model (the tree) already contains all necessary information.
What we just did is quite clever: we learned a general rule from images of gnomes. Could a computer do the same? This part of the lesson is delivered frontally.
Open Orange on the computer. The workflow we are about to create will look like this.
Open the Table widget by double-clicking it. Show the students the data that the computer will work with. This is important to show that the data also includes irrelevant features, such as the color of the belt, shoes, and hat shape. We will see whether these will mislead the computer or not.
Open the Tree Viewer.
If the students got the same tree, that’s great. If they got a different version, that’s also great, as we can compare both trees and see that, despite their differences, they will predict the same professions.
The Predictions widget shows the professions that the computer predicts for the six individuals (shown at the bottom) whose professions were unknown.
Do computer’s predictions match those made by the students?
Students learned how to determine the gnome professions from their images. Learning requires wit, intelligence. The computer also learned, just like they did, which means it was also intelligent. Since this intelligence is not natural or human but rather artificial, we call it artificial intelligence. The field of artificial intelligence that focuses on how machines (i.e., computers) learn is called machine learning.
When humans take on a task, we usually don’t follow strict instructions; we often just know how to approach it. However, for a computer to perform a task, we need to program it. Artificial intelligence is also just a program that enables a computer to follow instructions designed by a programmer.
So, for the computer to learn how to distinguish between gnomes, the programmer had to create a program - a process, a recipe - for building the tree. This process is simple: among all possible attributes, it finds the one that “best separates the gnomes”. The computer noticed that the presence of a shovel divided the gnomes into gardeners and miners on one side and builders and tailors on the other. On the other hand, when it checked the belt color, it found that gnomes of different professions appeared in both the white and black belt groups. Since the shovel attribute received the highest score, the computer split the gnomes into two groups based on that characteristic. Then, within each subgroup, it reassessed all attributes. Since this process eventually led to subgroups where all gnomes had the same profession, the task was complete.
If this activity serves as an introduction to others that require an understanding of tree construction, it is best to demonstrate the algorithm in a “physical” way - by observing and sorting cards with gnomes into subgroups.
The process we explored is not only useful for gnomes. What if we recorded symptoms of illnesses (fever, cough, nausea, headache, sore throat, stuffy nose, stomach pain) along with the corresponding diagnoses (cold, flu, viral infection)? If we showed such data to a computer, it could help identify which illness we have. We could also record the characteristics of school snacks (Is it sweet? Does it contain milk? Is bread served with it?) and whether a particular classmate, Petra, liked the snack that day. The computer might even be able to determine how Petra decides whether she will like a snack and predict whether she will enjoy the bread with jam that’s on the menu tomorrow.
Such procedures have indeed been used, for example in medicine. They have been used to predict the success of operations, to determine diseases, the effectiveness of drugs… Today, we use similar models, but they can do even more, and are therefore much more complex, requiring more data and better computers.