Random forest

Supervised · Classification & regression A random forest builds hundreds of decision trees, each trained on a slightly different random sample of the data and features. For a new case, every tree gives its answer and the forest takes a vote (or an average, for numbers). Many imperfect trees together make a strong, stable prediction.

Everyday analogy

Asking 100 friends for a restaurant recommendation instead of trusting one. Individual opinions vary, but the crowd's favourite is usually a safe bet.

Example

Used for: card fraud detection, credit risk, medical diagnosis support, crop yield prediction, predicting equipment failure.

🌳Tree 1Fraud🌳Tree 2Fraud🌳Tree 3OK🌳Tree 4Fraud🌳Tree 5OK🗳️ Majority: Fraud (3 of 5)
A random forest asks many slightly different trees and goes with the majority vote.

Many trees, one vote

New payment₹48,000 at 3 a.m., new device, different city
→
Tree 1Fraud
Tree 2Genuine
Tree 3Fraud
… Tree 100Fraud
→
Vote83 say fraud, 17 say genuine → block and verify

How it works, step by step

  1. Make many random samples of the training data. Each sample picks rows at random, with repeats allowed (called bootstrapping).
  2. Train one decision tree on each sample. At every split, each tree only looks at a random subset of features, so the trees end up different from each other.
  3. For a new case, ask every tree for its answer.
  4. Classification: the majority vote wins. Regression: average the trees' numbers.
  5. The share of votes also works as a confidence score, for example 83%.

Worked example

A bank's forest has 100 trees. For a suspicious payment, 83 trees vote "fraud" and 17 vote "genuine". The payment is held and the customer gets an alert to confirm it. One tree alone might have been fooled; 100 rarely are.

✓ Good for

  • Usually much more accurate and stable than one tree
  • Handles messy data, missing values and many features well
  • Shows which features matter most (feature importance)

⚠ Watch out for

  • Slower and uses more memory than a single tree
  • Harder to explain one individual decision
  • Not ideal for very large text or image data, where neural networks do better

Try it yourself

About 10 min

Ask a crowd

  1. Ask 5 friends (or 5 new chats) to guess a number, e.g. a jar of sweets or a city's population.
  2. Average the guesses.
  3. Compare the average with the individual guesses.

What you should see: Many average guesses combined are often better than one. That's the idea behind a random forest.

Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.

Build it for real · guided projectYour first machine learning model: predict house pricesAbout 75 min · Copy-paste code · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.