VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 10: Trees and BSTs

Lesson 10.14 of 14 in this module Unrolled Pro

Predict with a Decision Tree

Run a trained decision tree on new samples. From flattening the tree into if-then rules and testing every rule against every sample (O(leaves × depth) per sample), to walking one root-to-leaf path (O(depth)), to the flat parallel arrays that libraries store trees in, where prediction is a tight loop over integers. Then ensembles that sum many trees (gradient boosting) or vote (random forests), missing feature values with a learned default direction, explaining a prediction by its decision path, and processing a whole batch level by level.

about 10 min 4 Python examples 2 quick checks

Problem. A trained decision tree has internal nodes that test one feature against a threshold ("go left if x[feature] ≤ threshold") and leaves that hold a prediction. Given the tree and a batch of samples, return the prediction for each sample.

text
            income ≤ 40k?
           /             \
       age ≤ 25?        debt ≤ 10k?
       /      \          /       \
   "deny"  "review"  "approve"  "review"

x = {income: 52k, debt: 4k, age: 31}   →   income > 40k → debt ≤ 10k → "approve"

This is the payoff of the module: a decision tree is a binary tree, and predicting is a walk from the root to a leaf. The interesting engineering is how to make that walk fast for millions of samples and hundreds of trees, which comes down to how the tree is stored.

Why it matters. Gradient-boosted trees (XGBoost, LightGBM, CatBoost) are still the strongest models on most tabular data and run in production fraud, ranking and pricing systems that score millions of rows per second. Their prediction code is a few lines of tree walking over flat arrays, repeated across hundreds of trees (Change A).


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Predict with a Decision Tree"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee