Skip to main content

A high-performance Multiple Linear Regression model implemented in C++ with a clean Python API via Pybind11 bindings

Project description

mlr_cpp – Fast C++ Multiple Linear Regression with Python API

mlr_cpp is a high-performance Multiple Linear Regression library implemented in C++ and exposed to Python using pybind11. It is designed for speed, delivering results over 10x faster than scikit-learn, while providing a user-friendly pandas-compatible API.


Key Features

  • Blazing fast C++ core, with Pybind11 for seamless Python integration
  • Supports full model diagnostics: R², Adjusted R², MAE, MSE, F-test, T-statistics, P-values
  • Automatically checks for multicollinearity and sufficient data
  • Equation generation with smart rounding and absolute tolerance
  • Compatible with pandas DataFrames

Benchmarks with sklearn

coefficients

mlr_cpp: [3.98827526e+00 3.98919944e+00 8.77169801e+00 3.74320006e+00
          3.38302087e-04 1.10138110e-02]
sklearn: [3.98919944e+00 8.77169801e+00 3.74320006e+00 3.38302087e-04
          1.10138110e-02]

Runtimes

mlr_cpp: 0.000344s
sklearn: 0.004404s

$R^2$ Scores

mlr_cpp: 0.987661
sklearn: 0.987661

mlr_cpp provides identical accuracy while being ~10x faster than scikit-learn

Installation

pip install mlr_cpp

Optional Extras

pip install mlr_cpp[examples]  # for examples, plotting
pip install mlr_cpp[dev]       # for development tools

Example Usage

import pandas as pd
from mlr_wrapper import MLRWrapper

df = pd.read_csv("your_data.csv")
model = MLRWrapper(df, target_col="mpg")

model.fit()
eqn, predictors, tests = model.get_model_summary(tstats=True)

print(eqn)
print(predictors)
print(tests)

Prediction

model.predict(new_df)

Model Summary

You can retrieve a complete summary of the model including the regression equation, coefficients, p-values, and test metrics:

eqn, predictor_summary, model_tests = model.get_model_summary(tstats=True)

print(eqn)                  # Prints the regression equation
print(predictor_summary)    # DataFrame with coefficients, p-values, and t-statistics
print(model_tests)          # DataFrame with metrics like R², MAE, MSE, etc.

Evaluation Metrics

After fitting the model, mlr_cpp provides access to standard evaluation metrics for performance diagnostics:

model.get_R2()           # Coefficient of Determination (R²)
model.get_AdjustedR2()   # Adjusted R²
model.get_MAE()          # Mean Absolute Error
model.get_MSE()          # Mean Squared Error
model.get_ftest()        # F-statistic of the regression model
model.get_TStatistics()  # T-statistics for each predictor
model.get_PValues()      # P-values corresponding to each predictor
model.get_model_tests()  # Summary DataFrame containing major evaluation metrics

👨‍💻 Author

Sidhant Raj Khati

🌐︎ Website: sidhantkhati.com
💼 LinkedIn: LinkedIn
🔗 GitHub: Sidhant-1299/mlr_cpp

📄 License

This project is licensed under the MIT License

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

mlr_cpp-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (670.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

mlr_cpp-1.1.0-cp312-cp312-macosx_10_13_x86_64.whl (629.8 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

mlr_cpp-1.1.0-cp311-cp311-macosx_11_0_arm64.whl (674.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mlr_cpp-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl (635.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

mlr_cpp-1.1.0-cp310-cp310-macosx_11_0_arm64.whl (673.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

mlr_cpp-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl (633.5 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

mlr_cpp-1.1.0-cp39-cp39-macosx_11_0_arm64.whl (673.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

mlr_cpp-1.1.0-cp39-cp39-macosx_10_9_x86_64.whl (633.6 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

Details for the file mlr_cpp-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4f5cdb2849d16d1fb5909f7a10ace583c78023315a91907b4293aed792f8524
MD5 61680918d4616cece0cd792a323317b1
BLAKE2b-256 99b4fd87fafd62e48d2329999ec8a40f810dbec7ea5c0ce6c0c069f479c9ce6a

See more details on using hashes here.

File details

Details for the file mlr_cpp-1.1.0-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 62db7ec747d24ba73a3908923ff7a982f54699bc4c6d36028518a1f7d99864f3
MD5 1cca5173c1008631eed53c447cd7d41f
BLAKE2b-256 fe443ff501811c6d2c8c0f562cfd60db2d8e93ee983e48abb51e205d8c5c8318

See more details on using hashes here.

File details

Details for the file mlr_cpp-1.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c681f6d2f2538ef8bad30a21e32e0cb33a130332c9ba978e24efb385cf987da3
MD5 9b6593f3e3bbbc7bc101a434edd2d132
BLAKE2b-256 c7b3c07ccde0f212e683d0304b3f4a81e79047d0f4d44b8600335d5a7f7f54c1

See more details on using hashes here.

File details

Details for the file mlr_cpp-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 483237a1db6850ca8f396f1a137ae4f4c51c7110fa63556d68db2193e4ece9b0
MD5 51be4e36ad55dfdbdc8bf477dea73912
BLAKE2b-256 17571d36c4c056b91ff138cd134cd18232b192d1d4f573ce5ebf8d29087a1376

See more details on using hashes here.

File details

Details for the file mlr_cpp-1.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d7b101d354ee1c0329673780e89196415e138f4cef50a64efc60e10146569c9e
MD5 f17ead4e44aa8158f116ec0fb1aa901a
BLAKE2b-256 6c5d8c489a248147acd919e1f51ef94270018b7f3083031563573ee4d44422ca

See more details on using hashes here.

File details

Details for the file mlr_cpp-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ce8963d3c59c45da9fc68c4f14dcf79fd881b5e1097d7bb2494270145c10bfeb
MD5 f75ea24bd7979b6dc025dbc9572699e9
BLAKE2b-256 6af21aba72098f0a829dcfc39376018cd7f7677040b5fb5d48161b0d10fbdcd3

See more details on using hashes here.

File details

Details for the file mlr_cpp-1.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0387cbd53b595afaf780d034955223e6e4ffe29892b60438c2f6ce1321ea8067
MD5 f1b01ada78b1ba75b87f3a030071a972
BLAKE2b-256 bc60cf22c1dfede6487027f318317bc078ef2a2d36f9bc4c083945af05706198

See more details on using hashes here.

File details

Details for the file mlr_cpp-1.1.0-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for mlr_cpp-1.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7f663b5a4f38f781a53e38a87068a0000b5bee258f803bc818053c88c23f6a23
MD5 6ed7ddc996cdd705b304af45c5142c9d
BLAKE2b-256 3f2e7cfe53c52345800ec7e7c95b273a55e6896c8c1aa317ab83a6506f46c137

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