A learning project focused on understanding core machine learning concepts by implementing Logistic Regression both from scratch and using scikit-learn.
🎓 Purpose: This project is designed to learn and demonstrate understanding of:
- Gradient descent optimization from first principles
- Binary cross-entropy loss function
- Sklearn Pipelines for clean ML workflows
Uses synthetic data to focus on algorithm implementation rather than real-world prediction.
⚠️ Disclaimer: This is purely an educational project. Relationship outcomes depend on countless factors beyond what any model can capture!
- Overview
- Notebooks
- Dataset
- Technical Approach
- Results
- Installation
- Usage
- Project Structure
- Learning Outcomes
This project contains two implementations of Logistic Regression:
| Notebook | Approach | Purpose |
|---|---|---|
gf_pred_manual.ipynb |
From scratch with NumPy | Understand gradient descent |
gf_pred_sklearn.ipynb |
Using sklearn Pipeline | Learn production-style workflow |
- ✨ Manual implementation with no ML libraries
- 📊 Custom gradient descent with 100,000 iterations
- 📈 Visualization of cost function convergence
- 🔧 Sklearn Pipeline for comparison
The dataset (indian_boys_gf_prediction_balanced.csv) contains 300 balanced samples with the following features:
| Feature | Description | Range |
|---|---|---|
age |
Age in years | 18-30 |
height_cm |
Height in centimeters | 155-190 |
income_lpa |
Annual income (Lakhs/year) | 1.5-20 |
fitness_level |
Self-rated fitness score | 1-10 |
confidence |
Self-rated confidence score | 1-10 |
social_media_hours |
Daily social media usage (hours) | 0.5-6.0 |
has_gf |
Target variable | 0 (No) / 1 (Yes) |
- Class 0 (No GF): ~50%
- Class 1 (Has GF): ~50%
z = (x - μ) / σ
Ensures all features are on the same scale for faster gradient descent convergence.
σ(z) = 1 / (1 + e^(-z))
Maps linear output to probability between 0 and 1.
J(W, B) = -(1/m) Σ [y·log(ŷ) + (1-y)·log(1-ŷ)]
W = W - α · (∂J/∂W)
B = B - α · (∂J/∂B)
Where α = 0.1 (learning rate)
| Metric | Value |
|---|---|
| Training Accuracy | ~65% |
| Test Accuracy | ~54% |
| Iterations | 100,000 |
| Learning Rate | 0.1 |
- Model converges successfully (cost function decreases)
- Moderate accuracy expected due to:
- Inherently noisy/random nature of the target
- Limited feature set
- Small dataset size
- Python 3.8+
- pip
# Clone the repository
git clone https://github.com/yourusername/logistic_regression_gf_pred_proj.git
cd logistic_regression_gf_pred_proj
# Install dependencies
pip install pandas numpy matplotlib scikit-learn jupyter# Manual implementation (from scratch)
jupyter notebook gf_pred_manual.ipynb
# Sklearn implementation
jupyter notebook gf_pred_sklearn.ipynb# Example: Predict for a new user
user_input = pd.DataFrame([{
"age": 25,
"height_cm": 180,
"income_lpa": 12,
"fitness_level": 10,
"confidence": 7,
"social_media_hours": 5
}])
# Scale using training statistics
scaled_input = (user_input.values - X_train.mean(axis=0)) / X_train.std(axis=0)
# Get probability
probability = sigmoid(np.dot(scaled_input, W) + B)
print(f"Probability of having GF: {probability[0][0]:.2%}")logistic_regression_gf_pred_proj/
├── gf_pred_manual.ipynb # From-scratch implementation
├── gf_pred_sklearn.ipynb # Sklearn Pipeline implementation
├── indian_boys_gf_prediction_balanced.csv # Dataset
└── README.md # This file
This project teaches:
- ✅ Logistic Regression theory and math
- ✅ Gradient Descent from first principles
- ✅ Binary Cross-Entropy loss function
- ✅ Feature scaling importance
- ✅ Train/Test split to prevent overfitting
- ✅ Sklearn Pipelines for clean workflows
For future projects with real-world data:
- EDA: Exploratory Data Analysis before modeling
- Feature Engineering: Create meaningful features
- Cross-Validation: k-fold CV for robust evaluation
- Hyperparameter Tuning: GridSearchCV / RandomizedSearchCV
- Model Comparison: Try multiple algorithms
This project teaches:
- ✅ Logistic Regression theory and implementation
- ✅ Gradient Descent optimization
- ✅ Binary Cross-Entropy loss function
- ✅ Feature scaling importance
- ✅ Train/Test split to prevent overfitting
- ✅ Model evaluation metrics
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch
- Submit a pull request