Skip to main content

Rust-backed econometrics models with a scikit-adjacent Python API.

Project description

crabbymetrics

Rust-backed econometrics 🦀🔢 models with a scikit-adjacent Python API. Focus: extremely low dependency (just numpy), simple, fast estimators with robust standard errors and bootstrap support.

Features

  • OLS, FixedEffectsOLS, SyntheticControl, ElasticNet, Logit, Multinomial Logit, Poisson, TwoSLS, FTRL
  • ElasticNet spans the ridge and lasso corners: use l1_ratio=0.0 for ridge-style shrinkage and l1_ratio=1.0 for lasso-style shrinkage
  • PCA and KernelBasis for feature engineering before regression-style estimation
  • Optimizers namespace exposing LBFGS, BFGS, NonlinearConjugateGradient, Gauss-Newton least squares, and SimulatedAnnealing
  • fit, predict, summary, bootstrap
  • HC1 standard errors where applicable

Install

This package is built with pyo3/maturin and ships as native wheels.

uv pip install crabbymetrics

Example

import numpy as np
from crabbymetrics import OLS

x = np.random.randn(200, 3)
beta = np.array([1.0, -2.0, 0.5])
y = 0.3 + x @ beta + np.random.randn(200) * 0.1

model = OLS()
model.fit(x, y)
print(model.summary())

The direct optimizer wrappers live under Optimizers and follow a lightweight scipy-style interface:

import numpy as np
from crabbymetrics import Optimizers

def objective(theta):
    return float((theta[0] - 1.0) ** 2 + 2.0 * (theta[1] + 2.0) ** 2)

def gradient(theta):
    return np.array([2.0 * (theta[0] - 1.0), 4.0 * (theta[1] + 2.0)])

result = Optimizers.minimize_lbfgs(objective, np.array([4.0, 3.0]), gradient)
print(result["x"], result["fun"])

Benchmarks

The latest cross-library runtime snapshot is checked into benchmarks/runtime_comparison.csv with the corresponding plot in benchmarks/runtime_comparison.png.

Runtime comparison across crabbymetrics, scikit-learn, and statsmodels

This benchmark used synthetic problems with p=5, sample sizes from 10^3 to 10^6, fit-only timing, and a 45-second per-fit timeout.

  • OLS is competitive already and was faster than both scikit-learn and statsmodels at n=10^6.
  • Poisson beats statsmodels comfortably but still trails scikit-learn at larger n.
  • Logit and especially MultinomialLogit are the main performance gaps to close before adding more iterative GLM-style estimators.

Development

Create and populate the project virtual environment, then build the extension into that venv.

uv sync
uv run maturin develop

uv run maturin develop is sufficient for rebuilding and reinstalling the package in .venv once the environment exists. If you change Python dependencies or the pyproject.toml metadata, run uv sync again first.

Package versioning is sourced from Cargo.toml. The Python package metadata is dynamic, and commit_tag_release.sh reads the crate version directly before creating the vX.Y.Z tag.

Rendered examples and API docs live under docs/. Rebuild the site with quarto render docs. For the plotting examples, install the docs extra first: uv sync --extra docs.

Wheels

Wheels are platform-specific and included in GitHub releases. See the releases tab.

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

crabbymetrics-0.5.0.tar.gz (12.8 MB view details)

Uploaded Source

Built Distributions

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

crabbymetrics-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

crabbymetrics-0.5.0-cp314-cp314-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

crabbymetrics-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

crabbymetrics-0.5.0-cp313-cp313-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

crabbymetrics-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

crabbymetrics-0.5.0-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

crabbymetrics-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

crabbymetrics-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

crabbymetrics-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

crabbymetrics-0.5.0-cp310-cp310-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file crabbymetrics-0.5.0.tar.gz.

File metadata

  • Download URL: crabbymetrics-0.5.0.tar.gz
  • Upload date:
  • Size: 12.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for crabbymetrics-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fe9d28b8a79d164fba5e3f1ab45d67f79ca7c43107951d58baae033a98502602
MD5 da3322fd181addb4e6a426d70de953bf
BLAKE2b-256 5adec3ea9e46dffa42ccb3a3b05da6827a6d7f384ff8b0d4031e1283d93d142d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0.tar.gz:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d759038153f409e35b1a298a01568e44bd4f8267fbb4af0862d35cf20a4ca21b
MD5 81bc4c6eb1e6461725004c62a1704fde
BLAKE2b-256 f6da8c8ed2c64f160ff15022e256bd0644d33f6f16a6dd784a495f248b60d692

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5845563060feade7c7d7417b16d498cccd3feb5216a1be5591e7600c771203cd
MD5 dbb082538974ab7a0e5e915a48c4c548
BLAKE2b-256 c3e9f1090533776125dfa6a4edff8da5017213eb97dcc45a98f94bd74c78536d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 892947479240b484c57e8a08451cdbbe1ab437698372691d8ce994404f5aa81b
MD5 f53caa7818e1e58a0466eb3f7a6cbde0
BLAKE2b-256 c763cef11a36143e34c199a18ec61a396c5bca0f81ef9ce657d48e2892d4c654

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4bd5d49b4af5b9c8ac3528c303c652033a945953cdcabdbd9b7bf6dfc774821
MD5 7c5f650b790b5604944b62683877396f
BLAKE2b-256 608495574f2a7d84abb74b361af89f4697120cdeafb2cd965c46307f98a18bb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 142361199cb767b26c0d35e82ea25a4e4cbbb71b5eb2888e37e5c28611129051
MD5 557b1aaf398b6a7216e107dc5eb1881e
BLAKE2b-256 852048563927678db6cc2fe841f128eceb6964b6041b46702f84fd6e63ee4500

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f026dcfae903e7c6e2b3b7874691020b0f7b2528c7c21fdfc419856bf5e7d792
MD5 22c9731600f630213f55e596132eb71c
BLAKE2b-256 7e2d4ff0e5287fb8b1f86391ecac050d8e47324697a7d9a5a90b2acfe16616ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e4c07805d84456f943513488fbee448808443b6fcbf63613ae42e7d1fa4b7835
MD5 368a1ac2d80f39d1d4f7f4d9903c3a0c
BLAKE2b-256 74c493bd58afe92ec600d9a493422913687f48aa38b374056f3e3660e57ec119

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 364d1a7f5f350c639ef7b4bc1d98b72ebf4ea298ed4624554dad0083bef7ed25
MD5 9f193d7a4dacdb388a2f22aab36c573e
BLAKE2b-256 0021d2f3baf8863fe83f80b90b04fd1c30bd65c28ae2df864f6f4eb82580c146

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c87a0b2221fabd94000e2cfb3e28ed3e49d7584a80d324b6eec8cf1b67d39c1a
MD5 5cffc883adf6ec5d1ebab67eb6d29129
BLAKE2b-256 5a6ec71755f411dca02dcea49e43c4a2fa981b7a0bd8d9df2877a425fea94d2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crabbymetrics-0.5.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b782506a7f8855d28ee2dd4b01f72d6107e8cf9af19c3ef5914979be77e91f4
MD5 8c4ebcbd6003608655da30d77855693c
BLAKE2b-256 9bdbe9d9a39e31b9fefbdd2389ae4e50bcb46e4b195cc8b07d45fe0558291843

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.5.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: wheels.yml on apoorvalal/crabbymetrics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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