Skip to main content

Formula-first generalized additive models with a high-performance Rust core

Project description

gamfit

PyPI Python License

A formula-first generalized additive model library for Python, backed by a high-performance Rust engine.

gamfit fits Gaussian, binomial, Poisson, and Gamma GLMs with smooth terms, random effects, location-scale extensions, survival likelihoods, and flexible/learnable links. Smoothing parameters are selected by REML or LAML. Posterior sampling uses NUTS.

Install

uv add gamfit

Or with a managed Python (one-off, no project required):

uv pip install gamfit

Wheels are published for Linux (x86_64, aarch64), macOS (x86_64, Apple silicon), and Windows. No Rust toolchain required.

Quick start

import gamfit

train = [
    {"y": 1.2, "x": 0.0},
    {"y": 1.9, "x": 1.0},
    {"y": 3.1, "x": 2.0},
    {"y": 4.5, "x": 3.0},
]

model = gamfit.fit(train, "y ~ s(x)")
predictions = model.predict([{"x": 1.5}, {"x": 2.5}], interval=0.95)
print(model.summary())
model.save("model.gam")

Pandas, pyarrow, dict-of-columns, and list-of-records inputs all work without conversion.

What's different

  • Three-part penalty structure. Each smooth gets separate penalties for magnitude, gradient, and curvature. Most GAM libraries use one (curvature only) or two; the three-part decomposition gives the smoother more degrees of freedom to distinguish flat-but-offset functions from wiggly ones.
  • Flexible link functions. A spline offset from a base link (e.g. probit) lets the data correct for link misspecification while encoding the belief that the base link is approximately right.
  • Surface smooths. Thin-plate splines, Duchon radial bases with triple-operator regularization, and Matérn covariance smooths in arbitrary dimension, with automatic knot placement.
  • Adaptive anisotropy. Per-axis spatial anisotropy lets the model shrink or stretch each feature axis independently within a single joint smooth.
  • Composable basis/kernel. Mix and match the kernel of one spline family with the length-scale behavior of another (e.g. Duchon kernel with Matérn-style global κ scaling).

scikit-learn integration

from gamfit.sklearn import GAMRegressor

est = GAMRegressor(formula="y ~ s(x)")
est.fit(train)
preds = est.predict([{"x": 1.5}, {"x": 2.5}])

Public API

Symbol Purpose
gamfit.fit(data, formula, **kwargs) Fit a model from a dataset and a Wilkinson-style formula.
gamfit.load(path) / gamfit.loads(bytes) Reload a saved model.
gamfit.validate_formula(data, formula, ...) Type-check a formula against a dataset without fitting.
gamfit.build_info() Native-extension build metadata.
gamfit.explain_error(exc) Convert a gamfit exception into a human-readable hint.
gamfit.Model Fitted-model handle: predict, summary, check, diagnose, plot, report, save.
gamfit.sklearn.GAMRegressor / GAMClassifier scikit-learn-compatible estimators.

See the project documentation for the full guide, the formula DSL reference, and the CLI.

Optional extras

uv add "gamfit[pandas]"     # pandas + pyarrow input/output
uv add "gamfit[plot]"       # matplotlib-based plotting
uv add "gamfit[sklearn]"    # scikit-learn integration
uv add "gamfit[all]"        # everything

License

AGPL-3.0-or-later. See LICENSE. A commercial license is available for closed-source or SaaS use — see COMMERCIAL.md.

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

gamfit-0.1.27.tar.gz (2.5 MB view details)

Uploaded Source

Built Distributions

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

gamfit-0.1.27-cp310-abi3-win_amd64.whl (10.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.27-cp310-abi3-musllinux_1_2_x86_64.whl (9.7 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

gamfit-0.1.27-cp310-abi3-musllinux_1_2_aarch64.whl (8.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.27-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

gamfit-0.1.27-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gamfit-0.1.27-cp310-abi3-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.27-cp310-abi3-macosx_10_12_x86_64.whl (9.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file gamfit-0.1.27.tar.gz.

File metadata

  • Download URL: gamfit-0.1.27.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gamfit-0.1.27.tar.gz
Algorithm Hash digest
SHA256 660c0c7cc2a66490aa67d9342696a23e400256c77cdc33a903894df353026bc8
MD5 c6f25e24c206858a0f68ae378649c438
BLAKE2b-256 f44e514172573f5a881943bb2dd7b5002471e11c6218c5fa125875daf7c3125c

See more details on using hashes here.

File details

Details for the file gamfit-0.1.27-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: gamfit-0.1.27-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 10.0 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for gamfit-0.1.27-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 734642a93ca22dff410c963ac8846f0da5c984272571fa668aed89571c45a0ab
MD5 d061e2fd5668e4807610ee089b05749c
BLAKE2b-256 6580f1d7c00d41428b535a65cf9b720e0f6860839b89c22fbbc4c47e622ade78

See more details on using hashes here.

File details

Details for the file gamfit-0.1.27-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for gamfit-0.1.27-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 829d988183ede50549e2a0babad4026bdee70c0ab619280a9511c87804284485
MD5 a6af94b541924b498a2ef3ea109e7d1a
BLAKE2b-256 52d78d86376621c587ee09631998491891f2791db5efa2083550daf924d2521c

See more details on using hashes here.

File details

Details for the file gamfit-0.1.27-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for gamfit-0.1.27-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 02d1e12a923bd3ca9669271108f39f8c99fff4bf4a2269395ad8239447437547
MD5 d64f237eb90ade3689a1ae5d094c354d
BLAKE2b-256 ff4fd078103af2e62a50c80e83ce0eb2974bf13b80e73e8a6a8b6aacb480d8ef

See more details on using hashes here.

File details

Details for the file gamfit-0.1.27-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gamfit-0.1.27-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d80871cc79f50fb7f839059e098d025108c0c71635478d85ce0524d4745a3362
MD5 21e6af1da5370d36401352459c3d6804
BLAKE2b-256 065d6f417629ec218d4addfc1fec2027386e20212e3fab87d7bf00516fdeb32e

See more details on using hashes here.

File details

Details for the file gamfit-0.1.27-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for gamfit-0.1.27-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 70b521b5ddf819c146cfb30c6b0aaac55988c8ec4b495a70950ec29a61741271
MD5 e0a68bce1cc21704065693f3ae370830
BLAKE2b-256 21f90a96a3c716270d3c6661404665746a09a7e6be93b65d9a24d4d34e02bdd7

See more details on using hashes here.

File details

Details for the file gamfit-0.1.27-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for gamfit-0.1.27-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a8d1cbe74f80289cd5a1c8c07dd30abf1b7deb30a2cdefb7149d6ff9c41d83a
MD5 3acf0c591358a1e1b1d153cdc980d3e2
BLAKE2b-256 465e0489ace420217d6cbcaad67c25c1ebc4f4ebc5fa8380377b2161a93b3efb

See more details on using hashes here.

File details

Details for the file gamfit-0.1.27-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for gamfit-0.1.27-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9273fbe4b1ea0ae01d74a1fc0a7d424a98020649568f152553806aa483eae91f
MD5 5c0d64d59bf5654fa5004961d5604aed
BLAKE2b-256 0f6287f1d4c7e5a2189dbb5d7a3f2e84b5ca19e0b2d359c934a23dbcb1adbc64

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