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.4.0.tar.gz (9.7 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.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

crabbymetrics-0.4.0-cp314-cp314-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

crabbymetrics-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

crabbymetrics-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

crabbymetrics-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

crabbymetrics-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

crabbymetrics-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

crabbymetrics-0.4.0-cp311-cp311-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

crabbymetrics-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

crabbymetrics-0.4.0-cp310-cp310-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for crabbymetrics-0.4.0.tar.gz
Algorithm Hash digest
SHA256 a5efe4664637671d87537d1214299ce54cf82e9351b62fc8864d9084ea666f4f
MD5 5446275638b5640a6bb81320cf3e161d
BLAKE2b-256 999edc9d42aff1dc15ffa766ad353306f768c3f88c5aa255e971caef1e90821f

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4928e0e4def190b7094a470548416d3b51c2ac8b3b09838b64153794fd56c3c
MD5 1e89a5ab87aad946068c8cf0f8687fd3
BLAKE2b-256 7e37c7d6d4b221562ddf1e0499c2996ee49b3cd42d6e9a948be5f19eb8ee8dc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 24ad4b12ba1c58a96bcc075e487607ed2ed28f5293547db02d92790b7b6fa362
MD5 f8515ae7e9b196ae3d97b3a0db19eb6d
BLAKE2b-256 97aa50bf575d792ece5077b7c712185dc475f94dd95612304474e25a086791de

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59ab21ea945e31c42590480c078ecdbdc10914252d1847db810f547a4f8a4451
MD5 3e999751747142ee15c162313927f79c
BLAKE2b-256 6421cc2bd841647e316b553f4daf73d8536f81e31cb58d6fe0fb136fa5b5c507

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29d38625278e04d8caaa2002db1848010e13559985d40c0da2847ad7de6f81ce
MD5 97c5544836a1b83d9f5e19a3361f747c
BLAKE2b-256 32142025af60194980dfbc41c52708d44ef0ddb6939b43d9987bad5a066cd7ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 714621debf64a77378010436258057d593cbc9c6e9d07a62260d4aecc4c9b60b
MD5 6bfb539c515de6ff01ab6ac7d75d2bf5
BLAKE2b-256 1677ca7b26120e2a2af4980fb1c36d6b7c5810c71361c59a9d36bf3603fb5985

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03e33a586274fb982bc764c462b6bc5d855f04d7d0a679510421fae987046564
MD5 7a39b7e582971e4daefbc50e28c6e41f
BLAKE2b-256 60b6bafaee8cf901f18b487de59cb340614a690a7f301733128458bae8f81fee

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8033acec1a6f3c932f850b2a6590a8bd14baa3e71183734bd3f524501f4e96c2
MD5 9eb5b609fbf6fcfec000da9596868f27
BLAKE2b-256 4fe66fe03100944db9946087964639b49f4041910105aef8427db550736cf392

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5a54ca8ff9c68f939ec3dab48b1b432d52479db595e1ebf7c3d7b1fd1f045c7
MD5 dd66c091603c93d16ffb7ae57b47d81d
BLAKE2b-256 8fcf065fe44609b8679afc2bc417a938224010f823113e0003a0366646cf0a17

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 942d8d233a9ecdee0be7bcb684a17a7ddb1ea0eb155fa264e6b35c0d3a69d105
MD5 5472bb5a57c6fe503f2c085de9d370d8
BLAKE2b-256 42c03d4a85a90cb1d986c1468af5312fb80b45986fc9add919e1df177360b458

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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.4.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crabbymetrics-0.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 412e89d9e630c6615a381b73df36cd2391e14ca0271ae767f7fb8130572835a3
MD5 df35a8ecf79f45bf7d16469d5b986798
BLAKE2b-256 0a65cf12e0074162e39873e1253e680c14a20ffae946bb7bef11a0121dba00ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabbymetrics-0.4.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