Skip to main content

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 model
  • predict(X) → Predict target values
  • score(X, y, sample_weight=None) → Compute R² score
  • coef_() → Get feature coefficients
  • intercept_() → Get model intercept

Parameters

  • method: "normal_equation" | "gradient_descent" | "ridge" | "lasso"
  • fit_intercept: True (default) | False
  • n_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

linear_model_surya_sudhaharan-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file linear_model_surya_sudhaharan-0.1.0.tar.gz.

File metadata

File hashes

Hashes for linear_model_surya_sudhaharan-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fde71a52c79c76242718f2c9dde600f350d23a6fcb8c7b7f2900547b679d12fd
MD5 e62dd79e593f447952951510e6ec020a
BLAKE2b-256 34696be4be5a6b8aa03beb4326dada4aa37da0e69852882ee1d3069397bd39da

See more details on using hashes here.

File details

Details for the file linear_model_surya_sudhaharan-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for linear_model_surya_sudhaharan-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2dcea5f2480b986717626cdde21b81fcdfa645278e24821985a7f9200d4e5016
MD5 70d80b937698ac09bd33e75d551b97c7
BLAKE2b-256 d7775725e62a83043ad13a88becc2515d496a233de8432602a3870919536cfeb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page