Skip to main content

Fast OLS and TLS regression using Rust backend

Project description

rustgression

PyPI Downloads

This project provides fast regression analysis (OLS, TLS) as a Python package.

Overview

rustgression provides high-performance regression analysis tools implemented in Rust as a Python package. It includes the following features.

  • Ordinary Least Squares (OLS): Traditional least squares method. Minimizes errors only in the y-direction.
  • Total Least Squares (TLS): Orthogonal regression. Considers errors in both variables (x-axis and y-axis).

This package targets Python version 3.11 and above.

Installation

Using pip:

pip install rustgression

Using uv:

uv add rustgression

Usage

import numpy as np
from rustgression import OlsRegressor, TlsRegressor

def generate_sample_data(size: int = 100, noise_std: float = 0.5) -> tuple[np.ndarray, np.ndarray]:
    """Generate sample data for regression example.

    Args:
        size: Number of data points
        noise_std: Standard deviation of noise

    Returns:
        Tuple of (x, y) arrays
    """
    x = np.linspace(0, 10, size)
    true_slope, true_intercept = 2.0, 1.0
    y = true_slope * x + true_intercept + np.random.normal(0, noise_std, size)
    return x, y

def main():
    # Generate sample data
    x, y = generate_sample_data()

    # Ordinary Least Squares (OLS) Regression
    print("=== Ordinary Least Squares (OLS) Results ===")
    ols_model = OlsRegressor(x, y)
    print(f"Slope: {ols_model.slope():.4f}")
    print(f"Intercept: {ols_model.intercept():.4f}")
    print(f"R-value: {ols_model.r_value():.4f}")
    print(f"P-value: {ols_model.p_value():.4e}")
    print(f"Standard Error: {ols_model.stderr():.4f}")
    print(f"Intercept Standard Error: {ols_model.intercept_stderr():.4f}\n")

    # Total Least Squares (TLS) Regression
    print("=== Total Least Squares (TLS) Results ===")
    tls_model = TlsRegressor(x, y)
    print(f"Slope: {tls_model.slope():.4f}")
    print(f"Intercept: {tls_model.intercept():.4f}")
    print(f"R-value: {tls_model.r_value():.4f}")

if __name__ == "__main__":
    main()

Documentation

Author

connect0459

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.

rustgression-0.5.0-cp311-cp311-win_amd64.whl (212.2 kB view details)

Uploaded CPython 3.11Windows x86-64

rustgression-0.5.0-cp311-cp311-manylinux_2_35_x86_64.whl (361.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

rustgression-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (314.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file rustgression-0.5.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for rustgression-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ff37ea97f64f1f9064b4787c30eec55b6b4606de0f6a81cd49f1941ae2edbfa9
MD5 bac7a8c86def8257c7d959c044f9e156
BLAKE2b-256 660fb7a77d059fcf63fb8ca2962213655adb9e91c8a68c704427b0d675ef6996

See more details on using hashes here.

File details

Details for the file rustgression-0.5.0-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for rustgression-0.5.0-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 675292d259f2e6f3531310e75ee8cd1d8e6fd87dbb452619a49d5a23f1fc4986
MD5 4acc4d2cfd03a800d692029bdbc666c3
BLAKE2b-256 ffd7edba732e1d0c246d7375aec6f8ceac0d31c17e9505ac8fdff8c1389dbf7f

See more details on using hashes here.

File details

Details for the file rustgression-0.5.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rustgression-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4344b31bb53ee648eb6873a672f4ebb6f0cfcd9f2d02090f055d689bdff47867
MD5 79c0b0c2ed748714bf787a66ca9c67bf
BLAKE2b-256 6a922a46c913cdd2389551b70ba59dc8027af6a4cb9ae70d29a079376b456869

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