Decision Tree ID3: A Complete Solved Numerical Example
Scenario: Bank Loan Approval
The Objective: Predict whether a loan application should be approved based on applicant profile.
Step 1: The Training Data
Before calculating recursive splits, we must define the dataset. The ID3 algorithm evaluates each feature to predict the target class (Approved).
| Data Point | Credit_History | Employment | Income_Level | Owns_Property | Approved |
|---|---|---|---|---|---|
| P1 | Good | Stable | High | Yes | Yes |
| P2 | Good | Stable | Medium | No | Yes |
| P3 | Poor | Unstable | Low | No | No |
| P4 | Poor | Stable | Medium | Yes | No |
| P5 | Good | Unstable | High | Yes | Yes |
| P6 | Poor | Unstable | High | No | No |
| P7 | Good | Stable | Low | No | Yes |
| P8 | Poor | Stable | Low | Yes | No |
| P9 | Good | Unstable | Low | No | No |
| Target | Good | Unstable | Medium | No | ? |
Step 2: Recursive Splitting (Entropy & Gain)
To build the tree, we recursively calculate the Entropy of the system and find the Information Gain for every available feature. The feature with the highest gain becomes the splitting node.
Iteration 1
Context: Root
1. Entropy of Target Class, Entropy(S)
Positives (P) for 'Yes' = 4
Negatives (N) for 'No' = 5
2. Subset Information Required
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Good | 4 | 1 | 0.7219 |
| Poor | 0 | 4 | 0.0000 |
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Stable | 3 | 2 | 0.9710 |
| Unstable | 1 | 3 | 0.8113 |
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| High | 2 | 1 | 0.9183 |
| Medium | 1 | 1 | 1.0000 |
| Low | 1 | 3 | 0.8113 |
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Yes | 2 | 2 | 1.0000 |
| No | 2 | 3 | 0.9710 |
3. Weighted Feature Entropy
4. Feature Information Gain
5. Feature Selection Decision
Credit_History generated the highest Information Gain (0.5900).
It is selected as the optimal splitting node for this subset.
Iteration 2
Context: Credit_History = Good
| Data Point | Credit_History | Employment | Income_Level | Owns_Property | Approved |
|---|---|---|---|---|---|
| P1 | Good | Stable | High | Yes | Yes |
| P2 | Good | Stable | Medium | No | Yes |
| P5 | Good | Unstable | High | Yes | Yes |
| P7 | Good | Stable | Low | No | Yes |
| P9 | Good | Unstable | Low | No | No |
1. Entropy of Target Class, Entropy(S)
Positives (P) for 'Yes' = 4
Negatives (N) for 'No' = 1
2. Subset Information Required
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Stable | 3 | 0 | 0.0000 |
| Unstable | 1 | 1 | 1.0000 |
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| High | 2 | 0 | 0.0000 |
| Medium | 1 | 0 | 0.0000 |
| Low | 1 | 1 | 1.0000 |
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Yes | 2 | 0 | 0.0000 |
| No | 2 | 1 | 0.9183 |
3. Weighted Feature Entropy
4. Feature Information Gain
5. Feature Selection Decision
Employment generated the highest Information Gain (0.3219).
It is selected as the optimal splitting node for this subset.
Iteration 3
Context: Employment = Unstable
| Data Point | Credit_History | Employment | Income_Level | Owns_Property | Approved |
|---|---|---|---|---|---|
| P5 | Good | Unstable | High | Yes | Yes |
| P9 | Good | Unstable | Low | No | No |
1. Entropy of Target Class, Entropy(S)
Positives (P) for 'Yes' = 1
Negatives (N) for 'No' = 1
2. Subset Information Required
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| High | 1 | 0 | 0.0000 |
| Low | 0 | 1 | 0.0000 |
| Value | Pi | Ni | I (Pi, Ni) |
|---|---|---|---|
| Yes | 1 | 0 | 0.0000 |
| No | 0 | 1 | 0.0000 |
3. Weighted Feature Entropy
4. Feature Information Gain
5. Feature Selection Decision
Income_Level generated the highest Information Gain (1.0000).
It is selected as the optimal splitting node for this subset.
Step 3: Final Computed Decision Tree
Combining all the recursive splits from Step 2 yields the final classification tree.
Final Takeaway
This tree mathematically proves which variables have the highest predictive power for determining loan approvals based on historical data.