ID3 mushroom classification
A from-scratch ID3 decision tree that predicts whether a mushroom is edible or poisonous from its attributes.
- Type
- School
- Year
- 2020
- Built with
- Python · Decision trees · Information gain
A colleague and I implemented the ID3 algorithm from scratch, then trained it on mushroom attributes to classify each specimen as edible or poisonous.
Building a decision tree by hand — computing entropy and information gain at each split rather than calling a library — is the fastest way I know to understand why trees overfit, and why the split that looks most informative on training data is so often the one that betrays you.
The tree below was retrained with the same algorithm on the full UCI Mushroom dataset — 8,124 specimens, 22 attributes each. It asks about smell first, and for most mushrooms that’s the only question it needs. The odourless ones are where it has to work.
Mini game
Is it poisonous?
A real specimen from the dataset. Make your call, then see what the tree says.
- Score
- 0 / 0
- Streak
- 0
- Best
- 0
Specimen
- cap-shape
- —
- cap-surface
- —
- cap-color
- —
- bruises
- —
- odor
- —
- gill-attachment
- —
- gill-spacing
- —
- gill-size
- —
- gill-color
- —
- stalk-shape
- —
- stalk-root
- —
- stalk-surface-above-ring
- —
- stalk-surface-below-ring
- —
- stalk-color-above-ring
- —
- stalk-color-below-ring
- —
- veil-type
- —
- veil-color
- —
- ring-number
- —
- ring-type
- —
- spore-print-color
- —
- population
- —
- habitat
- —
The whole tree · 8,124 training specimens, 0 misclassified
- odor?8,124 specimens
- nonespore-print-color?3,528 specimens
- brownedible1,344 specimens
- blackedible1,296 specimens
- whitehabitat?624 specimens
- grassesedible288 specimens
- wasteedible192 specimens
- leavescap-color?64 specimens
- cinnamonedible24 specimens
- brownedible24 specimens
- whitepoisonous8 specimens
- yellowpoisonous8 specimens
- woodsgill-size?40 specimens
- narrowpoisonous32 specimens
- broadedible8 specimens
- pathsedible40 specimens
- greenpoisonous72 specimens
- chocolateedible48 specimens
- orangeedible48 specimens
- yellowedible48 specimens
- buffedible48 specimens
- foulpoisonous2,160 specimens
- fishypoisonous576 specimens
- spicypoisonous576 specimens
- almondedible400 specimens
- aniseedible400 specimens
- pungentpoisonous256 specimens
- creosotepoisonous192 specimens
- mustypoisonous36 specimens
- nonespore-print-color?3,528 specimens
A toy trained on 23 species of Agaricus and Lepiota from a 1981 field guide. It cannot tell you whether the mushroom in your hand is safe — please don't use it for real foraging.
Details and results are in the research report.