Building a Random Forest and Classifying by Majority Vote
Problem Setup
Scenario:Predict whether a patient will be readmitted by combining the predictions of three decision trees trained on different bootstrap samples of the training data.
Given:A labeled dataset of 8 patient records with four candidate features — Age_Group, Diagnosis_Severity, Num_Medications, and Has_Support — and Readmitted as the target class. The target patient has Age_Group = Senior, Diagnosis_Severity = Mild, Num_Medications = Many, and Has_Support = No.
Task:Build the three decision trees using bootstrap sampling and random feature selection, obtain each tree's prediction for the target patient, and use majority voting across the trees to determine the Random Forest prediction.
Need a quick refresher? Review Random Forest theory
Training Data & Target Patient
The eight labeled records are used to construct the bootstrap samples for each tree. The target patient has no known class label and will be classified using the forest's combined predictions.
| Data Point | Age_Group✎ | Diagnosis_Severity✎ | Num_Medications✎ | Has_Support✎ | Readmitted |
|---|---|---|---|---|---|
| P1 | Young | Mild | Few | Yes | No |
| P2 | Young | Severe | Many | No | Yes |
| P3 | Middle | Mild | Few | Yes | No |
| P4 | Middle | Severe | Many | Yes | Yes |
| P5 | Senior | Mild | Many | No | Yes |
| P6 | Senior | Severe | Few | No | Yes |
| P7 | Middle | Mild | Many | No | No |
| P8 | Young | Mild | Few | No | No |
| Target | Senior | Mild | Many | No | ? |
Forest Configuration (3 Trees)
Tree 1
Must equal exactly 8 rows.
Tree 2
Must equal exactly 8 rows.
Tree 3
Must equal exactly 8 rows.
Tree 1 Math Breakdown
Iteration 1
Context: Root
| Data Point | Age_Group(cand) | Diagnosis_Severity(cand) | Num_Medications | Has_Support | Readmitted |
|---|---|---|---|---|---|
| P1 | Young | Mild | Few | Yes | No |
| P1 | Young | Mild | Few | Yes | No |
| P3 | Middle | Mild | Few | Yes | No |
| P4 | Middle | Severe | Many | Yes | Yes |
| P5 | Senior | Mild | Many | No | Yes |
| P6 | Senior | Severe | Few | No | Yes |
| P6 | Senior | Severe | Few | No | Yes |
| P8 | Young | Mild | Few | No | No |
1. Entropy of Target Class, Entropy (S)
Positives (P) for 'Yes' = 4
Negatives (N) for 'No' = 4
Calculation:
2. Subset Information Required
| Value | Pi | Ni |
|---|---|---|
| Young | 0 | 3 |
| Middle | 1 | 1 |
| Senior | 3 | 0 |
Detailed Entropy Calculation
Value: Young
Value: Middle
Value: Senior
Evaluated Feature: Age_Group
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Young | 0 | 3 | 0 |
| Middle | 1 | 1 | 1 |
| Senior | 3 | 0 | 0 |
| Value | Pi | Ni |
|---|---|---|
| Mild | 1 | 4 |
| Severe | 3 | 0 |
Detailed Entropy Calculation
Value: Mild
Value: Severe
Evaluated Feature: Diagnosis_Severity
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Mild | 1 | 4 | 0.722 |
| Severe | 3 | 0 | 0 |
3. Weighted Feature Entropy
Calculation:
Calculation:
4. Feature Information Gain
5. Feature Selection Decision
Age_Group generated the highest Information Gain (0.75).
It is selected as the optimal splitting node for this subset.
Iteration 2
Context: Age_Group = Middle
| Data Point | Age_Group | Diagnosis_Severity(cand) | Num_Medications | Has_Support | Readmitted |
|---|---|---|---|---|---|
| P3 | Middle | Mild | Few | Yes | No |
| P4 | Middle | Severe | Many | Yes | Yes |
1. Entropy of Target Class, Entropy (S)
Positives (P) for 'Yes' = 1
Negatives (N) for 'No' = 1
Calculation:
2. Subset Information Required
| Value | Pi | Ni |
|---|---|---|
| Mild | 0 | 1 |
| Severe | 1 | 0 |
Detailed Entropy Calculation
Value: Mild
Value: Severe
Evaluated Feature: Diagnosis_Severity
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Mild | 0 | 1 | 0 |
| Severe | 1 | 0 | 0 |
3. Weighted Feature Entropy
Calculation:
4. Feature Information Gain
5. Feature Selection Decision
Diagnosis_Severity generated the highest Information Gain (1).
It is selected as the optimal splitting node for this subset.
Final Answer
Tree predictions:Tree 1 = Yes, Tree 2 = No, Tree 3 = Yes
Final prediction:Yes
The trees were constructed using different bootstrap samples and feature restrictions, so they can classify the same patient differently. The forest uses their collective vote rather than relying on one tree's decision.
Exam Takeaway
- Preserve repeated records in bootstrap samples: Sampling with replacement means a training row can appear more than once. Count every occurrence when calculating class distributions, entropy, and Information Gain for that tree.
- Evaluate only the permitted features at each split: Do not automatically compare every feature in the dataset. Follow the candidate-feature restrictions given in the question and select the highest-gain feature from those available at the current node.
- Separate tree predictions from the forest prediction: First follow the target record through every tree, then count the class votes. A majority vote determines the forest's predicted class, but the vote fraction is not necessarily a calibrated prediction probability.