English:Decision trees and interpretable classification - AI Year 7
Introduction

Build and trace a three-test classification tree, prove one branch unreachable and prune it without changing valid outputs. Then compare a deliberately fitted detail on training and separate cases, using complete original Python and clearly stated evidence limits.
Construct a three-test tree and trace six original records
Read a classification tree as a sequence of tests
A decision tree connects feature tests to branches and final outputs. A root is the first test, an internal node is another test, and a leaf gives an output such as a class label. A path explains which conditions this model followed for one input. A visible path can help you inspect a result; it does not by itself establish that the input, labels or chosen rules are correct.
CodeAI: AI, What is Machine Learning? Connect the verified introduction with the difference between a supplied rule and learning a rule from examples. Our starting tree is teacher-supplied. A later deliberately narrow extension uses training labels to fit one detail. This course does not implement a general decision-tree training library or claim that every diagram was learned automatically.
Construct the supplied tree with three test nodes
Use fictional leaf cards with shape oval or pointed, a height proxy in centimetres greater than zero and at most 100, and artificial classes A, B and C. These are invented drawing-card features and class codes, not species identification, plant health advice or real measurements. Missing, unknown or out-of-contract features return ASK in the program.
Draw N1 at the top, N2 on its yes branch and N3 on N2's yes branch. Add the labelled outputs and connect both branches of each test. There are three test nodes in total; not every input visits all three. A pointed card stops after N1, while a short oval card visits three tests.
| Node | Test | Yes branch | No branch |
|---|---|---|---|
| N1 | Is the shape oval? | Go to N2 | Output A |
| N2 | Is height at most 15 cm? | Go to N3 | Output C |
| N3 | Is height at most 20 cm? | Output B | Output A; investigate whether reachable |
For an oval card with height 12, N1 is yes. N2 is yes because 12 is at most 15. N3 is yes because 12 is at most 20, so the output is B. At height exactly 15, the at-most condition is still true. At height just above 15, N2 is false and the output is C. The endpoint belongs to the branch that the stated comparison defines.
Trace six records and distinguish output from supplied label
The six original training records below include a final exceptional B label. It is a supplied fictional class, not a statement that a real leaf was measured or mislabelled. Trace the starting tree before looking at the last column. Keep its predicted output separate from the supplied label, including a mismatch.
| Record | Shape | Height cm | Supplied label | Actual path | Tree output |
|---|---|---|---|---|---|
| T1 | pointed | 8 | A | N1 shape is oval: no | A |
| T2 | pointed | 20 | A | N1 shape is oval: no | A |
| T3 | oval | 12 | B | N1 shape is oval: yes then N2 height at most 15: yes then N3 height at most 20: yes | B |
| T4 | oval | 15 | B | N1 shape is oval: yes then N2 height at most 15: yes then N3 height at most 20: yes | B |
| T5 | oval | 18 | C | N1 shape is oval: yes then N2 height at most 15: no | C |
| T6 | oval | 22 | B | N1 shape is oval: yes then N2 height at most 15: no | C |
T6 has supplied label B while the starting tree outputs C. Do not erase that mismatch or silently change the label to make the tree perfect. The question is whether an added rule is justified by appropriate evidence, rather than whether you can make this small training table match exactly.
Prune a branch fit a narrow detail and compare separate cases
Prove one branch unreachable and prune it
You reach N3 only after N2 has answered yes, meaning height is at most 15. Such a height is also at most 20, so N3 cannot answer no under the declared feature contract. The specific no branch from N3 is unreachable. Class A itself is still reachable for pointed cards at N1; an unreachable branch is not the same as an unreachable class everywhere.
Prune the unnecessary N3 test by replacing that whole subtree with B. The remaining supplied tree has two tests: pointed goes to A; oval at most 15 goes to B; other valid oval inputs go to C. This pruning preserves every valid input's output because of the logical condition, not merely because six examples happen to match. Keep the original version and compare traces. Unknown or invalid features still return ASK.
Fit a deliberately narrow detail from training only
Now compare the pruned rule with the six supplied labels. Only T6, the oval card at 22, disagrees. Our teaching variant places a narrow B interval around that one training exception: 21.5 through 22.5, inclusive. The centre comes from T6. The half-unit radius is a declared classroom choice, not optimised on the later test cases or known as an appropriate botanical tolerance.
The extension is considered only on the existing C branch. It tests whether height is at least 21.5, then whether it is at most 22.5. If both are true, it outputs B; otherwise C remains. Pointed and short-oval outputs remain as before. This detailed version has two original pruned tests plus two extra tests. It is a narrowly fitted teaching variant, not CART, a general induction method or a claim that this interval is naturally meaningful.
Keep four separately prepared test records out of fitting
| Test record | Shape | Height cm | Prepared expected label |
|---|---|---|---|
| E1 | pointed | 9 | A |
| E2 | oval | 13 | B |
| E3 | oval | 19 | C |
| E4 | oval | 22.25 | C |
The pruned rule matches five of six training labels; the more detailed variant matches six of six. On the four separate test records, the pruned rule matches all four, while the detailed variant matches three. E4 at 22.25 is in the fitted B interval but has expected class C. A fixed A baseline matches only E1. These counts belong to the original classroom fixtures, not a survey of real classification performance.
This is a counterexample to the claim that deeper is always better. It does not prove that shallower is always better or that every exception should be removed. Relevant extra structure may help a different task. The point is to inspect the assumptions and use evidence that was not used to fit the detail. One small successful test set still does not certify generalisation.
Inspect and run the complete original program
Trace on paper, or use an approved Python environment. The standard-library code records each supplied-tree path, applies the logically equivalent prune, fits the one exceptional interval from TRAIN only and evaluates the separate records. It has no account, external model, real sensor or plant-care interface.
"""Original fictional leaf cards; no botanical identification or real plant data."""
from copy import deepcopy
import json
TRAIN = [["T1", "pointed", 8, "A"], ["T2", "pointed", 20, "A"],
["T3", "oval", 12, "B"], ["T4", "oval", 15, "B"],
["T5", "oval", 18, "C"], ["T6", "oval", 22, "B"]]
TEST = [["E1", "pointed", 9, "A"], ["E2", "oval", 13, "B"],
["E3", "oval", 19, "C"], ["E4", "oval", 22.25, "C"]]
def valid_features(shape, height):
return (type(shape) is str and shape in ["oval", "pointed"]
and type(height) in [int, float] and height > 0 and 100 >= height)
def trace_tree(shape, height, pruned=False):
if not valid_features(shape, height):
return dict(label="ASK", path=["outside the declared feature contract"])
path = []
oval = shape == "oval"
path.append(["N1 shape is oval", oval])
if not oval:
return dict(label="A", path=path)
short = 15 >= height
path.append(["N2 height at most 15", short])
if not short:
return dict(label="C", path=path)
if pruned:
return dict(label="B", path=path)
redundant = 20 >= height
path.append(["N3 height at most 20", redundant])
return dict(label="B" if redundant else "A", path=path)
def validate_records(rows):
if type(rows) is not list or not rows:
raise ValueError("Use nonempty fictional labelled records")
seen = set()
for row in rows:
if type(row) is not list or len(row) != 4:
raise ValueError("Use identifier shape height and class")
rid, shape, height, label = row
if type(rid) is not str or not rid or rid in seen:
raise ValueError("Use unique nonempty record identifiers")
if not valid_features(shape, height) or type(label) is not str or label not in ["A", "B", "C"]:
raise ValueError("Record outside the declared contract")
seen.add(rid)
def fit_narrow_detail(training):
validate_records(training)
differences = [r for r in training if trace_tree(r[1], r[2], True)["label"] != r[3]]
if not differences:
return None
if len(differences) != 1:
raise ValueError("This teaching variant expects one exceptional training record")
row = differences[0]
if row[1] != "oval" or not row[2] > 15 or row[3] != "B":
raise ValueError("Exception outside this deliberately narrow teaching variant")
return dict(source_id=row[0], centre=row[2], lower=row[2] - .5, upper=row[2] + .5)
def trace_detailed(shape, height, detail):
result = trace_tree(shape, height, True)
if result["label"] != "C" or detail is None:
return result
above_lower = height >= detail["lower"]
result["path"].append(["D1 height at least lower bound", above_lower])
if not above_lower:
return result
below_upper = detail["upper"] >= height
result["path"].append(["D2 height at most upper bound", below_upper])
if below_upper:
result["label"] = "B"
return result
def evaluate(rows, predictor):
validate_records(rows)
outputs = [predictor(r[1], r[2])["label"] for r in rows]
return dict(total=len(rows), matches=sum(p == r[3] for p, r in zip(outputs, rows)), outputs=outputs)
def demonstrate():
detail = fit_narrow_detail(TRAIN)
base = lambda shape, h: trace_tree(shape, h, True)
deeper = lambda shape, h: trace_detailed(shape, h, detail)
return dict(training=deepcopy(TRAIN), tests=deepcopy(TEST),
six_supplied_tree_paths=[trace_tree(r[1], r[2]) for r in TRAIN],
fitted_detail=detail, pruned_training=evaluate(TRAIN, base),
detailed_training=evaluate(TRAIN, deeper), pruned_test=evaluate(TEST, base),
detailed_test=evaluate(TEST, deeper),
held_out_records_used_for_fitting=False)
if __name__ == "__main__":
print(json.dumps(demonstrate(), indent=2))The complete program was actually executed. It gives the six paths shown above, a centre of 22 and bounds 21.5 and 22.5, training matches five versus six, and test matches four versus three. No test record is passed to fit_narrow_detail. If you change a fixture, declare your expected result first and record the actual version and output; do not present a paper prediction as an observed run.
Interpret paths test boundaries and construct a new tree
Interpret a path without claiming a real cause
The oval-12 path explains why this supplied program returns B: the input satisfies the model's stated conditions. It does not explain why a real species has a particular shape, whether class B is a useful category or whether another representation would be better. Traceability makes assumptions inspectable; it does not turn them into facts about the world.
CodeAI: AI, Training Data & Bias. Ask how feature and example choices influence a system's scope. Our two features omit many possible details and all records are invented. Do not turn artificial classes or trace lengths into judgements about people. The introductory Commons image illustrates flexible fitting around example points; it is not a plot of these leaf cards or a rendered version of our tree.
Design boundaries that follow the comparisons
For the supplied tree, compare oval heights just below 15, exactly 15 and just above 15. For the detailed extension, compare 21.49, 21.5, 22, 22.5 and 22.51. The endpoints 21.5 and 22.5 are included in B, while the immediate outside examples stay C. A pointed card at the same heights remains A because the extra tests occur only after the oval/high path.
Then try zero, a negative value, a missing height, an unknown shape, a boolean or a non-finite number. The declared classroom input contract rejects these with ASK instead of pretending a valid class was observed. This contract is for a small example, not a complete treatment of missing data in every decision-tree library.
Test pruning with both path reasoning and a range of valid inputs. The argument that at most 15 implies at most 20 is stronger than simply observing no failure in a few examples. A sampled program check still helps detect a coding error, but it is not a replacement for stating the logical reason.
Construct a new three-test tree for a fictional archive
Suppose an original card archive needs review trays rather than plant classes. You have declared fields audio_present, transcript_present and illustration_present, each yes or no. Make a root test for audio_present. On its yes branch, test transcript_present to select an audio-ready or transcript-review tray. On its no branch, test illustration_present to select an illustrated or text-only tray. This is three tests in total, with at most two visited on a path.
This is a worked paper construction guide, not an executed archive service or an automatically learned tree. Supply cases for all four leaves, then change one field at a time to trace the intended route. If a field is missing, choose and justify a manual review route. Reconsider whether the trays, source permissions and features fit the real purpose before any practical implementation; the old height thresholds have no role here.
Preserve evidence and decide proportionately
Keep your three-test construction, six paths, unreachable-branch argument and pruned version. Add the separately prepared test table, the detailed interval's training and test counts, baseline comparison, boundary predictions and actual results or a labelled paper trace. Explain which part was supplied, which detail was fitted and what remains untested. If a label or feature is uncertain, document it and request review rather than adding complexity solely to hide an error.
Interactive Tasks
Quiz: Test Your Knowledge
What does a leaf in this classification tree provide? (An output class label) (!A guarantee of real species identity) (!A numeric reward for an agent) (!A new training record on every visit)
How many supplied test nodes are drawn before pruning? (Three in total) (!Three on every input path) (!Two in total) (!Six because there are six records)
What is the supplied-tree output for oval and height twelve? (B) (!A) (!C) (!ASK because twelve is never valid)
Why can the no branch from N3 not be reached? (Reaching N3 already requires height at most fifteen) (!Class A cannot be reached anywhere in the tree) (!Every oval card has height exactly twelve) (!The program ignored all comparisons)
What does pruning N3 preserve? (Every valid input output under the stated comparisons) (!Only the first training label) (!A universal guarantee about future real plants) (!The maximum number of tests on a short oval path)
Where does the fitted interval centre come from? (The exceptional training record T6 at height twenty-two) (!The later E4 outcome) (!An actual greenhouse measurement) (!A globally optimal tree search)
What is declared rather than optimised from the later test records? (The half-unit interval radius) (!The actual label of each real species) (!The future performance of every tree) (!The observation of learner mastery)
Which version matches more of the four prepared test labels? (The pruned rule with four matches) (!The detailed rule with six test matches) (!The fixed A baseline with four matches) (!Every version matches all four)
What happens for oval height twenty-two point two five in the detailed variant? (It outputs B inside the fitted interval) (!It outputs A because the shape is pointed) (!It returns the expected C automatically) (!It adds E4 to fitting before prediction)
What follows from the deeper-tree counterexample? (More detail can improve training fit while harming separate cases) (!A shallower tree is always best) (!Every exception should be erased) (!A visible path proves real-world causation)
Memory Game
| Root | The first test in a decision tree |
| Branch | A route following a test outcome |
| Leaf | A final output location |
| Feature | An input detail used by a test |
| Pruning | Removing or simplifying part of a tree |
| Overfitting | Fitting detail that does not transfer well to new cases |
Drag and Drop
| Start with the first shape question | Root test |
| Follow the stated yes or no outcome | Branch selection |
| Give the reached class output | Leaf prediction |
| Remove a logically unnecessary test | Output-preserving pruning |
| Keep later cases out of fitting | Separate evaluation |
Crossword Puzzle
| ROOT | What is the first test location? |
| BRANCH | What route follows a test outcome? |
| LEAF | What location provides a final output? |
| FEATURE | What input detail can a test use? |
| PRUNING | What can remove an unnecessary subtree? |
| DEPTH | What describes the length of a path through tests? |
LearningApps
Optional extra practice. Choose an appropriate activity with your teacher. If the external collection is unavailable, use the native activities and independent tasks in this course.
Cloze Text
Open Tasks
Easy
- Construct the supplied tree: Draw N1, N2 and N3 with both branches and all outputs; distinguish total test nodes from tests visited on a path.
- Trace six records: Follow all six original cards, keep predicted outputs separate from supplied labels and retain the T6 mismatch.
- Explain the unreachable branch: Use the conditions leading to N3 to show why its no branch is unreachable while class A remains reachable elsewhere.
- Prune and compare: Replace N3 with its justified output, redraw the tree and explain why valid outputs are preserved.
Standard
- Reconstruct the fitted detail: Find the exceptional training record, calculate the stated half-unit interval and identify the two additional tests.
- Compare training and separate evidence: Report five-versus-six training matches and four-versus-three test matches, including which record changes and a fixed A baseline.
- Test the thresholds: Predict and check values around fifteen and both fitted-interval endpoints; repeat with pointed shape and invalid input cases.
- Explain interpretability limits: Use the oval-twelve path to distinguish a program explanation from real-world truth, feature suitability and causation.
Advanced
- Construct a new three-test tree: Use the archive fields to build the worked paper tree, supply cases for all leaves and justify a manual route for missing fields.
- Review a complexity claim: Use the original counterexample to challenge deeper-is-always-better without replacing it with shallower-is-always-better.
- Plan independent follow-up evidence: Propose new original cases and a development versus final-test plan for a revised rule; state what a small result cannot establish.
- Transfer to a new classification purpose: Choose fictional inputs, outputs, source rights and error costs, explain which old thresholds must be discarded and design an inspectable human review path.
Learning Check
- Construct and trace the supplied tree: How do N1, N2 and N3 route an oval card at 12 and a pointed card at 20?
- Justify pruning logically: Which exact branch is unreachable and what replaces N3?
- Explain the fitted interval honestly: How is the detail fitted and what is not learned?
- Compare the actual results: What do the training and separate test counts establish?
- Check input and threshold boundaries: What should happen at 15, 21.5 and 22.5 and outside the feature contract?
- Transfer a three-test construction: How does the archive tree differ from the leaf-card example?
Worked checks and assessment guidance
- N1 tests oval shape. A pointed card returns A immediately. An oval 12 card reaches N2, satisfies at most 15, reaches N3, satisfies at most 20 and returns B. There are three supplied tests in total but different path lengths. These are artificial classes and drawing-card values, not real species identification.
- To reach N3, an oval input must already satisfy height at most 15. It therefore satisfies at most 20, so the no branch from N3 cannot occur under the stated contract. Replace N3 with B. Class A remains reachable from N1 for pointed inputs. The output-preserving argument applies to valid inputs generally, not only the six observed traces.
- The pruned rule disagrees only with training record T6, oval height 22 with supplied label B. The centre comes from that record; the radius 0.5 is a declared classroom choice, giving inclusive bounds 21.5 and 22.5. Two extra tests modify the existing C branch. This is a narrow teaching variant, not general tree induction, a botanical tolerance or a fit to the held-out outcomes.
- The pruned rule matches 5 of 6 training labels; the detail matches 6 of 6. On four separately prepared test cases, the pruned rule matches 4 and the detail 3 because E4 at 22.25 is sent to B while its expected class is C. Fixed A matches one test case. This counters an always-better claim for depth, without proving every shallow rule better or estimating real-world accuracy.
- For oval input, exactly 15 belongs to the short B branch. In the detailed high branch, 21.5 and 22.5 are included in B; neighbouring outside examples remain C. Pointed inputs remain A. Missing, unknown, boolean, non-finite and nonpositive or over 100 heights return ASK under the declared fictional contract. Preserve expected and actual results or label a paper trace.
- Use audio_present at the root, transcript_present on its yes branch and illustration_present on its no branch. That gives three total tests, four reachable trays and at most two visited tests per path. It is a paper construction unless actually implemented and tested. Recheck field meaning, permissions, missingness and error costs; the old height thresholds and artificial plant classes do not transfer.
Learning evidence
Retain a constructed three-test tree, six path traces with predictions separate from labels, a logical unreachable-branch argument, original and pruned versions, the training-only narrow-detail derivation, training/test and fixed-baseline comparisons, expected and actual boundary results or an explicitly labelled trace, and a new three-test archive construction with missing-field review. Distinguish supplied rules, fitted detail, executed program and paper design. No botanical identification, independent expert certification, practical mastery or complete curriculum coverage is implied.
OER and Wikipedia
DfE Computing, Key Stage 3 supplies the broader algorithms context. This AI Year 7 placement, tree construction and task design are editorial enrichment. scikit-learn: Decision trees, overview and limitations explains tree rules, interpretability and over-complexity risks. scikit-learn: Common pitfalls supports separating development and evaluation. Relevant primary sections read 15 November 2026. Our teacher-supplied tree and single-record interval fitter are original code, not the scikit-learn implementation or a complete induction algorithm.
Overfitting.svg, Chabacano, CC BY-SA 4.0. Original overfitting illustration unchanged; it is not a diagram of the supplied tree or a plot of the fictional leaf cards.
https://www.youtube.com/watch?v=OeU5m6vRyCk — CodeAI: AI, What is Machine Learning? https://www.youtube.com/watch?v=x2mRoFNm22g — CodeAI: AI, Training Data & Bias. Actual publisher and verified playability/embedding/preview evidence retained; recordings embedded unchanged. No copied transcript, endorsement or relicensing implied.
All feature values, labels, tree rules, interval choices, test cases, code and archive transfer are original fictional classroom material. The complete standard-library Python was actually executed and independently checked. The archive construction is explicitly a paper guide, not an executed service. No plant sampling, pupil data, paid API, local generative LLM, real sensor or deployment is used.
Linked learning areas
aiMOOC Projects
Schulfach+


aiMOOCs


aiMOOC Projekte


MOOCwiki · Deutsch
Nach dem Lernen ist vor dem Lernen
Entdecke direkt den nächsten Lernkurs. Weitere Inhalte erscheinen, wenn Du weiter nach unten scrollst.
Zur MOOCwiki-HauptseiteMediathek
Mediathek wird aus dem Wiki geladen ...
Keine passenden Inhalte gefunden. Bitte ändere Suche oder Filter.
NEWSLernweltNOAH fragen