CoursesAIMathCodePhysicsAbout and FAQ

TwiddleLab / Artificial Intelligence / Learning From Data

Twenty Questions: Decision Trees

Lesson 3 of 11 · 6 min · Free, no account needed

What you will learn

  • A decision tree answers with a chain of yes or no questions about the features.
  • Each question is a split that cuts the map into boxes; each final box is a leaf with an answer.
  • Fewer questions that still sort the critters make a tree you can trust and explain.
  • More questions can fit every studied critter, even the odd ones. That isn't always good.

Start the lesson

How the lesson goes

  1. Can a machine learn which yes or no questions to ask?

    Like twenty questions, about critters. Start with one cut. Draw a straight line, up-down or across, that best separates Puffs (green) from Zips (orange). Then Check.

  2. Ask one question. Drag the cut to make as few mistakes as you can.

    Pick ear length or tail length, then drag the violet tab. Each side answers with its most common kind.

  3. Grow a tree: ask a second question inside the mixed box.

    Tap a box, then a question. The machine puts the best cut for that question inside that box. Get to 0 mistakes, then Check.

  4. Your questions have names.

    Tap to reveal them.

    Each question is a split: it cuts one box of the map into two.

    A box with no more questions is a leaf. It answers with the most common kind inside it.

    Questions and leaves together make a decision tree. A machine grows one by picking, at each box, the question that leaves the fewest mistakes.

  5. Tree golf.

    A new island of critters. Grow a tree with 0 mistakes in as few questions as you can. Par is 3.

  6. Run your tree on four new critters.

    Before each drop, tap the leaf you think the critter will land in. Then press Drop and watch it roll down.

  7. Two trees, the same 24 studied critters. Which would you trust?

    Press Try new critters on both trees. Then tap the one you'd send to the field station, and Check.

  8. Code: a tree is just if and else.

    This is the tree from the start of the lesson, written in Python (Decisions: if). One print is wrong. Run it, find the bug, tap the line to fix it, then Check.

  9. A critter has ears of 3.5 cm and a tail of 3 cm. Where does it land?

    Follow the questions from the top. Tap the leaf, then Check.

  10. Let the tree ask more and more questions.

    These 30 studied critters include a few odd ones. Slide the limit on questions and watch the studied score.

Previous lesson: Ask Your Neighbors: kNN · Next lesson: Train, Test, Don't Peek · Part of the course: Learning From Data

Lessons are interactive and need JavaScript. Turn it on to play them.

Loading TwiddleLab