Imagine predicting whether a shipment will arrive late. One decision tree relies heavily on the dispatch hour. Another uses route length and depot backlog. Combining the two can make the prediction less sensitive to a rule learned from one slice of the training data. A random forest applies this idea across many trees.
A random forest is an ensemble of decision trees trained with randomness. Each tree learns its own splits. The forest combines their predictions, typically by averaging class probabilities for classification or numeric predictions for regression.
Two choices make the trees different
In a typical random forest, each tree trains on a bootstrap sample. Sampling with replacement means the same row can appear several times in one tree’s sample while other rows are left out. Different samples give trees different examples to learn from.
At each split, the tree considers a random subset of features, subject to the implementation and settings. A strong predictor can still help. Limiting which features compete at each split gives other predictors a chance to form rules, which can reduce how strongly the trees’ errors are correlated. The trees train independently and their predictions are combined at the end. Scikit-learn ensemble guide.
Follow one shipment through five trees
Suppose five trees give the following estimated probabilities that a shipment will be late. These are invented values to show the arithmetic. In scikit-learn, a tree’s class probability is derived from the class proportions in the leaf reached by the example, with sample weights reflected if used.
| Tree | Late probability | Label at a cutoff of 0.50 |
|---|---|---|
| 1 | 0.90 | Late |
| 2 | 0.49 | On time |
| 3 | 0.48 | On time |
| 4 | 0.47 | On time |
| 5 | 0.46 | On time |
Hard voting would give “on time” four votes. The average probability is (0.90 + 0.49 + 0.48 + 0.47 + 0.46) ÷ 5 = 0.56. At the same cutoff, averaging gives “late.” This is why you should check what a library aggregates before interpreting its output.
With regression, each tree predicts a number. If three trees predict delays of 8, 14, and 20 minutes, their mean is 14 minutes. The forest can dampen unusually high or low predictions from individual trees, though systematic errors shared by the trees can remain.
Use out-of-bag error as a training diagnostic
A tree’s out-of-bag examples are the training rows omitted from its bootstrap sample. For a given row, combine predictions from the trees that left it out, then compare the result with its observed label or value. Repeat across eligible rows to estimate performance without fitting a separate model for each fold.

If out-of-bag error stabilizes as you add trees, extra trees may offer little improvement for that dataset while using more time and memory. With few trees, some rows may have too few out-of-bag predictions for a reliable estimate. Compare the diagnostic across a sensible range of tree counts.
Out-of-bag sampling operates on rows. If the same customer appears in many rows, trees can still see that customer in training. If your model will be used on new customers or future shipments, assess it with a grouped or time-based split that matches that setting. Unlimited AI guide to choosing a cross-validation split.
Read feature importance as a model diagnostic
Permutation importance measures what happens to a fitted model’s score when you shuffle one feature. If shuffling depot backlog lowers the score, the model relied on information in that column for this dataset and metric. Run the calculation on a representative held-out set after confirming that the model performs usefully there.

A low score can be misleading when two columns carry similar information. Shuffling one leaves the other available to the model. Test correlated features together where appropriate, and avoid treating importance as proof that changing a feature would cause an outcome to change.
Decide whether a random forest fits your problem
Start with a forest for tabular data when you expect nonlinear patterns or interactions. In the shipment example, a long route might increase risk mainly when the depot is already congested. Tree splits can represent that interaction without an explicit product feature. Compare the forest with a simple baseline on the same split.
Tune tree complexity before assuming tree count will fix poor performance. Shallower trees or larger leaves can reduce sensitivity to small pockets of the training data. The number of candidate features per split changes how much trees differ. Compare validation performance and record prediction time if the model needs to respond quickly.
Forests can be less convenient when you need a short, transparent rule or when you must predict beyond the range of training targets. A standard regression forest averages leaf predictions, so check carefully before relying on it for extrapolation.
Common questions
Do random forests need feature scaling?
Conventional tree splits typically depend on the ordering of feature values. Scaling that preserves this order generally makes little difference to the split logic. You still need to handle categorical inputs and missing values in ways your implementation supports.
Does adding trees fix overfitting?
More trees can stabilize the ensemble, but they cannot repair a leaky dataset, an unrepresentative evaluation split, or a poor target definition. If validation stays weak while training performance is high, investigate the split and tree complexity. Unlimited AI guide to diagnosing overfitting.
For your first comparison, fit a baseline and a random forest using the same training split. Compare the metric that matters, inspect the model’s mistakes, and measure how much time it takes to make predictions.













