Skip to content
Home » Random Forest

Random Forest

1. Definition

Random Forest is a supervised machine learning algorithm that combines the predictions of multiple Decision Trees to produce a more accurate and reliable prediction.

In simple words:

Random Forest = Many Decision Trees working together.

It is called a forest because instead of using one Decision Tree, it creates a collection of many trees.


2. Simple Example

Suppose we want to predict whether a customer will buy a product or not.

Instead of asking only one Decision Tree:

        Decision Tree
              ↓
         BUY / NOT BUY

Random Forest uses many trees:

       Tree 1 → BUY
       Tree 2 → BUY
       Tree 3 → NOT BUY
       Tree 4 → BUY
       Tree 5 → BUY
              ↓
       Majority Voting
              ↓
            BUY

Here, 4 out of 5 trees predict BUY, so Random Forest predicts:\[ \boxed{BUY} \]


3. Why Do We Need Random Forest?

A single Decision Tree can sometimes overfit the training data.

For example:

Training Data
     ↓
One Decision Tree
     ↓
Very complex tree
     ↓
Overfitting

Random Forest reduces this problem by using many different Decision Trees and combining their results.

                    Training Data
                         ↓
        ┌────────┬──────┼──────┬────────┐
        ↓        ↓      ↓      ↓        ↓
      Tree 1   Tree 2  Tree 3 Tree 4  Tree 5
        ↓        ↓      ↓      ↓        ↓
        └────────┴──────┼──────┴────────┘
                         ↓
                   Combine Results
                         ↓
                     Prediction

4. How Random Forest Works

Random Forest mainly works through two important ideas:

1. Bootstrap Sampling

Different random samples of the training data are created.

Original Dataset
       ↓
Random Sample 1 → Tree 1
Random Sample 2 → Tree 2
Random Sample 3 → Tree 3
Random Sample 4 → Tree 4

Each tree gets a slightly different dataset.


2. Random Feature Selection

At each split, the algorithm considers a random subset of features rather than always considering every feature.

For example, suppose we have:

  • Age
  • Income
  • Education
  • Location
  • Website visits
  • Previous purchases

One tree may consider:

Age + Income + Education

Another may consider:

Location + Website visits + Previous purchases

This creates diversity among the trees.


5. Complete Working

                 Training Dataset
                        ↓
              Random Sampling
                        ↓
          ┌─────────────┼─────────────┐
          ↓             ↓             ↓
       Tree 1         Tree 2        Tree 3
          ↓             ↓             ↓
      Prediction     Prediction    Prediction
          └─────────────┼─────────────┘
                        ↓
                 Combine Results
                        ↓
                    Final Result

6. Random Forest for Classification

For classification, Random Forest generally uses majority voting.

Example:

TreePrediction
Tree 1Pass
Tree 2Fail
Tree 3Pass
Tree 4Pass
Tree 5Fail

Votes:

Pass = 3
Fail = 2

Therefore:\[ \boxed{Pass} \]


7. Random Forest for Regression

Random Forest can also be used for regression.

For regression, instead of voting for a class, the predictions from different trees are generally averaged.

Suppose five trees predict a house price:

TreePrediction
1₹50 lakh
2₹52 lakh
3₹48 lakh
4₹51 lakh
5₹49 lakh

The final prediction is approximately:\[ \frac{50+52+48+51+49}{5}=50 \]

Therefore:\[ \boxed{₹50\text{ lakh}} \]


8. Important Terms

1. Ensemble Learning

Random Forest is an example of ensemble learning.

Ensemble learning means combining multiple models to produce a better final model.

Multiple Models
      ↓
Combine Predictions
      ↓
Better Prediction

2. Number of Trees

The number of Decision Trees in the forest is an important parameter.

For example:\[ 100,\ 200,\ 500 \]

trees can be used.

Generally, more trees can improve stability, but they also require more computational resources.


3. Feature Randomness

Random Forest randomly selects features when building trees.

This helps make the trees different from each other.


9. Advantages of Random Forest

1. Reduces Overfitting

Because it combines many trees, it generally performs better than a single Decision Tree.

2. Good Accuracy

It often provides strong performance on many classification and regression problems.

3. Handles Large Datasets

It can work effectively with large datasets and many features.

4. Handles Classification and Regression

It can solve both types of problems.

5. Less Sensitive to Noise

Combining multiple trees can make the model more robust.

6. Feature Importance

Random Forest can provide information about which features are important for prediction.

For example:

Previous Purchases → High importance
Website Visits     → High importance
Age                → Medium importance
City               → Low importance

10. Disadvantages

1. More Computationally Expensive

Building many trees requires more processing power than building one tree.

2. Uses More Memory

Many trees need to be stored.

3. Less Interpretable

A single Decision Tree is easy to understand.

A forest containing hundreds of trees is much harder to explain.

4. Training Can Be Slower

Compared with a simple Decision Tree, Random Forest generally requires more time.


11. Decision Tree vs Random Forest

This is a very important exam comparison.

Decision TreeRandom Forest
One Decision TreeMultiple Decision Trees
Single modelEnsemble of models
More prone to overfittingUsually less prone to overfitting
Easy to understandMore difficult to interpret
FasterUsually slower
Less memoryMore memory
Can have unstable predictionsGenerally more stable
Uses one set of decisionsCombines many different trees

Easy memory:

Decision Tree = One expert

Random Forest = Committee of many experts


12. Applications of Random Forest

Random Forest is used in:

Banking

  • Loan approval
  • Credit risk prediction
  • Fraud detection

Healthcare

  • Disease prediction
  • Medical diagnosis

E-commerce

  • Customer purchase prediction
  • Product recommendation

Digital Marketing

  • Customer segmentation
  • Lead conversion prediction
  • Customer churn prediction
  • Campaign response prediction

Other Areas

  • Image classification
  • Stock market analysis
  • Agriculture
  • Cybersecurity

13. Example in Digital Marketing

Suppose we want to predict whether a lead will become a customer.

Features:

  • Age
  • Income
  • Website visits
  • Number of pages viewed
  • Previous purchases
  • Ad clicks

Random Forest creates many Decision Trees.

Tree 1 → Convert
Tree 2 → Convert
Tree 3 → Don't Convert
Tree 4 → Convert
Tree 5 → Convert
Tree 6 → Don't Convert
Tree 7 → Convert

Votes:

Convert       = 5
Don't Convert = 2

Final prediction:\[ \boxed{\text{Lead will probably convert}} \]


14. Exam-Ready Answer

Random Forest is a supervised machine learning algorithm based on the concept of ensemble learning. It creates multiple Decision Trees using different random samples of training data and random subsets of features. For classification, the predictions of all trees are combined using majority voting, while for regression, the predictions are generally averaged. Random Forest usually provides better stability and reduces overfitting compared with a single Decision Tree. It can be used for both classification and regression. Its disadvantages are higher computational cost, greater memory usage and lower interpretability.

Remember:

Random Forest = Random Data + Random Features + Many Decision Trees + Combined Prediction

And for your syllabus, just like KNN and Decision Tree, Random Forest is a supervised learning algorithm, not a clustering algorithm.