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.26.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.26-cp310-abi3-win_amd64.whl (10.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.26-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.26-cp310-abi3-musllinux_1_2_aarch64.whl (8.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.26-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.26-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.26-cp310-abi3-macosx_11_0_arm64.whl (8.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.26-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.26.tar.gz.

File metadata

  • Download URL: gamfit-0.1.26.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.26.tar.gz
Algorithm Hash digest
SHA256 dfb3a25e7e4ddf3f73f870c3e79db092f39c30a255efce1d951d1a7f834a7763
MD5 61b18777f1a943f84aa56c663d23716c
BLAKE2b-256 75ea41d2d31a6e17b6a7a646f1376f6d73b62a0caaa23f8efc831d342e42ec6b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.26-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.26-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ea0e826d82866f2365496be178bd1566182ab922313757e6a9462071f2321bde
MD5 5af8dda7bd791c2f107179bd4f2007d4
BLAKE2b-256 e8489d9ebc8501552a704b265c25cd81b686ff749a5d73329c91e5db36f4ac5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.26-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d70de0cf0d4e9960066d19703ac0cb8483c3954abd8fb35ed38b1536b8af0b8c
MD5 f60e107753aa18f1545b1a7b344777f0
BLAKE2b-256 2338e982f2770d708068f8752634795adf7d75402aa67df453ed71cb25fdb1ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.26-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 46a4dd3c062c6f2680d9b3fec47504b11f98fb87fe3b8758252c3697f6726372
MD5 a561f8773908af2c901be40ceb4ab79d
BLAKE2b-256 1b3b7b0a9deaa8cc99fd337315fe385e9350adfc5a9b17e4a07df7815bacab22

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.26-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93b146fe76f947268d75ab4632fd83a9c3f593a3e98a9aa1a0514a3570dc82ca
MD5 e217b7a971e900817f64a08c8068f90e
BLAKE2b-256 0aaf1431c7fd246c4ee99f62e036b25eadc591246e27c10d0a989860f86602ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.26-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6492a6dd6b9bca390006863ec118184f2f63ce4327ba5b69546ef4af90afcc36
MD5 e56350f49385cd88a01f8687e998e7fb
BLAKE2b-256 be382d153cb43e35538936af8f4e2a557b16579094bad9367fb6fa1968bfc6c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.26-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c8bd86a9000227abcd3aecfd046e06c093eb42d1a553c9a387bc6ccbeb0a5636
MD5 8744abc244049549224c5700b6ea42c2
BLAKE2b-256 c792e69a4ecce8ebdd853cb769bfe75679b439d9dc0df4661fd6e77430e0fd51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.26-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 43e54632eae180f1603687afc07035e807e3da2c5b6533d7bf9c0c4591db8f73
MD5 31ddaf397c791168326fdb2c5ff2d43e
BLAKE2b-256 ce20edfdadc5567803d12f407a5eccf59b6bb2a18ac58a345f51271511d8a600

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