Comparison of Logistic Regression and Decision Tree on Adult Income Dataset
Experiment
Title
Comparison of Logistic Regression and Decision Tree on Adult Income Dataset
π― Objective
-
To predict whether income is:
-
<=50Kor>50K
-
-
To compare:
- Logistic Regression
- Decision Tree
-
To evaluate using:
- Accuracy
- Precision
- Recall
- F1-score
π Dataset: Adult Income
Features include:
- Age
- Education
- Occupation
- Hours-per-week
- Capital gain/loss
Target:
-
Income (
<=50K,>50K)
⚙️ Steps
- Load dataset
- Handle missing values
- Encode categorical variables
- Train models
- Evaluate performance
- Compare interpretability
π» Python Program
πResults
=== Logistic Regression ===
Accuracy: 0.8246583755565792
precision recall f1-score support
0 0.85 0.94 0.89 4942
1 0.71 0.46 0.56 1571
accuracy 0.82 6513
macro avg 0.78 0.70 0.72 6513
weighted avg 0.81 0.82 0.81 6513
=== Decision Tree ===
Accuracy: 0.8490710885920467
precision recall f1-score support
0 0.86 0.95 0.91 4942
1 0.78 0.52 0.62 1571
accuracy 0.85 6513
macro avg 0.82 0.74 0.76 6513
weighted avg 0.84 0.85 0.84 6513
π Observations
πΉ Logistic Regression
- Linear model
- Stable performance
- Works well with scaled data
πΉ Decision Tree
- Non-linear model
- Captures complex patterns
- May overfit (especially deep trees)
π Interpretability Comparison
| Aspect | Logistic Regression | Decision Tree |
|---|---|---|
| Model Type | Linear | Rule-based |
| Interpretability | Medium | High ✅ |
| Explanation | Coefficients | If-else rules |
| Visualization | Difficult | Easy |
π³ Decision Tree Interpretation
Example rule:
π Easy to understand
π Logistic Regression Interpretation
- Uses coefficients:
π Harder to interpret for beginners
Key Insights
-
Logistic Regression:
- Better generalization
-
Decision Tree:
- Better interpretability
⚖️ When to Use What?
| Situation | Best Model |
|---|---|
| Need explainability | Decision Tree |
| Need accuracy & stability | Logistic Regression |
| Non-linear data | Decision Tree |
π§ͺ Lab Tasks
Task 1
Change tree depth:
Task 2
Remove scaling → observe LR performance
Task 3
Plot tree:
Result
-
Logistic Regression:
- Stable, good baseline
-
Decision Tree:
- Easy to interpret
-
Trade-off:
- Accuracy vs interpretability
Comments
Post a Comment