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

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.23-cp310-abi3-musllinux_1_2_x86_64.whl (9.5 MB view details)

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

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

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.23-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.23-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.23-cp310-abi3-macosx_11_0_arm64.whl (7.9 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.23-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.23.tar.gz.

File metadata

  • Download URL: gamfit-0.1.23.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.23.tar.gz
Algorithm Hash digest
SHA256 fd32fd57a0abf09e498d6a88c6944696ed7bc9f23793ffe53f994e63009160a5
MD5 d50b03e1b57fef66c6db2216332fcd1b
BLAKE2b-256 1ca86fd10b2848e66d72b449cc605c7ca57b48c6b4d9207b08ce33a1602fb3d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.23-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.23-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 79ed71651218f27719c9f74c1bf596528dcc2f0a58c198d92a781a61975f93dd
MD5 d7897ecb8ced686e1512c49fd13c8111
BLAKE2b-256 91668b50cffd13a40391c4c0736c3146d93adef972c71bf50faec41905438de8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.23-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8d0df7899c4724ad0486be64bc3b102885403d9867ce3177f41434be8bd47ae2
MD5 04ebda9593662fb993a7c34fb7cdf918
BLAKE2b-256 d10df1d8b7af02f52cfa12ba7cfd16d9ea6056d754d4dd01e2d68a23c40cdd0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.23-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cbd8d6ee6562389e00722a50f6200f8671d8a00a3912ea95560887c4b1e9b287
MD5 949b60ec048cc93d2abf06b0af81b81e
BLAKE2b-256 35500ba7438eb6613b522d524ff2bada3ee08b1b32825a6ac24031cfa13363c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.23-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b38eaf57e0ad9bc097c24af970b56432878f1e3280aee939886f66cb59032b54
MD5 51714315e63a4d5a15ed45bbe91f4487
BLAKE2b-256 a0a3c33a5151dbf2f97e8cc6c602b80a169749422e360b73899fa15394af2695

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.23-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 aa6850f96c1403b5b14c95371d81598826b4be8c3cc8080552cb272441477b3e
MD5 7fa2160563001e34bc13b3048c71c09b
BLAKE2b-256 83c5c4a6ddb78d020c0890a8ac7d023769b7200895f2219f2f25b69497773111

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.23-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5bf62fbf5cf2eb33a1faf15f0ca7c0ab506697f3642164e03627834414f8d1fd
MD5 798ab89817ee54add2919fce01ac172e
BLAKE2b-256 1d438e363b6c373843ffdf631df939a25c1dacbce200db674e04921b82197a69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.23-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 cb2395227254ecea3099e52e6e8418578e60e099b2cc9beb44d1aca394c2b4b9
MD5 a90757696ca9e110dda5863cbaf930b7
BLAKE2b-256 07f24b074a3ddb265ddecece888de97098bf1c845123b154e90f2ff81433ceed

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