Parameter Estimation in Logistic Regression using MLE and MAP
Experiment
Parameter Estimation in Logistic Regression using MLE and MAP
π― Objective
- To implement Logistic Regression
-
To estimate model parameters using:
- Maximum Likelihood Estimation (MLE)
- Maximum A Posteriori (MAP)
- To compare the effect of regularization (prior)
Theory
πΉ Logistic Regression Model
Where:
- = weight
- = bias
- = sigmoid function
πΉ Likelihood Function (MLE)
For dataset
Log-likelihood:
πΉ MAP Estimation
Assume Gaussian prior:
MAP objective:
π Equivalent to L2 regularization (Ridge)
π§© Problem Statement
Classify whether a student passes (1) or fails (0) based on study hours.
π Sample Dataset
| Study Hours (x) | Result (y) |
|---|---|
| 1 | 0 |
| 2 | 0 |
| 3 | 0 |
| 4 | 1 |
| 5 | 1 |
| 6 | 1 |
⚙️ Algorithm
MLE:
-
Initialize
- Compute predictions using sigmoid
- Compute log-likelihood
- Update using gradient ascent
MAP:
- Same as MLE
- Add L2 penalty term
- Update gradients with regularization
π» Python Implementation
π Output
π Visualization Code
π Observations
-
MLE:
- Fits data aggressively
- Can produce large weights
- May overfit
-
MAP:
- Produces smoother curve
- Penalizes large weights
- Better generalization
Experiment Variations
1. Change Regularization Strength
π Observe curve smoothing
2. Add Noise
π MLE overfits, MAP resists noise
3. Increase Features
Add:
- Study hours
- Sleep hours
π Comparison Table
| Aspect | MLE | MAP |
|---|---|---|
| Prior used | ❌ No | ✅ Yes |
| Regularization | ❌ None | ✅ L2 |
| Overfitting | High | Reduced |
| Stability | Low (small data) | High |
Results
- Logistic regression MLE = maximize likelihood
- MAP = MLE + regularization
-
MAP improves:
- Stability
- Generalization
- Widely used in real ML systems

Comments
Post a Comment