A clean, minimal implementation of Linear Regression from scratch using NumPy. This project is built for learning and quick experimentation, with ready-to-run notebooks and sample data.
- Pure NumPy implementation (no scikit-learn)
- Simple API with
LinearModelclass - Example notebooks included
- Works with your own CSV/Excel datasets
-
Clone the repo
-
Install dependencies
pip install numpy pandas matplotlib xlrd- Run a notebook
Open and run:
example_implementation.ipynbmain.ipynb
from linear_model import LinearModel
import numpy as np
# X shape: (m, n) and y shape: (m, 1)
X = np.array([[1.0], [2.0], [3.0], [4.0]])
y = np.array([[1.2], [1.9], [3.1], [3.9]])
model = LinearModel(num_features=1)
losses = model.train(X, y, iterations=2000, lr=0.01)
y_pred = model.forward_pass(X)
print(y_pred)Sample files are included:
chirps.csvchirps.xls
You can load the Excel file like this:
import pandas as pd
df = pd.read_excel("chirps.xls", engine="xlrd").
├── linear_model.py # Core Linear Regression implementation
├── example_implementation.ipynb # Step-by-step walkthrough
├── main.ipynb # Main usage notebook
├── chirps.csv # Sample dataset (CSV)
├── chirps.xls # Sample dataset (Excel)
└── README.md # Project guide
The model minimizes Mean Squared Error using gradient descent:
Parameters are updated iteratively using:
- Scale your features if values are large.
- Increase
iterationsfor better convergence. - Tune
lr(learning rate) if loss is unstable.
Created by Rehnoor Aulakh.
If you find this helpful, feel free to star the repo and share it.