What is a decision tree?
A decision tree is a model that predicts by asking a sequence of yes/no questions about the input, such as "is x ≤ 0.4?". Each internal node holds one question, each branch is an answer, and each leaf holds a prediction: the majority class for classification or the mean target for regression. Training grows the tree greedily, picking at each node the question that best separates the training labels.
Trees handle numeric and categorical features, need no feature scaling, and can be read as a set of if-then rules, which makes them popular in credit scoring, medical triage, and other settings where a decision has to be explained. A single deep tree overfits easily, so trees are most often used as building blocks. Random forests average hundreds of them, and gradient boosting libraries such as XGBoost and LightGBM add them up one at a time. Those ensembles remain among the strongest models for tabular data.
Key ideas
- A decision tree predicts by routing an input through a series of feature-threshold questions to a leaf.
- Each split is chosen greedily to give the largest drop in impurity, measured by Gini or entropy.
- Every split tests one feature, so the decision regions are axis-aligned rectangles.
- Deeper trees fit the training data more closely and memorize noise more easily.
- Pruning and limits on depth or leaf size trade some training accuracy for better test accuracy.
- Trees need no feature scaling and are the base learners in random forests and gradient boosting.
Common questions
Can decision trees be used for regression?
Yes. A regression tree predicts the mean target value of the training points in each leaf and picks the splits that most reduce squared error. Its prediction is a step function that is constant within each region. CART handles classification and regression with the same algorithm.
Do decision trees need feature scaling?
No. A split compares one feature to a threshold, so any monotonic transformation of that feature, such as standardizing it or taking its log, leaves the set of possible splits unchanged. Distance-based methods such as k-nearest neighbors and SVMs are different and need scaled features.
How do decision trees handle categorical features?
A tree can split a categorical feature by sending some categories left and the rest right. Many libraries expect numeric input, so categories are often one-hot or ordinal encoded first. LightGBM and CatBoost can split on categorical features directly.
How is feature importance computed for a decision tree?
The usual measure adds up the impurity reduction from every split that uses a feature, weighted by the number of samples reaching that split, and normalizes the totals. It is cheap to compute but tends to favor features with many distinct values. Permutation importance, which measures how much accuracy drops when one feature's values are shuffled, is a common cross-check.
Related explainers
- Bagging & Random Forests — Bootstrap aggregation and decorrelated tree ensembles
- Gradient Boosting — Sequential residual fitting for powerful predictions
- Overfitting & Underfitting — The bias-variance tradeoff and generalization
- Bias-Variance Tradeoff — Why models underfit or overfit — the fundamental decomposition
- Entropy & Cross-Entropy — Measuring surprise, uncertainty, and prediction quality
- K-Nearest Neighbors — Classification by proximity and distance metrics
References
- James, Witten, Hastie & Tibshirani, "An Introduction to Statistical Learning", chapter 8: Tree-Based Methods
- Quinlan (1986), "Induction of Decision Trees", Machine Learning
- Breiman, Friedman, Olshen & Stone (1984), "Classification and Regression Trees"
Last updated