Skip to main content

Random Forest Optimization


We input a fruit: Apple (Color = Red, Size = Small). Random Forest predicts its class by sending it through multiple decision trees and taking a majority vote.

How Random Forest Works Internally

Random Forest Decision Trees Diagram Tree 1 Color? Red→Apple Org→Org Tree 2 Size? Sml→Apple Lrg→Org Tree 3 Color? Red→Apple Org→Org Majority Vote → Apple

How Random Forest Differs from General ML Models

  • General ML: Learns complex function from all training data (e.g., neural network weights, linear regression coefficients).
  • Random Forest: Builds multiple simple decision trees on random subsets of data and features.
  • General ML models often have continuous parameters and internal layers/tensors.
  • Random Forest has no layers or tensors; its “learning” is simple rules at each node (splits) and aggregation by majority vote or averaging.
  • Random Forest uses bootstrap sampling and random feature selection to reduce overfitting and improve generalization.
  • Prediction in Random Forest = aggregate of simple tree predictions, while general ML models compute a complex mapping function.

1. Overview

Random Forest is an ensemble learning method that builds multiple decision trees and combines their outputs to improve predictive accuracy and reduce overfitting.

  • For classification: output is the majority vote of the trees.
  • For regression: output is the average of the trees’ predictions.

Mathematically, it can be expressed as aggregating outputs of multiple trees.

2. Decision Tree Basics

A single decision tree partitions the feature space recursively:

  • Let the input vector be ๐‘ฅ = (x₁, x₂, ..., xโ‚š)
  • Tree splits create regions Rโ‚˜ in feature space.
  • Prediction in region Rโ‚˜:
Regression: ลท = (1 / Nโ‚˜) ฮฃi ∈ Rโ‚˜ yแตข
Classification: ลท = mode({yแตข: i ∈ Rโ‚˜})

Where Nโ‚˜ is the number of samples in region Rโ‚˜.

3. Random Forest Prediction

Assume we have B trees {T₁, T₂, ..., T_B}:

Regression:
ลท_RF(x) = (1 / B) ฮฃb=1 to B T_b(x)

Classification:
ลท_RF(x) = majority_vote { T₁(x), T₂(x), ..., T_B(x) }

Where T_b(x) is the prediction of the b-th tree.

4. Bootstrap Aggregation (Bagging)

  • Each tree is trained on a bootstrap sample (random sample with replacement).
  • Reduces variance by decorrelating trees.
If the training set is D = { (xแตข, yแตข) } for i = 1..N
Bootstrap sample for tree b: D_b ~ Uniform sample with replacement from D

5. Random Feature Selection

At each split, instead of using all p features, a random subset of m << p features is considered:

  • Reduces correlation between trees.
  • Split selection:
Choose feature j* = argmax (Information Gain or Gini Reduction) 
from random subset of m features

6. Out-of-Bag (OOB) Error

  • For each sample, some trees did not include it in their bootstrap set.
  • OOB prediction for sample i:
ลท_OOB,i = (1 / |B_i|) ฮฃb ∈ B_i T_b(x_i)

Where B_i = set of trees where i was not included in training.

OOB error estimates generalization error without a separate validation set.

Random Forest = Bagging + Random Feature Selection

  1. Build B trees on bootstrap samples.
  2. At each split, select the best split from a random subset of features.
  3. Predict by averaging (regression) or majority vote (classification).
  4. OOB samples estimate generalization error.

Random Forest Example with Dummy Dataset

Let’s break Random Forest down with a small, simple dataset for classification.

1. Dummy Dataset

Suppose we have a dataset of fruits with features Color and Size, and we want to predict if the fruit is Apple or Orange.

Fruit Color Size
1RedSmall
2RedLarge
3OrangeLarge
4OrangeSmall
5RedSmall
6OrangeLarge

Notes: Color → Red/Orange, Size → Small/Large, Target → Apple (Red) or Orange

2. Step 1: Bootstrap Sampling

Random Forest trains each tree on a random sample with replacement. Example Tree 1 bootstrap sample:

Fruit Color Size
1RedSmall
2RedLarge
5RedSmall
6OrangeLarge
3OrangeLarge

Some rows may be missed and some may repeat.

3. Step 2: Random Feature Selection

At each split, Random Forest randomly selects a feature instead of using all features.

  • Suppose Tree 1 chooses Color first → split Red vs Orange.
  • Next, Tree 1 might consider Size in each branch.

4. Step 3: Build the Tree

         Color?
       /       \
     Red       Orange
    /   \       /    \
  Small Large Large Small
Apple Apple Orange Orange

Leaves give predicted class based on majority vote.

5. Step 4: Build More Trees

