A lightweight Python library for Linear Regression with multiple training methods and regularization options.
Project description
📦 linear_model
A lightweight and easy-to-use Python library for Linear Regression.
Supports multiple training methods, regularization options, and sample weighting.
✨ Features:
- 📐 Normal Equation
- 🔁 Gradient Descent
- 🛡️ Ridge Regression (L2 regularization)
- ✂️ Lasso Regression (L1 regularization)
- ⚖️ Sample weights for weighted regression
- 🎯 Optional intercept fitting
🚀 Installation
Clone the repository and install in editable mode:
git clone https://github.com/<your-username>/linear_model.git
cd linear_model
pip install -e .
Or install directly from GitHub (no clone needed):
pip install git+https://github.com/<your-username>/linear_model.git
📌 Quick Start
import numpy as np
from linear_model import LinearRegression
# Training data
X = np.array([[1], [2], [3], [4]])
y = np.array([2, 4, 6, 8])
# Initialize model
model = LinearRegression(method="ridge", alpha=0.01, lambd=0.1)
# Fit model
model.fit(X, y, sample_weight=None)
# Predictions
print("Predictions:", model.predict([[5], [6]]))
# Model details
print("Coef:", model.coef_())
print("Intercept:", model.intercept_())
# R² score
print("R²:", model.score(X, y))
⚙️ API Overview
fit(X, y, sample_weight=None)→ Train the modelpredict(X)→ Predict target valuesscore(X, y, sample_weight=None)→ Compute R² scorecoef_()→ Get feature coefficientsintercept_()→ Get model intercept
Parameters
method:"normal_equation" | "gradient_descent" | "ridge" | "lasso"fit_intercept:True(default) |Falsen_iter: Number of iterations for gradient methods (default:1000)alpha: Learning rate for gradient methods (default:0.01)lambd: Regularization strength (default:0.1)
🧪 Testing
Run unit tests with:
pytest tests/
📂 Project Structure
linear_model/
│── __init__.py
tests/
│── test_linear_regression.py
setup.py
README.md
LICENSE
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file linear_model_surya_sudhaharan-0.1.0.tar.gz.
File metadata
- Download URL: linear_model_surya_sudhaharan-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fde71a52c79c76242718f2c9dde600f350d23a6fcb8c7b7f2900547b679d12fd
|
|
| MD5 |
e62dd79e593f447952951510e6ec020a
|
|
| BLAKE2b-256 |
34696be4be5a6b8aa03beb4326dada4aa37da0e69852882ee1d3069397bd39da
|
File details
Details for the file linear_model_surya_sudhaharan-0.1.0-py3-none-any.whl.
File metadata
- Download URL: linear_model_surya_sudhaharan-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dcea5f2480b986717626cdde21b81fcdfa645278e24821985a7f9200d4e5016
|
|
| MD5 |
70d80b937698ac09bd33e75d551b97c7
|
|
| BLAKE2b-256 |
d7775725e62a83043ad13a88becc2515d496a233de8432602a3870919536cfeb
|