Skip to main content

Linear Regressor that automatically does all the tests on the data

Project description

LinearRegressor — A From-Scratch Linear Regression Library with Statistical Diagnostics


LinearRegressor is a fully custom-built Python library that implements Ordinary Least Squares (OLS) linear regression from scratch, without relying on scikit-learn.
It is designed not only to fit regression models, but also to validate data, check statistical assumptions, detect multicollinearity, and generate diagnostic reports.

This project was created as an educational yet production-grade implementation of classical econometrics and regression analysis.

🚀 Key Features
✔️ End-to-end data validation

Before training, the library automatically checks:

Type validation for X and y

Missing values (NaN), infinite values, and empty entries

Feature dimensionality and dataset size

Non-numeric values

Duplicate columns

Collinearity and matrix singularity

If the data is not suitable for regression, it raises clear, interpretable errors.

✔️ From-scratch OLS estimation

The model computes parameters using:

𝛽
^
=
(
𝑋

𝑋
)

1
𝑋

𝑦
β
^


=(X

X)
−1
X

y

with custom error handling for singular matrices and multicollinearity issues.

✔️ Automatic assumption diagnostics

After fitting, the library runs classic econometric tests:

Assumption Test Used Detects
Linear specification Ramsey RESET Nonlinear relationships
Normality of residuals Jarque–Bera Skewness & kurtosis issues
Heteroscedasticity Breusch–Pagan Non-constant variance
Multicollinearity VIF High correlation between features
Autocorrelation (for time series) Durbin–Watson Serial correlation

Warnings are issued automatically with actionable suggestions.

✔️ Prediction

Simple .predict() interface using learned weights and bias.

✔️ Model evaluation

Compute common regression metrics:

MSE

RMSE

MAE



✔️ Built-in visualization (optional)

The library can generate:

Regression plot (for single-feature regressions)

Residual plot

to quickly evaluate model quality.

📦 Example Usage
from linreg_prod import LinearRegressor

model = LinearRegressor()
model.fit(X_train, y_train)

predictions = model.predict(X_test)

🧪 Unit-Tested

The library includes a complete test suite validating:

Data validation logic

Preprocessing

Correlation warnings

Fitting and prediction

OLS estimation behavior

Metrics correctness

Error handling for singular matrices and invalid data

All tests are written in pytest and pass successfully.

Change Log
==========

0.0.2 (20/11/2025)
-------------------
- First Release

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

linregressor-0.0.2.tar.gz (8.4 kB view details)

Uploaded Source

File details

Details for the file linregressor-0.0.2.tar.gz.

File metadata

  • Download URL: linregressor-0.0.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for linregressor-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2b4889bf9bdb61f102394cfa695f8e6770f8bd1b37de3e8094f072d4ddac4ed8
MD5 dca0e006dba9e656c9961cd267ff7e6b
BLAKE2b-256 e5a458e4429e24831bb921e699a8db818f5b847fe878eb444877ca747d9088e0

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