Random Forest builds multiple trees with different bootstrap samples and random features.

Example predictions for new fruit (Red, Small):

Tree Prediction
1Apple
2Apple
3Orange

6. Step 5: Aggregate Predictions

  • Classification: majority vote → Apple
  • Regression: average of tree outputs.

Another Example

Key Points

  1. Random Forest uses multiple decision trees.
  2. Each tree sees a different random sample.
  3. Each tree considers a random subset of features at each split.
  4. Predictions are aggregated: majority vote (classification) or average (regression).
  5. This reduces overfitting compared to a single tree.

Dataset

Fruit Color Size Target
1RedSmallApple
2RedLargeApple
3OrangeLargeOrange
4OrangeSmallOrange
5RedSmallApple
6OrangeLargeOrange

We want to predict the fruit type based on Color and Size.

Step 1: Bootstrap Sampling

  • Tree 1 sample: 1, 2, 5, 6, 3
  • Tree 2 sample: 2, 3, 4, 5, 6
  • Tree 3 sample: 1, 3, 3, 4, 5

Notice some fruits repeat and some are missing.

Step 2: Build Trees with Random Feature Selection

At each split, Random Forest chooses a random subset of features.

Tree 1

         Color?
       /       \
     Red       Orange
    /   \       /    \
  Small Large Large Small
 Apple  Apple Orange Orange

Tree 2

         Size?
       /       \
     Small     Large
    /   \       /    \
  Red Orange Red  Orange
 Apple Orange Apple Orange

Tree 3

         Color?
       /       \
     Orange     Red
    /    \      /   \
 Small Large Small Large
 Orange Orange Apple Apple

Step 3: Predict a New Sample

New fruit: Color = Red, Size = Small

  • Tree 1 predicts: Apple
  • Tree 2 predicts: Apple
  • Tree 3 predicts: Apple

Majority vote → Apple

Step 4: How Randomness Helps

  • Bootstrap: Trees see different samples → reduces overfitting.
  • Random features: Trees are less correlated → improves generalization.

Step 5: Aggregate Prediction

  • Classification: majority vote → Apple
  • Regression: average of tree outputs

Further Reading

Contact Us

Name

Email *

Message *

Popular Posts

UGC NET Electronic Science Previous Year Question Papers with Solutions

Home / Engineering & Other Exams / UGC NET 2026 PYQ ⬇️ Download Papers and Solutions ๐Ÿ“‹ Exam Pattern ๐Ÿ’ก Preparation Tips ❓ FAQs ๐Ÿ“Š Exam Highlights: Electronic Science (88) Feature Details Junior Research Fellowship (JRF) ₹37,000 + HRA per month Eligibility M.Sc/M.Tech in Electronics (55%) Validity of Certificate JRF (3 Years) | Lectureship (Lifetime) ๐Ÿ“ฅ Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading ๐Ÿ“‚ View All Question Papers June 2025 - Question Paper Download PDF June 2025 - Solved Paper + Explanation ...

UGC NET Electronic Science June 2025 Question Paper with Answer Key & Detailed Solutions

Home / UGC NET PYQ / June 2025 Solved UGC NET Electronic Science June 2025 Question Paper with Answer Key and Full Explanations ๐Ÿ“ฅ Download Question Paper (PDF) 2025 2024 2023 2022 2021 2020 Explanations 1.  Answer: Option (3) For forming a p-type semiconductor, the dopant must be a trivalent impurity (three valence electrons) so that it creates acceptor levels and holes become the majority carriers. Among the given elements, boron (B) is a group-III element (trivalent). Arsenic (As) and phosphorus (P) are group-V (pentavalent) donors that produce n-type material, and germanium (Ge) is a group-IV element usually used as the semiconductor, not as an acceptor dopant. Hence, doping an intrinsic semiconductor with B produces a p-type semiconductor. 2.  Answer: Option (4) The ohmic resistance of a JFET at zero gate bias is given by the standard relation: R DS(on) = V P / I DSS ...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

Bit Error Rate (BER) & SNR Guide Analyze communication system performance with our interactive simulators and MATLAB tools. ๐Ÿ“˜ Theory ๐Ÿงฎ Simulators ๐Ÿ’ป MATLAB Code ๐Ÿ“š Resources BER Definition SNR Formula BER Calculator MATLAB Comparison ๐Ÿ“‚ Explore M-ary QAM, PSK, and QPSK Topics ▼ ๐Ÿงฎ Constellation Simulator: M-ary QAM ๐Ÿงฎ Constellation Simulator: M-ary PSK ๐Ÿงฎ BER calculation for ASK, FSK, and PSK ๐Ÿงฎ Approaches to BER vs SNR What is Bit Error Rate (BER)? The BER indicates how many corrupted bits are received compared to the total number of bits sent. It is the primary figure of merit f...

