Skip to main content

Educational regression models built from scratch in Python

Project description

RegressionLib

RegressionLib is a lightweight, educational regression library implemented from scratch in Python with NumPy. It supports multiple regression models, aiming to help students and researchers understand the mathematical foundations of regression algorithms without the black-box nature of larger frameworks.


🚀 Features

  • Linear Regression
  • Lasso Regression (L1 regularization)
  • Ridge Regression (L2 regularization)
  • Polynomial Regression
  • Clean, beginner-friendly API (fit, predict, evaluate)
  • Minimal dependencies (NumPy only)
  • Clear educational codebase, easy to extend import numpy as np from regressionlib import LinearRegression, LassoRegression, RidgeRegression, PolynomialRegression

Example training data

X_train = np.array([[1], [2], [3], [4], [5]]) y_train = np.array([1.5, 2.5, 3.5, 4.5, 5.5])

Linear Regression

lr_model = LinearRegression() lr_model.fit(X_train.flatten(), y_train, learning_rate=0.01, epochs=1000) mse, r2, acc = lr_model.evaluate(X_train.flatten(), y_train) print(f"Linear Regression - MSE: {mse:.4f}, R2: {r2:.4f}, Accuracy: {acc:.2f}%")

Lasso Regression

lasso = LassoRegression(learning_rate=0.01, iterations=1000, l1_penalty=0.1) lasso.fit(X_train, y_train) mse, r2, acc = lasso.evaluate(X_train, y_train) print(f"Lasso Regression - MSE: {mse:.4f}, R2: {r2:.4f}, Accuracy: {acc:.2f}%")

Ridge Regression

ridge = RidgeRegression(learning_rate=0.01, epochs=1000, l2_penalty=0.1) ridge.fit(X_train, y_train) mse, r2, acc = ridge.evaluate(X_train, y_train) print(f"Ridge Regression - MSE: {mse:.4f}, R2: {r2:.4f}, Accuracy: {acc:.2f}%")

Polynomial Regression

poly = PolynomialRegression(degree=2, learning_rate=0.01, epochs=1000) poly.fit(X_train, y_train) mse, r2, acc = poly.evaluate(X_train, y_train) print(f"Polynomial Regression - MSE: {mse:.4f}, R2: {r2:.4f}, Accuracy: {acc:.2f}%")

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

RegressionLibrary-0.3.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

RegressionLibrary-0.3-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file RegressionLibrary-0.3.tar.gz.

File metadata

  • Download URL: RegressionLibrary-0.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for RegressionLibrary-0.3.tar.gz
Algorithm Hash digest
SHA256 32718558d099090cc64b1961a9761309894cdf70b6cbdb031469e2d82f66d03e
MD5 c7356a8edff7a684fc02bd8295916e25
BLAKE2b-256 6ba4e5cbb4896ca1826d690bbf7e1495124d4732397aad5d01e4d2fbbe2166bb

See more details on using hashes here.

File details

Details for the file RegressionLibrary-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for RegressionLibrary-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1de3e590ced00267a712e07791112383845d92b01ff753a33d363fce4338ea31
MD5 14fc3f579b7cab5a599fbe4aaa14c935
BLAKE2b-256 4db1efc68f1c408052db56644537270c49a999d02e3f1e2fa941d907a0a194f0

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