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

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.24-cp310-abi3-musllinux_1_2_x86_64.whl (9.6 MB view details)

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

gamfit-0.1.24-cp310-abi3-musllinux_1_2_aarch64.whl (8.3 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.24-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.3 MB view details)

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

gamfit-0.1.24-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gamfit-0.1.24-cp310-abi3-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.24-cp310-abi3-macosx_10_12_x86_64.whl (9.0 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: gamfit-0.1.24.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.24.tar.gz
Algorithm Hash digest
SHA256 bae33c6a032b0585e00145bc3a89debe8fcea4a5b6013de5b31a5b24b35b0ce0
MD5 bb592051a084e01ac3604ef663c9f35b
BLAKE2b-256 e5b561446711f4993b76954ffb4fffb5c82ad86cf3d5d108482568f67a333ccf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.24-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.9 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.24-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 71bbe4c3d3aea3d720f4f7c4e5944956f8bf535a556379ddec49582d84c6a6bb
MD5 785459cc31d773e69bc156134b3a9509
BLAKE2b-256 de0fef8c4ee733d83469a762d285748c85be887cdfc35bd5de39c04ee44f69fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.24-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5c00298997c93db927119d20561dfb4dbae5bac674f48455f94e210f13d37015
MD5 7579dc6869801bb7969f97619fbf2db7
BLAKE2b-256 f69dff3efb0f622ecb254d25e623f808bbb0cb97ce1213aa717236abfbbfcac6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.24-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1aa7b7ec313a20daf2d72de3ea4453ccef8b3e096c0a2d651ba88cae2bd1ad36
MD5 13a87a75f8c7b9a4aa5e9a9407ce64dc
BLAKE2b-256 4ad7f20a99f11e4bf1ac2dd2f4e34ef732d675fb5b5eedcb5140d9b7e0b8d29e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.24-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 607b8b3e2432d1e7e36b2ebad95d5ae21256648d9954165df45392030a084fc8
MD5 35749eb3aae130c48dd67edda9a51460
BLAKE2b-256 03fba5482867517c8449faaa6d349dbc5aa7f8e3a6b5968412ca78dea94eea40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.24-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 be966eab393cdd656833a7d7da8c82693dbb2672636f27276fd74644f2f34d27
MD5 e08600172716e101ee09ddea439a9e7c
BLAKE2b-256 a5be44307a77d618dc570768476c3a81b4924547a0c13a1389ee80a15accf3b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.24-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 407e8cd98b510653cfb982107029dd066f5090fdbfa2f23f51b29717695f30c3
MD5 78aa4028f9c14d1d5c0b7c9da08f3bfd
BLAKE2b-256 587e8a799fede77540acbcffed3e4eebd286d2143593a4864d6469edacbdf7f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.24-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 205bab0b810256a69f8aa8aa77cad347c43df5e93c1a7d66d8aeb695f05eebda
MD5 ebd824988704cb7d2a9a94da68a8a52d
BLAKE2b-256 fb2f531098970cde657482e4051f7f291da5463dce578908d21d572e3254fa51

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