Q-function in BER vs SNR Calculation

Q-function in BER vs. SNR Calculation | Interactive Guide Q-function in BER vs. SNR Calculation In digital communications and signal processing, the Q-function plays a significant role in predicting system reliability. It allows engineers to quantify the probability that Gaussian noise will exceed a specific threshold, causing a bit error. What is the Q-function? The Q-function is a mathematical function representing the tail probability of the standard normal (Gaussian) distribution. It is the complementary cumulative distribution function (CCDF) of a standard Gaussian distribution. Q(x) = (1 / √(2ฯ€)) ∫โ‚“∞ e^(-t² / 2) dt Q-Function Interactive Simulator Move the slider to see how the "Tail Probability" (the area in red) changes. This area represents the Probability of Error (BER) . Threshold Distance ( x ) — (Simulates Increasing SNR) ...

UGC NET Electronic Science December 2024 Question Paper with Answer Key & Detailed Solutions

Home / UGC NET PYQ / June 2025 Solved UGC NET Electronic Science December 2024 Question Paper with Answer Key and Full Explanations ๐Ÿ“ฅ Download Question Paper (PDF) 2025 2024 2023 2022 2021 2020 Q.1 Answer: Option (3) Q.2 Answer: Option (3) Solution 1. JMP SHORT LABEL Intrasegment (within the same code segment). Direct jump. ❌ Not intersegment indirect. 2. JMP 5000H:2000H Intersegment (far jump because both CS and IP are specified). Direct jump (address is explicitly given). ❌ Not indirect. 3. JMP [2000H] The destination address is taken from memory location 2000H. This is indirect. In 8086, a far indirect jump can use a memory operand containing both IP and CS (depending on operand size), making it an intersegment indirect jump. ✅ Correct answer. 4. JMP [BX] Indirect jump through memory addressed by BX. Usually intrasegment (near indirect jump). ❌ Not in...

Constellation Diagrams of ASK, PSK, and FSK (with MATLAB Code + Simulator)

Constellation Diagrams: ASK, FSK, and PSK Comprehensive guide to signal space representation, including interactive simulators and MATLAB implementations. ๐Ÿ“˜ Overview ๐Ÿงฎ Simulator ⚖️ Theory Q-function ๐Ÿ“š Resources ๐Ÿ“‚ Other Topics: M-ary PSK & QAM Diagrams ▼ ๐Ÿงฎ Simulator for M-ary PSK Constellation ๐Ÿงฎ Simulator for M-ary QAM Constellation BASK (Binary ASK) Modulation Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1. BFSK (Binary FSK) Modulation Transmits one of two signals: +√Eb​ (On the y-axis, the phas...

Online Simulator for ASK, FSK, and PSK

Interactive Digital Signal Processing (DSP) Tutorial and Simulator for ASK, FSK, and BPSK modulation techniques. Try our new Digital Signal Processing Simulator!   •   Interactive ASK, FSK, and BPSK tools updated for 2025. Start Now Digital Modulation Visualizer: ASK, FSK, & BPSK Simulator Learn and visualize binary modulation techniques (ASK, FSK, BPSK) in real-time with adjustable carrier and sampling parameters. Perfect for DSP students and engineers. ๐Ÿ“ก ASK Simulator ๐Ÿ“ถ FSK Simulator ๐ŸŽš️ BPSK Simulator ๐Ÿ“š More Topics ASK Modulator FSK Modulator BPSK Modulator More Topics 1. ASK (Amplitude Shift Keying) Simulat...

Shannon Limit Explained: Negative SNR, Eb/No and Channel Capacity

Understanding Negative SNR and the Shannon Limit An explanation of Signal-to-Noise Ratio (SNR), its behavior in decibels, and how Shannon's theorem defines the ultimate communication limit. Signal-to-Noise Ratio in Shannon’s Equation In Shannon's equation, the Signal-to-Noise Ratio (SNR) is defined as the signal power divided by the noise power: SNR = S / N Since both signal power and noise power are physical quantities, neither can be negative. Therefore, the SNR itself is always a positive number. However, engineers often express SNR in decibels: SNR(dB) When SNR = 1, the logarithmic value becomes: SNR(dB) = 0 When the noise power exceeds the signal power (SNR < 1), the decibel representation becomes negative. Behavior of Shannon's Capacity Equation Shannon’s channel capacity formula is: C = B log₂(1 + SNR) For SNR = 0: log₂(1 + SNR) = 0 When SNR becomes smaller (including negative values in dB), the expression approache...