Random Forest

Combine many decision trees to build a stronger random forest model.

A random forest combines many decision trees to make more stable predictions than a single tree alone.

Goal

Train a random forest and compare it to a single decision tree.

How Random Forests Work

Each tree in the forest is trained on a random subset of the data and features. The final prediction comes from voting across all trees, which reduces overfitting and improves generalization.

When to Use Random Forests

Random forests work well on structured tabular data and are a strong baseline before trying more complex models.

Interactive

Random Forest Voting Demo

Toggle each tree's prediction and see how majority voting determines the forest's final class.

Tree 1

Class 0

Tree 2

Class 1

Tree 3

Class 0

Tree 4

Class 1

Tree 5

Class 0

Tree 6

Class 1

Votes for Class 0

3

Votes for Class 1

3

Forest prediction

Tie

Majority vote

Each tree votes for Class 0 or Class 1. The random forest chooses the class with the most votes. If votes are equal, the result is a tie.

Tree votes: [0, 1, 0, 1, 0, 1] → Tie

Practice

Try It Yourself

Open the practice lab to complete the starter code in the notebook.

Knowledge Check

Quick Quiz

How does a random forest make a final prediction?

Summary

Key Takeaways

  • A random forest combines many decision trees into one ensemble model.
  • Voting across trees often produces more stable predictions.
  • Random forests are a strong baseline for tabular classification problems.