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

pip install 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

For detailed documentation in your preferred language.

For developers and contributors.

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.4.1-cp311-cp311-win_amd64.whl (197.0 kB view details)

Uploaded CPython 3.11Windows x86-64

rustgression-0.4.1-cp311-cp311-manylinux_2_35_x86_64.whl (349.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

rustgression-0.4.1-cp311-cp311-macosx_11_0_arm64.whl (297.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for rustgression-0.4.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c4922d8c16cebef856f7d0b5996faf8d2ab56322a34cd10466f6c5844b524b8a
MD5 7882b5807a6c7228f59c4793b06008b4
BLAKE2b-256 d6ddf50ec74948a669a08606fea68db60c6b358d2b61d0551f65cf70725dfcd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustgression-0.4.1-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 463fdc4bc6cd23d96e06dbd035985dea560276f277439696aaab6cacaeb95f22
MD5 4857d6f1cece079aa4aba396d521dc16
BLAKE2b-256 cbdbd87ecefff45ca1b22c7fe8af2d41da1308c424b627548a2603e6f6f85dc5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustgression-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70a3c3443406a834f933ef989ebaa8cbcef345891d779e266a22aa569b79e8ca
MD5 b0f4f42ca4963c2ce6e48403793ba7da
BLAKE2b-256 ea9d85fd09f938908d378e8321f7461722703b0af38de7ead2f17af15f75c38c

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