Skip to content

A complete implementation of Logistic Regression built from scratch using Python and NumPy, with detailed visualizations and mathematical explanations.

License

Notifications You must be signed in to change notification settings

willow788/Logistic-Regression-From-Scratch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

25 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ Logistic Regression From Scratch

โœจ Building Binary Classification from the Ground Up โœจ

Overview โ€ข Features โ€ข Quick Start โ€ข Math โ€ข Use Cases โ€ข Credits


๐Ÿ“š Overview

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘  ๐Ÿšซ No Scikit-Learn  |  โœ… Pure NumPy  |  ๐Ÿงฎ From Scratch  โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

This repository contains a complete implementation of Logistic Regression built entirely from scratch using Python and NumPy. Perfect for those who want to understand the mathematical foundations and inner workings of one of machine learning's most fundamental algorithms! ๐ŸŽ“



โœจ Features

Pure Implementation

Built with NumPy only - no ML libraries!

Optimization

Gradient descent from first principles

Visualizations

Beautiful ROC curves & confusion matrices

Metrics

Accuracy, precision, recall, F1-score

Improvements

Advanced techniques & regularization

Documentation

Interactive Jupyter notebooks



๐Ÿ—‚๏ธ Repository Structure

๐Ÿ“ฆ Logistic-Regression-Fron-Scratch
โ”ฃ ๐Ÿ“‚ Main jupyter notebook
โ”ƒ โ”— ๐Ÿ““ Core implementation & training
โ”ฃ ๐Ÿ“‚ Improved Model
โ”ƒ โ”— ๐Ÿ““ Enhanced versions with optimizations
โ”ฃ ๐Ÿ“œ . gitignore
โ”— ๐Ÿ“– README.md โ† You are here!  ๐Ÿ“


๐Ÿš€ Quick Start

๐ŸŽฌ Get Started in 4 Easy Steps!

Step 1

Clone Repo

Step 2

Install Packages

Step 3

Launch Jupyter

Step 4

Run & Learn!

๐Ÿ’ป Installation Commands

# 1๏ธโƒฃ Clone the repository
git clone https://github.com/willow788/Logistic-Regression-Fron-Scratch.git
cd Logistic-Regression-Fron-Scratch

# 2๏ธโƒฃ Install dependencies
pip install numpy pandas matplotlib seaborn jupyter scikit-learn

# 3๏ธโƒฃ Launch Jupyter Notebook
jupyter notebook

# 4๏ธโƒฃ Open and run the notebooks!  ๐ŸŽ‰

๐Ÿ“‹ Prerequisites

Python NumPy Pandas Matplotlib Seaborn Jupyter



๐Ÿงฎ Mathematical Foundation

๐ŸŽฏ The Sigmoid Function

$$ฯƒ(z) = \frac{1}{1 + e^{-z}}$$

Where: z = wโ‚xโ‚ + wโ‚‚xโ‚‚ + ... + wโ‚™xโ‚™ + b


| Component | Description | |:---------:|: ------------| | ๐ŸŽฒ Sigmoid | Maps linear output to [0, 1] probability | | ๐Ÿ’ฐ Cost Function | Binary Cross-Entropy Loss | | โšก Optimization | Gradient Descent Algorithm | | ๐Ÿ“‰ Learning | Iterative weight updates |



๐Ÿ“Š What You'll Learn

๐ŸŽ“ Core Concepts

+ Sigmoid activation function
+ Cost function derivation  
+ Gradient computation
+ Parameter optimization
+ Convergence analysis
+ Decision boundaries

๐Ÿ› ๏ธ Implementation Skills

+ Vectorized operations
+ Training loop design
+ Model evaluation
+ Hyperparameter tuning
+ Data preprocessing
+ Performance visualization


๐Ÿ“ˆ Algorithm Pipeline

graph LR
    A[๐Ÿ”ง Initialize<br/>Weights & Bias] --> B[โžก๏ธ Forward<br/>Propagation]
    B --> C[๐Ÿ’ฐ Calculate<br/>Cost]
    C --> D[โฌ…๏ธ Backward<br/>Propagation]
    D --> E[๐Ÿ”„ Update<br/>Parameters]
    E --> F{โœ… Converged?}
    F -->|No| B
    F -->|Yes| G[๐ŸŽฏ Make<br/>Predictions]
    
    style A fill:#e1f5ff
    style B fill:#fff4e1
    style C fill:#ffe1e1
    style D fill:#e1ffe1
    style E fill:#f0e1ff
    style F fill:#ffe1f0
    style G fill:#e1ffe1
Loading


๐ŸŽฏ Use Cases

๐Ÿ“ง Spam Detection

Email classification

๐Ÿฅ Medical Diagnosis

Disease prediction

๐Ÿ’ณ Fraud Detection

Transaction security

๐ŸŽฌ Sentiment Analysis

Review categorization



๐Ÿ” Model Improvements

Feature Description Benefit
โšก Regularization (L1/L2) Penalty terms added to cost Prevents overfitting
๐ŸŽฒ Feature Scaling Normalize input features Faster convergence
๐Ÿ”„ Mini-batch GD Update on data subsets Improved efficiency
๐Ÿ“‰ Learning Rate Schedule Adaptive learning rates Better optimization
๐ŸŽฏ Cross-Validation K-fold validation Robust evaluation


๐Ÿค Contributing

**Contributions, issues, and feature requests are welcome! **



GitHub Issues GitHub Pull Requests


Give a โญ if this project helped you!



๐Ÿ“ License

This project is MIT licensed.

License



๐Ÿ‘ค Author

willow788

GitHub Profile



๐Ÿ™ Acknowledgments

๐Ÿ“š Learning Resources

Tutorial on Logistic Regression implementation

๐Ÿ“Š Dataset Provider

High-quality datasets for training

๐ŸŽจ Visualization AI

Enhanced confusion matrix & ROC visuals


๐Ÿ’ก Special Thanks

  • Andrew Ng - Machine Learning Course inspiration
  • The ML Community - For continuous learning and support
  • Open Source Contributors - For making knowledge accessible


๐ŸŒŸ Made with โค๏ธ and lots of โ˜•

If you found this helpful, please give it a โญ


Happy Learning! ๐Ÿš€

About

A complete implementation of Logistic Regression built from scratch using Python and NumPy, with detailed visualizations and mathematical explanations.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors