Skip to main content

Fast C++ regression library with Python bindings

Project description

cRegression

cRegression is a fast and easy-to-use Python library for linear regression, powered by a C++ backend using pybind11.
It allows you to fit simple linear regression models, make predictions, and evaluate model performance efficiently with NumPy arrays.


Fast C++ regression library with Python bindings.

cRegression is a high-performance linear regression library written in C++ with seamless Python integration using pybind11 and numpy. It provides a simple API for fitting models and making predictions with the speed of C++.

Installation

You can install cRegression using pip:

pip install cRegression

Usage

import numpy as np
from cRegression import LinearRegression

2. Prepare your data

# Example data
x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 5, 4, 5])

3. Create a LinearRegression object

lr = LinearRegression(x, y)

4. Access model parameters

print("Slope (b):", lr.slope())
print("Intercept (a):", lr.intercept())

5. Make predictions

new_x = [6, 7]
predictions = lr.predict(new_x)
print("Predicted y:", predictions)

6. View detailed regression statistics

lr.summary()

This prints a complete summary including:

  • Mean(X) and Mean(Y)
  • Pearson correlation
  • Std(X) and Std(Y)
  • Slope and Intercept
  • RMSE and MAE
  • Residual standard error
  • Slope standard error
  • t-value of slope

API Reference

LinearRegression(x, y)

  • Parameters:
    • x – 1D NumPy array of independent variable values.
    • y – 1D NumPy array of dependent variable values.
  • Description: Initializes the linear regression model by fitting y = a + b*x.
Method Description
slope() Returns the slope (b) of the regression line.
intercept() Returns the y-intercept (a) of the regression line.
predict(values) Returns predicted y values for given x values.
predict_single(value) Returns the predicted y for a single x value.
rmse() Returns Root Mean Squared Error.
mae() Returns Mean Absolute Error.
r_squared() Returns coefficient of determination R².
residual_std_error() Returns residual standard error.
slope_standard_error() Returns standard error of the slope.
t_value_slope() Returns t-value for slope significance.
summary() Prints detailed regression statistics and error metrics.

Notes

  • Input arrays x and y must have the same length.
  • Optimized with C++ for speed on large datasets.
  • Simple and lightweight, focusing on core linear regression functionality.

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

cregression-0.1.0.tar.gz (45.0 MB view details)

Uploaded Source

Built Distribution

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

cregression-0.1.0-cp311-cp311-win_amd64.whl (433.1 kB view details)

Uploaded CPython 3.11Windows x86-64

File details

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

File metadata

  • Download URL: cregression-0.1.0.tar.gz
  • Upload date:
  • Size: 45.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for cregression-0.1.0.tar.gz
Algorithm Hash digest
SHA256 85df86433a5cfadafcd7fc0d307e02d49fcef1141c76a4bb155e1b44d432625c
MD5 3a3236992a012d8d708496d769cf3e9f
BLAKE2b-256 fd0ccea557d5e88a823950ad112e7d833166b2ca891d582f93001f4286bc39d5

See more details on using hashes here.

File details

Details for the file cregression-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for cregression-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 aa460a5f2b90775a2cf8ad8317139a502a6f361a27eaa0469b33f1a2a969f4b7
MD5 9973301a0a53bd9508f6eafd01dbddbb
BLAKE2b-256 3fe9fa97d26cf79a0a16f745b3a5dfdc90dad2ebca811c44a9c58a32aabb45d6

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