This project implements a simple linear regression model from scratch using Python and NumPy. The goal is to understand how machine learning models learn by manually building prediction, loss calculation, and gradient descent without using ML libraries.
- Predicts values using a linear model: y = wx + b
- Measures error using Mean Squared Error (MSE)
- Optimizes parameters using gradient descent
- Learns the best-fit line for a given dataset
Weight (w)
Controls the slope of the line
Bias (b)
Shifts the line up or down
Loss (MSE)
Measures how far predictions are from actual values
Gradient Descent
Iteratively updates parameters to reduce error
- Python
- NumPy
- Matplotlib (for visualization)
├── main.py # Core implementation ├── data.py # Dataset (optional) └── README.md
- Initialize parameters (w, b)
- Make predictions using current parameters
- Compute loss (MSE)
- Calculate gradients (dw, db)
- Update parameters using gradient descent
- Repeat until loss decreases
- Model converges to approximate values:
- w ≈ 2
- b ≈ 3
- The predicted line closely fits the data points
python main.py
Why This Project
This project focuses on building intuition behind machine learning by avoiding high-level libraries like Scikit-learn and implementing the core logic manually.