Decision trees with data cards

Apfel oder Popcorn? Eine enaktive Einführung in KI, maschinelles Lernen und Entscheidungsbäume mit Datenkarten

Core idea

In dieser Unterrichtsreihe geht es darum Schülerinnen und Schülern (SuS) eine Vorstellung von maschinellem Lernen und Künstlicher Intelligenz zu vermitteln. Dies wird anhand von datenbasierten Entscheidungsbäumen erarbeitet. Die Umsetzung in dieser Reihe basiert hauptsächlich auf unplugged Materialien, die das handlungsorientierte Lernen auf enaktiver Ebene ermöglichen. Dies wird ergänzt durch eine digitale Lernumgebung, die zum Ende der Reihe flexibel einsetzbar ist. Der ausgewählte Kontext „Lebensmittel“ ist für alle SuS relevant und insbesondere auch für jüngere SuS geeignet.

Lebensmittel kann man anhand von Nährwertangaben als “eher empfehlenswert” oder “eher nicht empfehlenswert” klassifizieren. Dabei müssen mehrere Merkmale wie Fettgehalt, Zuckergehalt und Kalorien berücksichtigt werden. Ein mehrstufiges Regelsystem, mit dem solche Klassifikationen durchgeführt werden können, sind sogenannte Entscheidungsbäume (engl. decision trees). Solche Entscheidungsbäume kann man basierend auf Daten erstellen. Mit Daten ist hier gemeint: Man geht von einer Menge von Lebensmitteln aus, zu dem Nährwertangaben bekannt sind, und zu denen man weiß, ob sie eher empfehlenswert oder nicht empfehlenswert sind. Darauf aufbauend kann man “manuell” schrittweise Entscheidungsbäume erstellen, die die Lebensmittel zunehmend fehlerfreier klassifizieren. Dieser Erstellungsprozess kann auch automatisiert werden, um nach bestimmten Kriterien optimale Entscheidungsregeln zu finden. Die Automatisierung erfordert, jedes Lebensmittel als “Datenkarte” – das ist eine Liste von Zahlenwerten zu den verschiedenen Nährwertmerkmalen – digital zu repräsentieren. Ein maschinelles Lernverfahren entwickelt zu diesen Daten einen passenden (daten-basierten) Entscheidungsbaum. In der Praxis sind neben Entscheidungsbäumen auch andere Typen von Klassifikatoren – z.B. neuronale Netze – im Gebrauch, mit darauf angepassten maschinellen Lernverfahren.

Entscheidungsbäume haben den Vorteil, dass sie als Regelsystem von SuS verstanden werden können, ebenso können die Erstellungsverfahren eines Baumes zunächst manuell erarbeitet und dann am Computer automatisiert werden. Im Unterricht werden Lebensmittel zunächst als reale Datenkarten modellhaft repräsentiert und die SuS können Karten sortieren und klassifizieren, um sich auf einer enaktiven Ebene Verfahren anzueignen. Der Anspruch ist, einen Einblick “in den Maschinenraum” des maschinellen Lernens zu gewinnen und nicht nur vorgegebene Systeme, die eine völlige Black-Box bleiben, als Klassifikatoren mit Daten zu trainieren.

In dieser Unterrichtsreihe wird in ca. 9 Unterrichtsstunden in datenbasierte Entscheidungsbäume eingeführt. Dabei steht im Vordergrund, wie ein Entscheidungsbaum aufgebaut ist und wie die passenden Entscheidungsregeln datenbasiert hergeleitet werden. Dieser systematische, datenbasierte Erstellungsprozess kann dann als eine Methode des maschinellen Lernens automatisiert erfolgen und ein resultierender Entscheidungsbaum kann als eine Form künstlicher Intelligenz bezeichnet werden. Dazu erstellen SuS manuell mit Hilfe von Datenkarten eigene Entscheidungsbäume, um zu verstehen, erstens wie ein Entscheidungsbaum als Regelsystem aufgebaut ist, und zweitens wie man systematisch bei der Konstruktion vorgehen kann, um Entscheidungsbäume mit möglichst geringer Fehlklassifikationsanzahl zu erhalten. Ergänzend gibt es eine vorbereitete digitale Lernumgebung, in der SuS Entscheidungsbäume automatisiert erstellen können. Dabei lernen sie etwas über Künstliche Intelligenz und maschinelles Lernen. Sie lernen Entscheidungsbäume als gewinnbringende Repräsentation von Daten kennen, mit deren Hilfe Erkenntnisse gewonnen und Vorhersagen getroffen werden können, bei deren Anwendung aber auch Fehler passieren können.

Auf fachlicher Basis der deutschen Gesellschaft für Ernährung (DGE) wird das Thema Ernährung aufgegriffen, welches in der Sekundarstufe I behandelt werden sollte, aber aktuell in den Lehrplänen der verschiedenen Fächer unterrepräsentiert ist. Auf diese Weise wird das Thema maschinelles Lernen mit einem bildungsrelevanten Sachthema verknüpft. Der Kontext ist nicht typische für den Bereich KI und maschinelles Lernen, eignet sich aber für die Anbindung an die Erfahrungswelt aller SuS (unabhängig von Alter, Geschlecht, etc.). Es gibt dazu Verknüpfungsmöglichkeiten z. B. zum Biologieunterricht und die Behandlung des Kontextes kann einen Beitrag zu allgemeinbildendem Unterricht darstellen.

Target group

Informatik in Klasse 5 und 6 (alle Schulformen) – Anknüpfung an Biologie- und Mathematikunterricht möglich.

Empfehlung: Ab Klasse 6

Inhaltsfeld

“Künstliche Intelligenz und maschinelles Lernen” (insbesondere der Schwerpunkt: überwachtes Lernen mit Entscheidungsbäumen), “Daten und Information”

Prior knowledge

Basiskenntnisse über Nährwertangaben sind wünschenswert, entsprechende Erklärungen könnten aber auch in diesem Modul integriert werden

Time scope

 8 to 10 lessons of 45 minutes each

Goals

Bezogen auf Datenkarten Entscheidungsbäume:

Die SuS…

  • können einen Entscheidungsbaum als Regelsystem zum Klassifizieren von Objekten anwenden.
  • verstehen eine Datenkarte als Repräsentation eines Objekts, auf dem die Ausprägungen verschiedener Merkmale dieses Objekts erfasst sind.
  • erstellen Entscheidungsregeln zum Klassifizieren von Objekten hinsichtlich eines (Ziel-)Merkmals systematisch basierend auf Daten (in Form einer Sammlung von Datenkarten), d. h. basierend auf den Ausprägungen anderer (Prädiktor-)Merkmale der Objekte.
  • präsentieren und reflektieren eigene Entscheidungsbäume angemessen.
  • verstehen die Rolle von Daten als Grundlage für die Erstellung von Entscheidungsbäumen.
  • verstehen, dass Entscheidungsbäume Prognosen liefern sollen (Klassifikationen neuer Objekte) und deshalb mit neuen Daten getestet werden müssen und dass dabei Fehler in Form falscher Prognosen auftreten können.
  • bewerten Entscheidungsbäume anhand der Anzahl falsch klassifizierter Objekte in einem Datensatz.
  • beschreiben anhand ihrer manuellen Erfahrungen mit Datenkarten, wie ein Computer Entscheidungsbäume automatisiert erstellen kann und identifizieren diesen Vorgang als maschinelles Lernen.
Bezogen auf den Inhalt Lebensmittel:

Die SuS…

  • lernen die Bedeutung einzelner Nährwertangaben (Merkmale) bei Lebensmitteln und ihre Relevanz für die Qualitätsbewertung von Lebensmitteln kennen.
  • leiten aus den gegebenen Nährwertdaten ein Regelsystem ab, das Prognosen darüber trifft , ob ein (neues) Lebensmittel eher empfehlenswert oder eher nicht empfehlenswert ist.

Leitfragen

  • Wie kann man anhand der Nährwertangaben einen Entscheidungsbaum konstruieren, der die Beurteilung unterstützt, ob ein Lebensmittel eher empfehlenswert oder eher nicht empfehlenswert ist?
  • Wie kann man einen Entscheidungsbaum für dieses Problem automatisiert (durch maschinelles Lernen) erstellen lassen?

Lesson overview

Part 1: Introduction to the context of AI and problematization
Phase Content Material
1

Purpose of the phase

  • Pupils are motivated to want to find out how an AI works.

  • Pupils gain initial insights into AI systems and machine learning:

      • Classifiers are an example of AI systems: they can assign objects to a class.

      • Training data is required for machine learning: These are examples with the appropriate label of a class.

