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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.28-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.28.tar.gz.

File metadata

  • Download URL: gamfit-0.1.28.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.28.tar.gz
Algorithm Hash digest
SHA256 c8bf061b1fb03ba810aa804740789207728d55b2318396fe1c958663d528bbd6
MD5 54dc1e3848e5891bb01f75c6fb41b820
BLAKE2b-256 ab06a4e46b506ad7623c04fcd30be5e87d31748315d5d90548952e04d64702c8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.28-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.28-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 54eb9eb4f53f271e359f6f245df748a2b92cf8b6bc8b1519cdea8f062a2d0d20
MD5 6041b4796e8f4032d7b64b31f948ee31
BLAKE2b-256 163e3c59cdc37d2a51b4dbba22535aa58b92206efbe44a937e0ae0e2ed08f671

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.28-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7146b80351112fd4943690cb9c199ae208617573c9d8374f3105e75c73a910e
MD5 73adfcf615054a24c07cc28391b8cb37
BLAKE2b-256 eccb28b41b840b779fae689cb6a32800c34bb1f8e22b0b7850fe59e85f31222c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.28-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c94bd6831bf600a83070364fe74d70ae62fa28cbe471d4b512cdaee690651e64
MD5 5e95b0fbe1c5f9d368dd2cd065a3021d
BLAKE2b-256 65a2d0e1d19d5b49a588e779cc35dd75b222ee4b0b11a0fd3e079befd14fa08f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.28-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fca0d8d5651d053875b3f4c244982df54b3f85463492334ef0d67f8c011fe760
MD5 3598ab2e03417ff7f97bef1d689e518d
BLAKE2b-256 e1da2a7ba327f7a509a4073c486148b14c3b3f7b97e3e56f025d64c1f6f4401e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.28-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 38cc5f69dc842eec9bdd5f91870c57f651a08674d3c8796661573e77b6f80f14
MD5 21db70e194baa6d414bfa34d4ccb1514
BLAKE2b-256 f76c79547bd532a5d7de49ac9cd06ce9752756cb19d4f2e168c82fcc4b72ef96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.28-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 04be0d4861e365f7ccb791ff34c75d0790c8257963c6ef27fe8c1f1f980f7c74
MD5 424ef6ad28bab8b525b8c1aea027f024
BLAKE2b-256 6e675c84d2561b56f13301a0cd13c44ed271959956351435bfd1c0f9d4377449

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.28-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 07f8bf154e732b7cd98e2fbfdebf096185038533cac23a48d3e8ff6c249289f2
MD5 ebcb3b984675ff7c0c42d57ae6d1ee23
BLAKE2b-256 ceedc13ef3d33b009003152aeddb92f64affc0807de00ae424ed912ad382f531

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