Core activity of the phase

  • The teacher briefly demonstrates Google Quick Draw (https://quickdraw.withgoogle.com/), a ready-made AI system that can classify images.

      • Work assignment: All pupils draw six objects that the AI is trying to recognize. The website is self-explanatory after opening the link. (20 min)

  • Important aspects for the subsequent discussion in plenary with presentation 1:

      • Slide 2: Discuss how the AI works: The AI classifies objects correctly when they are drawn appropriately.

      • Slides 3-4: The AI uses training data: After classification, an overview of what was or was not recognized was automatically displayed. In addition, some examples are shown that other people have painted the same object to illustrate the database on the basis of which the painted objects were classified. The technical term label is introduced here.

      • Slide 5: Motivating the key questions of the lesson series: How can AI systems classify objects? What role do data and machine learning play in this?

  • For further background information, see document Informationen 1 on this phase.

Word memory: AI, machine learning, object, class, label, feature

Phase Content Material
2

If you would like a more in-depth introduction to the topic of food, you will find suggestions in the documents Information 2 and Nutri-Score.pdf . This is optional. Cooperation with biology lessons may also be an option.

Phase Content Material
3

Purpose of the phase

  • A classification problem for food data is raised. A distinction should be made between "rather recommendable" and "rather not recommendable" foods.

  • The training data set for further use in the series of lessons is produced and agreed in plenary.

  • A link to the key question of the lesson series is established. The topic of these lessons is how an AI system can be created as a classifier based on data. This is worked out using the example of food data and the classification problem raised.

Core activities of the phase

  • The teacher introduces the problem "Classifying food" and establishes a link to the previously explored classification problem. The aim is for the pupils to create a system of rules from the nutritional information, which can be used to decide whether a food is "rather recommendable" or "rather not recommendable". The following points are important here:

      • Just as we saw with Quickdraw, we need a set of objects that already have suitable labels. In the example of food, these are not painted pictures, but food with data and with a label "rather recommended" or "rather not recommended". We call the collection of foods with labels: training data.

      • Based on the training data, we then want to create a system ourselves that classifies these foods as accurately as possible.

      • Later, we discuss how machines can produce such systems.

  • The teacher formulates the task for this phase: We create such examples with labels (=training data) together in order to train our AI system later.

      • Pupils work in pairs on Arbeitsblatt 1on which pictures of the foods are shown. They assign labels based on their own experiences and decide which foods they think are more recommendable and which they think are less recommendable.

      • When all pupils have completed WS1, the decks of cards are distributed to the class. One deck of cards and 50 green and 50 red paper clips per pair are handed out.

      • In a subsequent plenary discussion, a general consensus is reached on which foods should be given which labels. Only the blue cards in the deck are used, as these are intended for the training data. The yellow cards only become relevant later as test data.

      • Each pair of pupils labels their cards accordingly with the colored paper clips.

Didactic notes

In several tests, a stringent procedure has proven to be sensible for consensing the card set in data with a label. Here is a suggestion:

All the cards are gone through one by one (teacher holds up card, all pupils take the same card) in order to attach the labels (paper clips) to the cards together. Procedure:

  1. Each pair of pupils is given a deck of cards. The cards should always remain in the same order as they are in the box so that all pupils have the cards in the same order.

  2. The plenary discusses and decides which label should be given to the first blue data card (hazelnut slices). Initially, a simple vote can be taken. If there is no clear majority, a discussion takes place.

  3. If a consensus is reached, all pupils put a matching colored paper clip on the data card. If no agreement is reached after the discussion, the card can be put aside (it will be used as a new object in phase 6).

  4. 2. and 3. are repeated for all blue cards.

Leading the discussion: The teacher can moderate the discussions in plenary and, if necessary, intervene in the event of gross misjudgements (e.g. cucumber as "not recommended"). The file Rumpfdatensatz_28.csv, in which the foods that are particularly easy to categorize can be found, provides orientation. However, individual deviations from this suggestion are not a problem, i.e. the discussion does not have to be strictly guided. Many classroom trials have shown that the majority of foods are assigned by majority vote as suggested by the pupils. For further work, we recommend labeling about 30 cards (about 10 cards can be set aside). The cards from Rumpfdatensatz_28.csv should be included for the most part in order to achieve good results in further work.

WS1 can be used later in the lesson as a reminder of which card was labeled in which color if labels have fallen off the cards between lessons.

For further background information, see document "Informationen2on this phase.

A large envelope, a transparent envelope or a shoe box is suitable for storing the cards for each group. It is worth labeling them with the names of the pupils.

A large envelope, a transparent envelope or a shoe box is suitable for storing the cards for each group. It is worth labeling them with the names of the pupils. If the paper clips have fallen off the cards the next time the cards are taken out, WS1 can be used as a reference to reattach the correct paper clip to a card. Therefore, excess paper clips should be kept with the cards.

Word memory: data, example, object, label, training data

Phase Content Material
4

Purpose of the phase

  • A vocabulary for talking about data using food as an example is introduced. For this purpose, we understand nutritional values as characteristics of foods. Thus, a food can be represented by a list of data (numbers as nutritional information).

  • Establishing a decision rule based on data is introduced in order to classify food. The following important concepts are introduced: Data split, majority decision, misclassification, representation as decision tree(-diagram). (for background information on these concepts see here)

Core activity of the phase

  • The teacher introduces that a common vocabulary is needed for joint work and explains the terms object, feature, characteristic and label using a data card.

  •  Pupils work on worksheet 2 on the terms..

  • Discuss worksheet 2

  • Subsequently, the establishment of decision rules is introduced by means of presentation 2

      • The teacher gives the following impulse: "Maybe you can predict quite well with just one characteristic whether the food is recommendable or not. We try out a small data set and look for the energy characteristic. To get an overview, we sort the cards by energy 

      • To show this, the teacher uses presentation 2 . Presentation 2 shows a mini example with 6 foods. In the example shown, the optimal case is first shown in which all labels have the same color in both partial data sets.

      • Discovery: From a certain "threshold value", all cards above the threshold value are not recommended. Based on the threshold value, a "data split" is carried out (division into two groups) and the obvious decision rule is formulated 

      • The teacher states that this perfect separation into recommendable and not recommendable is the objective for a data split, but that this is not achieved by every data split.

      • An example is then shown with two additional foods, where a decision rule can only be set up in such a way that some foods are also classified incorrectly. This is the normal case. This example is used to introduce the majority decision and the term misclassification. The aim is to achieve as few misclassifications as possible with a decision rule.

  • What was previously seen in the presentation is now deepened through an activity. Live statistics re carried out in plenary to test the decision rule from presentation 2 with even more data. The concepts of data split, threshold value, majority decision in the two partial data sets and misclassifications are deepened and consolidated. Each pupil represents a food card by holding it (.e. as many cards are used as there are pupils in the class). The data split from the previous presentation is considered (energy, threshold value 260 kcal). For the exact implementation of the living statistics, see Informationen 3. The teacher notes the resulting one-step decision tree on the board.

  • The pupils return to their seats and the number of misclassifications is determined together in plenary using the documentation on the board for the decision tree 

  • A subsequent discussion serves as a summary of the previous phase and as an outlook for further content of the lesson series. The following points should be included in the discussion:

    • A single decision rule is a small decision tree with only one level.

    • Important contents learned so far are the steps for setting up a decision rule:

        • A data split is based on a specific characteristic and a value  

        • A majority decision is made in the partial data records

        • Counting misclassified foods (= number of misclassifications)

    • The decision tree is already quite good, as it only makes a few errors. In the next phase, even more single-level decision trees will be checked to find the best one.

    • Further levels of decision rules will be added later. The trees will "grow".

  • Homework:

 Word memory: object, characteristic, characteristic attribute, label, classification, threshold value, data split, number of misclassifications.

Phase Content Material
5

Purpose der Phase:

  • Setting up a decision rule with the help of data cards is practiced. The concepts of data split, threshold value, majority decision are explored in greater depth.

  • The comparison of decision rules is practiced. The concept of misclassifications are explored in greater depth.

  • Pupils learn a heuristic on how to select a favorable threshold valuefor a given feature in order to set up a decision rule.

Core activities of the phase

Activity 1: Develop a procedure for finding good threshold values

  • The first step is to introduce the sorting of data cards as an aid. By sorting in ascending order, different data splits can be tried out quickly without always having to form two piles of data cards (as in living statistics). The ruler method (See Information 4) can be used with sorted cards.

  • The ruler method is worked out in plenary based on Presentation 3 . In doing so, you can already give strategy tips on how to choose a threshold value by eye (see document Information 4).

  • Using Worksheet 4 , the ruler method is practiced in individual work in order to then apply the method in small groups with the data cards.

  • The results of WS4 are compared in plenary and corrected if necessary. Pupils can present and discuss their reasons. During the discussion, particular attention should be paid to the following aspects:

      • What is a criterion for a "best" threshold? (number of incorrectly classified cards/misclassifications)

Activity 2: Find the best decision rule with data cards

  • Pupils work in pairs, each with their own set of cards with labels. Each pair is assigned a feature by the teacher for which a decision rule is sought. Each feature should be assigned to at least one pair so that the decision rules can be compared afterwards based on all the different features.

      • Task: Each pair sorts the cards according to the characteristic assigned to them, considers several threshold values (at least three) and justifies which is the best threshold value among those considered. At least three should be considered in order to practise the comparison. It is not required to consider all possible thresholds between every two cards, as this can be overwhelming for some pupils. Optionally, game plan 1 can be used to support the process. Documentation is provided on Worksheet 5.

  • Discussion: All pairs present the best decision rule they have found. The feature, threshold value and number of misclassifications are stated. The best decision rule overall is then determined in class from the features examined and noted on the board with the threshold value and the number of misclassifications

      • Impulse for a joint discussion: What can a computer do faster and better than the pupils? Points are collected on the board. The following points are possible answers: A computer also looks for the best possible decision rule and takes all eatures into account.

      • For each feature, the computer determines all meaningful threshold values (i.e. between two map values) based on the data and compares them using the number of misclassifications.

      • A computer can typically perform these comparisons (and calculations) very quickly .

  • What did we (pupils) do compared to a computer?

      • The class group almost completely simulated the approach of a computer because all characteristics were considered across all groups. Presumably not all possible, but many of the sensible threshold values were considered and compared.

      • The computer can carry out these processes faster than a human. The class group, for , took half an hour.

 Didactic notes:

Handling the data cards is central to this phase. In order to be able to argue with misclassifications and thus compare the quality of different threshold values, it is necessary to sort the cards in ascending order. It may be necessary for pairs to work at two tables pushed together in order to be able to sort the cards completely in ascending order according to one characteristic. This sorting work takes some time and can be challenging for some pupils, but provides a good opportunity to discuss what a computer can do faster (and more accurately) than a human.

Word memory: data split, threshold value, majority decision, decision rule, misclassification, ruler method

Phase Content Material
6

Purpose of the phase

  • It is motivated to look at multi-level decision trees, not just single-level ones, as all single-level decision trees still make mistakes. In addition, good nutrition is multifactorial, so it makes sense to use several characteristics.

  • The procedure for creating the second stage is explained and practiced: The procedure for the second stage is essentially the same as for the first stage, with two differences. In the second stage, only the partial data records that were created in the first stage are worked on further, and different characteristics are used than in the first stage.

Core activity of the phase

  • The teacher motivates looking at multi-level decision trees as follows. The previous phase showed that not all foods can be correctly classified with single-level decision trees. Therefore, in this phase, based on the first rule, additional features are included to create decision rules in the second level of the decision tree, which improves the decision tree in terms of the number of misclassified foods.

  • As an important addition to the one-step decision tree, it is introduced that in the second step only the cards of a partial data set are worked on (either the cards in the left or right branch are worked on). This can either be discussed in plenary with the support of Präsentation 4 or optionally illustrated by another activity in the living statistics (see Information 5. on this phase).

  • Using presentation 4, the teacher explains the documentation of a multi-level decision tree according to worksheet 6.

  • Again working in pairs, the pupils work with their set of cards and create further levels of their decision tree. Each pair can choose whether to continue working with their own decision tree from the last phase or to use the one selected as the best one-step decision tree.

  • Next task for the pairs: Improve the tree by growing more steps. Select suitable features. Documentation is provided on worksheet 6. Game board part 2 can be used to organize the data cards, e.g. to store unused cards of a partial data set in a suitable place. See Information 5 for the exact use of the game plan. Information 5..

      • For differentiation for fast groups: Further improvements by changing the tree

          • Differentiation 1: A third level of the decision tree is added. Game plan part 2 can be used for this by creating "individual data splits" by cutting up game plan part 2. A third level of the decision tree can be drawn on WS6 itself.

          • Differentiation 2: Different features are tried out by pupils in the second split.

      • All pairs of pupils create at least one two-stage decision tree and document it on WS6.

  • In the plenary session, the multi-level trees created are presented with reference to the features used, threshold values and total number of misclassifications. The decision rules are also formulated verbally.

  • The trees created are compared with each other based on the criterion of the number of misclassifications. All trees are scored and the best three trees (those with the lowest number of misclassifications) are highlighted.

  • For the next lesson, the decision trees created in this phase (WS6) are hung up in the classroom (or collected by the teacher). These will be needed again in the next lesson to apply test data to them.

  • Homework: All pupils fill in a blank card (AB8) for a new food at home. These new foods are classified in the next lesson using the trees created. Optionally, AB7 can also be used as homework.

 Didactic notes

It is known from several tests that pupils work at very different speeds in this phase. The aim should be for all pairs of pupils to create a two-stage decision tree and document it on AB6 with the number of misclassifications.

A typical mistake made by pupils is to continue working with all the cards in a branch, even though they are only allowed to work with the subset of cards in that branch.

Word memory: Stages of a decision tree

Phase Content Material
7

Purpose of the phase

  • For the first time, pupils explicitly use a multi-level decision tree to classify a food. In doing so, they learn how to use the decision tree as a classifier.

  • Pupils apply different decision trees to the same food in order to determine that different decision trees as classifiers can make different decisions for the same food.

  • It is motivated to check which decision tree classifies a particularly large number of new foods correctly. Test data is introduced for this in the next phase.

Core activity of the phase

  • Preparation: The teacher lays out (or hangs up) the trees created (as a ausgefüllte AB 6 from the previous phase) as stations together with red and green paper clips in the classroom.

  • In plenary, Präsentation5_Baum_Anwenden is used to introduce how a decision tree can be used to classify a food item using a food map. This prepares the pupils for the next activity.

  • Each pupil goes from station to station with the new food (the blank card from AB 8filled in at home). At each station, the pupils go through the respective decision tree with the card and attach the appropriate colored paper clip to the card at the end (depending on whether the decision tree classifies the food as rather recommendable or rather not recommendable). Each new food is thus given a variety of classifications.

  • Important aspects for the joint discussion:

      • Observation: A food item may have been classified differently by different trees, which can be recognized by the different coloured paper clips on individual cards.

      • Conclusion: Different decision trees can classify the same food differently.

      • New goal: We want to find out which decision tree classifies food most reliably and correctly.

      • Procedure: This can be found out by using test data.

Word memory: test data, classifier

Phase Content Material
8

Purpose of the phase

  • Pupils apply test data to their own decision tree to find out how many of the 15 test foods are misclassified.

  • Pupils compare different decision trees based on the number of incorrectly classified test foods.

  • In class, the decision tree with the lowest number of incorrectly classified foods is selected on the basis of the test data.

Core activity of the phase

  • The yellow test cards are introduced in plenary and labeled with the help of worksheet 9 (as in phase 1 for the blue training data).

  • Each pair of pupils uses the test data to test their own decision tree (result from the previous lesson on AB6). To do this, each test card is taken and classified by the decision tree. For each card, note whether the classification by the decision tree corresponds to the label chosen on the card in the plenary session.

  • At the end, the following sentence can be added to WS6: "Using our group's decision tree, ___ foods were correctly classified from the test data and ____ foods were incorrectly classified."

  • The plenary session compares how well each tree performs with test data. The comparison criterion is the number of incorrect classifications by the decision tree.

  • Finally, the following aspects are discussed in plenary:

      • Which are the three best decision trees in terms of the number of incorrectly classified test foods?

      • The top 3 best decision trees based on the training data are compared with the top 3 best decision trees based on the test data.

          • Aspect for the discussion: A decision tree is created with training data and optimized for it. If this decision tree is used for new data, it may no longer provide the best result. It is therefore important to always additionally check decision trees created based on data with test data.

Didactic notes

To compare the performance of a decision tree on training and test data, the proportion of incorrect classifications in the training data is normally compared with the proportion in the test data. We have simplified this here to the absolute number of incorrect classifications in order to avoid potential difficulties for students when comparing decimal numbers.

Phase Content Material
9

Purpose of the phase

  • Pupils work out how a computer proceeds systematically when selecting threshold values. To do this, they draw on their own experience in creating decision trees.

  • Pupils create a decision tree, in the true sense of machine learning, automatically with the help of a computer and a digital learning environment.

  • Pupils reflect on the possible uses and limitations of their own decision trees.

Core activity of the phase

  • In the plenary session, the group revisits what was noted in an earlier phase (end of phase 4) about how a computer can automatically create a decision tree. The following points are important for this:

      • A computer first searches for the best one-step decision rule, taking all features into account.

      • For each feature, the computer determines all meaningful threshold values (i.e. between two map values) based on the data and compares them using the number of misclassifications.

      • The same procedure is then repeated in the second (third, fourth, ...) stage so that the tree gradually builds up.

      • A computer can typically perform these comparisons (and calculations) very quickly, so that we are shown a multi-level decision tree within seconds. A human would take much longer.

  • It also briefly discusses what a person has to contribute to this process:

      • Objects must be given a suitable label by a human before the computer can work with them.

      • The human must give the algorithm a few "instructions", such the maximum depth of the tree (= number of levels of the tree).

  • After this rough repetition, the pupils work out in detail how a computer tests all sensible threshold values for a characteristic and given data and makes a decision based on this. This is done on (worksheet 10). and discussed in plenary.

  • After learning how a computer works, the pupils work in a digital learning environmenthttps://go.upb.de/auto-baumto have decision trees created automatically by a computer. In preparation, they go through various steps that they had previously carried out manually with the data cards (selecting labels, sorting, creating decision rules manually). Further information on using the learning environment can be found in the document Informationen 8.1 .

  • n the plenary, two important aspects are discussed in turn (more detailed suggestions in Information 8.2): 

      • Comparison of the decision tree creation process manually with data cards and automatically with the computer

      • Reflection on the limits and possible applications of the self-created decision trees with regard to a healthy diet

Phase Content Material

Request for evaluation

At the end of the lesson series, please give the students the evaluation (feedback) with the note that this is an anonymous feedback to the "inventors" of the lesson series. The "inventors" are very interested in finding out how the students liked the series.

A survey on the evaluation can be found digitized on a server of the University of Paderborn: https://go.upb.de/ev-lebensmittel 

Thank you very much for this!

Ast Ein Ast innerhalb eines Entscheidungsbaums ist eine von mehreren Abzweigungen, die von einem Regelknoten zu einem nächsten Knoten führt.

Ausprägung/Merkmalsausprägung Die Werte, die ein Merkmal annehmen kann, nennt man Merkmalsausprägung.

Beispiel (im Kontext von KI) Ein Beispiel ist ein Objekt (z. B. Lebensmittel), das durch bestimmte Merkmale (z. B. Nährstoffe) beschrieben wird und mit einem Label (z. B. „eher empfehlenswert“ oder „eher nicht empfehlenswert“) versehen ist.

Blattknoten Ein Entscheidungsbaum besteht aus verschiedenen Knoten. Die Knoten am Ende eines Entscheidungsbaums nennt man Blattknoten und in ihnen ist immer eine Entscheidung für eine Ausprägung des Zielmerkmals eingetragen.

Datenkarte Eine Datenkarte repräsentiert ein Objekt, indem darauf die Ausprägungen einer Liste von Merkmalen dargestellt sind (z. B. ein Lebensmittel durch Nährwertangaben zu einer Liste von Nährstoffen). Eine Datenkarte kann digital oder analog repräsentiert sein.

data split Ein Datensplit ist die Aufteilung von Daten in Teildatensätze basierend auf den Ausprägungen eines Merkmals, z. B. durch einen Schwellenwert.

Entscheidungsbaum Ein Entscheidungsbaum ist ein (übersichtliches, in gewissen Grenzen nachvollziehbares) Regelsystem, das als Baumdiagramm dargestellt werden kann. Ein solcher Entscheidungsbaum veranschaulicht hierarchisch aufeinanderfolgende Entscheidungsregeln, an deren Ende immer eine Entscheidung für eine bestimmte Fragestellung steht.

misclassifications Eine Objekt, das durch einen Klassifikator einer falschen Klasse zugeordnet wird nennt man Fehlklassifikation.

Klasse (im Kontext von KI) Eine Klasse ist eine Ausprägung eines kategorialen Zielmerkmals beim überwachten maschinellen Lernen.

Klassifikation Mit einem Entscheidungsbaum kann man Ausprägungen eines (mit einer gewissen Wahrscheinlichkeit) Merkmals vorhersagen. Anders formuliert kann man also ein Objekt einer Klasse zuordnen. Eine solche regelgeleitete Zuordnung zu einer Klasse nennt man Klassifikation.

Klassifikator Ein Klassifikator ist ein Regelsystem (z. B. Entscheidungsbaum), das bestimmte Objekte anahand von Prädiktormerkmalen klassifizieren kann.

Klassifizieren Das Klassifizieren eines Objekts entspricht dem Zuordnen eines Objekts zu einer Klasse (aus einer Menge möglicher Klassen). Klassen können auch als Merkmalsausprägungen eines kategorialen Merkmals verstanden werden.

Künstliche Intelligenz (KI) Künstlicher Intelligenz befasst sich mit der Frage, wie man Computer dazu bringen kann, Dinge zu tun, die Menschen bisher besser beherrschen. Dazu gehören verschiedenste Anwendungen, u. A. die Fähigkeit in verschiedenen Szenarios Vorhersagen zu treffen oder Klassifikationen vorzunehmen die mit einer hohen Rate korrekt sind. Somit zählen leistungsfähige Klassifikatoren (z.B. Entscheidungsbäume) zu den Anwendungen von Künstlicher Intelligenz.

Label Ein Label gibt die Klassenzugehörigkeit eines Objekts an. Das Label kann als Ausprägung eines Merkmals (Zielmerkmal) verstanden werden.

Maschinelles Lernen Maschinelles Lernen bezeichnet Verfahren, in denen eine Lernaufgabe automatisiert durch Lernalgorithmen basierend auf Daten gelöst wird. Maschinelles Lernen unterscheidet verschiedene Arten von Lernaufgaben. Typischerweise wird zwischen drei Arten von Lernaufgaben unterschieden: überwachtes Lernen, unüberwachte Lernen und bestärkendes Lernen. Beim überwachten Lernen geht es darum, die Ausprägung eines Zielmerkmals für eine bestimmte Art von Objekten vorherzusagen. Beim unüberwachten Lernen geht es darum, Objekte anhand bestimmter Merkmale in Gruppen ähnlicher Objekte zusammenzufassen und beim bestärkenden Lernen geht es darum, sogenannte „Agenten“ (z.B. Roboter) zum Handeln zu bringen. Bei allen Lernaufgaben kommen unterschiedlichste Lernalgorithmen zum Einsatz.

Merkmal Merkmale charakterisieren Objekte und können verschiedene Ausprägungen annehmen. Es gibt numerische und kategoriale Merkmale.

Objekt  Objekte sind Merkmalsträger jeglicher Art. D. h. Objekte können durch Merkmale beschrieben werden (Z. B. Lebensmittel werden durch Nährwerte beschrieben, Menschen durch charakterisierende Eigenschaften wie Haarfarbe oder Körpergröße). Dabei ist nicht festgelegt welche Merkmale zum beschreiben eines Objektes herangezogen werden.

Pfad Ein Pfad innerhalb eines Entscheidungsbaums ist eine Abfolge von Ästen, die im Wurzelknoten beginnt und in einem Blattknoten endet.

Prädiktormerkmal Beim überwachten maschinellen Lernen geht es darum für eine bestimmte Art von Objekten die Ausprägung eines Zielmerkmals vorherzusagen. Für die Vorhersage wird ein Regelsystem basierend auf weiteren Merkmalen erstellt. Diese weiteren Merkmale, auf denen also die Vorhersage beruht nennt man Prädiktormerkmale.  

Regelknoten Ein Entscheidungsbaum besteht aus verschiedenen Knoten. Zu Beginn stehen immer Regelknoten, die anhand von Prädiktormerkmalen gebildete Entscheidungsregeln repräsentieren. Alle Knoten in einem Entscheidungsbaum, bis auf die jeweils letzten Knoten weines Pfades, sind Regelknoten.

threshold value Ein Schwellenwert ist eine Ausprägung, die zu einem numerischen Merkmal gewählt werden kann, um Objekte in Teildatensätze zu gruppieren. Die Teildatensätze ergeben sich aus den Objekten, deren jeweilige Ausprägung kleiner oder gleich dem Schwellenwert ist und denjenigen, deren jeweilige Ausprägung größer als der Schwellenwert ist.

Trainingsdaten Trainingsdaten sind ein Satz von Daten, die genutzt werden, um mit Hilfe von maschinellem Lernen einen Klassifikator (z. B. Entscheidungsbaum) zu erstellen.

test data Testdaten sind ein weiterer Satz von Daten, mit denen ein erstellter KLassifikator getestet wird. Trainings- und Testdaten sind disjunkt.

Zielmerkmal Beim überwachten maschinellen Lernen geht es darum für eine bestimmte Art von Objekten die Ausprägung eines Merkmals vorherzusagen. Das betreffende Merkmal nennt man Zielmerkmal.  

Überwachtes maschinelles Lernen (engl.: supervised learning) Überwachtes maschinelles Lernen wird angewandt, um Entscheidungsmodelle zu erstellen, die für eine bestimmte Art von Objekten vorhersagen über ein Zielmerkmal treffen zu können. (z.B. Klassifizieren von Lebensmitteln als “eher empfehlenswert” und “eher nicht empfehlenswert”). Damit das überwachte Lernen angewandt werden kann, benötigt man zuerst digitale Repräsentationen von Objekten, worin die Objekte anhand bestimmer (Prädiktor-)Merkmale beschrieben sind (z. B. Lebensmittel, die durch Nährwertangaben repräsentiert sind). Zusätzlich müssen für alle Objekte die gewünschten Ausprägungen des Zielmerkmals (z.B. eher empfehlenswert/eher nicht empfehlenswert) bekannt sein. Eine Sammlung von Beispielobjekten, denen Werte von Prädiktormerkmalen und Labeln zugeordnet werden, werden so zu einem Satz von Daten, der modellhaft eine ganze Klasse an Objekten repräsentiert. Mit diesen Daten können mit Hilfe von Lernalgorithmen verschiedene Arten von Regelsystemen/Entscheidungsmodellen (z.B. Entscheidungsbaum, neuronales Netz) erstellt werden. Den Erstellungprozess nennt man auch “Lernprozess” oder “Trainingsprozess” und die Daten, die dafür genutzt werden, nennt man Trainingsdaten. Das Verarbeiten der Daten in diesem gesamten Trainingsprozess kann man als “überwachtes maschinelles Lernen” bezeichnen und dabei wird das Regelsystem immer besser an die vorliegenden Daten angepasst, bis am Ende möglichst wenig Fehler bei der Zuordnung (Fehlklassifikationen) passieren. Im ersten Schritt wird ein Entscheidungsmodell also so trainiert, dass es die Trainingsdaten korrekt zuordnet. Zielstellung ist es aber eigentlich, dass das Entscheidungsmodell über die Trainingsdaten hinaus funktioniert und auch neue Objekte (z.B. neue Lebensmittel) korrekt zuordnet. Im Anschluss wird das Entscheidungsmodell mit neuen Objekten bzw. Daten getestet und evaluiert. Dann spricht man von Testdaten. Der Begriff „überwacht“  wird in diesem Zusammenhang genutzt, da für alle verwendeten Objekte in den Daten die Ausprägung des Zielmerkmals bekannt ist und daher genau überwacht werden kann, wie gut des erstellte Entscheidungsmodell für die Daten funktioniert. Ein solches gut funktionierendes Entscheidungsmodell kann man als KI bezeichnen.

Food data represented as data cards 

In the teaching unit, 55 data cards are used, each containing the typical seven nutritional values of a food item, as illustrated in Fig. 1 for an apple. The representation of food data on data cards, as in Fig. 1, and the subsequent work with data, connects for example to the topic of stochastics in the curriculum of North Rhine-Westphalia for lower secondary level (grades 5 and 6). From the very beginning, however, “multivariate” data – data with multiple attributes – are considered, which has long been emphasized in statistics education proposals as an essential component of statistical literacy. Similar connections can also be found in other curricula.

Using the data cards on food items, the teaching is guided by the following key question:

  • How can we, using the data cards, construct a recommendation system that classifies a food item, on the basis of its nutritional information, as rather recommendable or rather not recommendable with as few errors as possible?
Fig. 1: Data card for the food item "Apple"

Such a recommendation system is called a classifier, since individual objects (here: food items) are assigned to a class (“rather recommendable” or “rather not recommendable”) based on their characteristics (nutritional information), i.e. they are classified. The binary variable recommendation is referred to as the target variable, while the numerical nutritional variables are referred to as predictor variables.

Such a classifier is developed on the basis of a set of objects for which both the values of the predictor variables and of the target variable are known. These are the so-called training data. The ultimate goal, however, is that the recommendation also works for new objects. First, the system is tested with test data that were not involved in the training process but for which the values of the target variable are known. This makes it possible to estimate the probability with which the system classifies new objects with an unknown value correctly.

The data example consists of 40 blue cards for creating the recommendation system and 15 yellow cards for testing. Red and green paperclips are used in class to represent the agreed value of the target variable (also called the label).

A decision tree as a classifier

In the following, teachers are introduced to what a decision tree is and how such a tree can be constructed from data using data cards. The didactical implementation in the classroom will be addressed at a later point. A decision tree is a hierarchical system of rules that can be used as a classifier. An example of a decision tree for the previously described context is shown in Fig. 2. This rule system can, for instance, be used to classify the apple from Fig. 1 by traversing the decision tree from top to bottom and, depending on the values of the attributes fat and energy, following the corresponding branches. The first decision node checks the attribute fat. Since the apple contains less than 8 g of fat per 100 g, one takes the left branch and directly arrives at a terminal node (also called a leaf node) of the decision tree. A terminal node is always labeled with a value of the target attribute, which is then assigned to the object being classified. Accordingly, the apple is classified as “rather recommendable.” For a food item with a fat value greater than 8 g, however, one would need to take the right branch and, in a second step, also consider the energy value in order to arrive at a terminal node.

Fig. 2: A decision tree

This decision tree is merely an example and does not claim to classify food items in a meaningful way. In principle, such a decision tree can contain any number of levels and predictor variables. The aim of the teaching unit is that students create such a decision tree themselves on the basis of data and understand how computers can be set up to automatically generate decision trees from data (machine learning as part of AI).

Construct a data-based decision tree

A prerequisite for data-based construction of decision trees is the availability of a dataset consisting of a set of example objects for which the values of both the target variable and the predictor variables are known. In the following (Figures 3 and 4), we consider eleven food items as example objects, with their nutritional information specified on each card. These represent the values of the predictor variables such as fat, energy, etc. Furthermore, a green (or red) clip symbolizes whether the food item is classified as rather recommendable (or rather not recommendable), representing the value of the target variable. Based on such a dataset, a decision tree can be built step by step with the aim of classifying the training data with as few errors as possible.

Fig. 3: Creating a decision rule using a data split

The basis for constructing the decision tree is the so-called data split. That is, using one predictor variable and a threshold value, the dataset is divided into two subsets (Component 1). In Figure 3, we see a data split with the variable fat and the threshold of 8 g, meaning that all food items with more than 8 g of fat are on the right side, and those with up to 8 g of fat are on the left. In each subset, a majority decision regarding the target variable is then made (Component 2). In our example, the left subset contains only rather recommendable food items, while in the right subset the majority of items are rather not recommendable. The resulting decision rule (if ≤ 8 g fat, then rather recommendable; if > 8 g fat, then rather not recommendable) can be evaluated (Component 3) by determining the number of food items misclassified in the dataset (misclassifications). In our example, two food items are misclassified, namely avocado and fried egg on the right-hand side. When constructing a decision tree, data splits are chosen in such a way that these majority decisions produce as few misclassifications as possible. Finally, the resulting one-level decision tree can be represented (Component 4). This can be done verbally or by means of a typical tree diagram. In the representation of the decision tree, the data cards no longer appear. Instead of the cards (cf. Fig. 3), however, the distribution of the target variable in both subsets (4 to 0; 2 to 5) should be noted, so that the number of misclassifications remains transparent.

The one-level decision tree developed so far, which misclassifies two food items, can now be further improved by adding another level. The data cards in the left branch can be set aside, since everything there is already correctly classified. With the cards in the right branch, the procedure is the same as described for the first level. If the predictor variable energy and the threshold of 220 kcal are used for another data split, the resulting decision tree (see Fig. 2) correctly classifies all food items in this dataset.

Fig. 4: Sorted data cards for comparing data splits. For better readability, the fat values are noted above the cards.

A central aspect that has not yet been explained is how a variable and a threshold are selected for the first data split and for the subsequent ones in a “favorable” way—i.e., such that as few misclassifications as possible occur. With the data cards, this can be carried out by sorting and systematic trial and error.

Starting from the sorted data cards, different possible data splits and the resulting number of misclassifications can be compared. For a given dataset, we consider the split to be optimal that produces the smallest number of misclassified objects. In this example, the optimal split is the one visualized in Fig. 4, between the slice of wholemeal bread and the chicken nuggets. This can be verified by systematically examining all possible data splits. To do so, the separating vertical line is shifted step by step into each gap between two cards, and Components 1–3 (as explained earlier) are applied in each case to determine the number of misclassified objects. For example, a split between avocado and French fries results in three misclassified objects and is therefore to be rated as less favorable.

Once an optimal data split has been selected (in our example with two misclassified objects), a threshold can be chosen within the interval between the fat values of the two adjacent cards. In Fig. 4, the value 8 was chosen as the threshold within the interval between 4.9 and 11.0. For all other predictor variables, an optimal split can likewise be determined, after which the predictor variable is selected that yields the smallest possible number of misclassified food items. This means that a so-called greedy strategy is applied: one first searches for the best one-level decision tree, and only then considers the second level and decides whether further splits are required. At each stage, the best variable with its optimal split in the respective subset of the data is selected. It is essentially this systematic method that is implemented in professional decision tree algorithms. These also include suitable stopping criteria. In classroom practice, however, examining all possible splits is very laborious for students, so (initially) somewhat simplified strategies can be applied, which will be explained in the next section. These strategies follow the same approach and can therefore provide a foundation for understanding how a machine proceeds automatically, exhaustively, and systematically.

Materials

Download of all materials

Hier können Sie alle Arbeitsblätter, Hilfszettel und Hinweisblätter als komprimierten Ordner herunterladen:

Eine Druckvorlage für die Datenkarten finden Sie hier:

Zwei Klassensätze der Datenkarten können Sie hier bestellen:

Further information

Learning path for pupils - decision trees with data cards

The learning path “Decide like an AI” was created in cooperation between ProDaBi and inf-schule.de. It offers a supplement to the food data cards developed in ProDaBi and the corresponding series of lessons on decision trees.
The learning path is prepared for pupils and has the following introductory text: “In this learning path, you are to create an artificial intelligence (AI) that decides whether a food is recommended or not recommended based on its nutritional values. You will train your AI yourself with selected foods in order to have a decision-making aid for other foods afterwards.”

Links:

Informationen über Maschinelles Lernen

Maschinelles Lernen ist ein weiter Bereich, der verschiedene Methoden und Lernalgorithmen für das automatische Lösen unterschiedlichsterer Aufgabentypen umfasst. Das verbindende Element zwischen allen Methoden die zum maschinelle Lernen gehören ist, dass sie auf Trainingsdaten beruhen. Wir konzentrieren uns auf die Unterart des überwachten Lernens, insbesondere auf Klassifikationsaufgaben, die mit Entscheidungsbäumen gelöst werden können.
Bei der Klassifikation geht es darum, Objekte oder Individuen einer Population mit (idealerweise) korrekten Labels in Bezug auf eine bestimmte Fragestellung zu versehen. In der Statistik ist eine Population eine Menge von ähnlichen Individuen, Objekten oder Ereignissen, die für eine bestimmte Frage oder statistische Untersuchung von Interesse sind. Typische Beispiele für Klassifikationsaufgaben sind die Zuordnung eines Patienten (Individuum) zu einer Diagnose (Etikett) oder die KLassifikation von E-Mails als “Spam” oder “kein Spam”. Die möglichen Labels stammen aus einer Label-Menge, je nachdem, ob man von einem binären Klassifikationsproblem (zwei mögliche Labels) oder einem Multiklassen-Klassifikationsproblem (eine endliche Menge von mehr als zwei Labels) spricht.

Die Aufgabe eines Lernalgorithmus besteht darin, einen Klassifikator zu erstellen, der für jedes beliebige Objekt in der Population ein Label vorhersagt. Um eine fundierte Vorhersage zu treffen, wird ein Objekt durch eine Reihe von Merkmalen repräsentiert, die als Vektor dargestellt werden. Da die Merkmale die Wahl des vorhergesagten Labels beeinflussen, werden sie als Prädiktorvariablen bezeichnet. Die Labels sind die Werte einer so genannten Zielvariable. Die Erstellung eines Klassifikators basiert auf Trainingsbeispielen, d. h. auf Objekten aus der Grundgesamtheit, von denen die Werte der Prädiktorvariablen und die korrekten Labels bekannt sind. Ein Satz von Trainingsbeispielen wird als Trainingsdaten bezeichnet. Als Maß für den Erfolg wird in der Praxis  anhand von Testdaten  die Fehlklassifikationsrate berechnet. Die Testdaten sind strukturell identisch mit den Trainingsdaten, wurden aber nicht zur Erstellung des Klassifikators verwendet.

Entscheidungsbäume werden algorithmisch aus Daten konstruiert, um als Klassifikatoren zu dienen. Besonders wenn der Baum nicht zu groß ist, macht die Verwendung einer hierarchischen Baumstruktur die Entscheidung sehr transparent und verständlich.

Informationen zum Nutri-Score

Ein Infoblatt zum Nutri-Score und der einfacheren Kategorisierung in der ProDaBi Unterrichtsreihe finden Sie hier:

Kurzübersicht über die Inhalte der Unterrichtsstunden

Citation:

Fleischer, Y., Podworny, S., Biehler, R., Schulte, C., Höper, L. & Hüsing, S. (2023). Entscheidungsbäume mit Datenkarten - Apfel oder Popcorn? Eine enaktive Einführung in KI, maschinelles Lernen und Entscheidungsbäume mit Datenkarten. https://www.prodabi.de/materialien/entscheidungsbaeume/

Veröffentlicht am 07.04.2025

Version:

License note:

Creative Commons Attribution-ShareAlike (CC BY-SA 4.0)

Nach oben scrollen