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.40.tar.gz (2.7 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.40-cp310-abi3-win_amd64.whl (11.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.40-cp310-abi3-musllinux_1_2_x86_64.whl (11.2 MB view details)

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

gamfit-0.1.40-cp310-abi3-musllinux_1_2_aarch64.whl (9.7 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.40-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

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

gamfit-0.1.40-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gamfit-0.1.40-cp310-abi3-macosx_11_0_arm64.whl (9.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.40-cp310-abi3-macosx_10_12_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: gamfit-0.1.40.tar.gz
  • Upload date:
  • Size: 2.7 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.40.tar.gz
Algorithm Hash digest
SHA256 2ba7bb90c83a61d5517b56843ba5bff5230589af5d456dcd3b787e7c2ca4d74e
MD5 ff4284d0a154515aec8042be6ff6f766
BLAKE2b-256 1cd1add6dd8422cfde86122a1c0b18acf84f462c060a65a484e9dca570729009

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.40-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 11.4 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.40-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fa185d34302fddd5ae21a0b961f848809b8b9fbc3b0f53ef8e9128d1ba2c4fb5
MD5 c2cc17586fdbaa636076cb85317ebe79
BLAKE2b-256 8b34e7b6543a4fb052d60c805e547e05f3b63b47b0286cd5d4e5c733cdef0ae6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.40-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2449c46f93528e806810313c1b16d9c0f791af9e9417847eee2d45553b3c096f
MD5 31476c04d3b02b7110ca17b2d7a319c8
BLAKE2b-256 3f097473ae0b8aa5339fab28ae1d720d2af9951e7369bd332c0d86224b6998a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.40-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b787b2a39946f5184220b2753744e0382911e266f3707e36440fa0330c7bc364
MD5 c10261c0161694f7b022da5e171e3ec0
BLAKE2b-256 1c4998ac188e89c7b8586afdf459140da129e86033c922b8f14cc340cf4490b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.40-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf8cfeb43ef773b58ae2d54c8069d8abd2b32f55470c5a939940595d3ade0965
MD5 be3bffcddd2a67f964ae92501ec68582
BLAKE2b-256 0e455a308e24a3c7af181dc39003a2805913de04c842b348bf4413245fa08a64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.40-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1b4cece804a64fc9e3565246dedea8c1a811182a5d63b8f6fb5c2b2d8c40cb36
MD5 169fcc2839ae5c409156f5d918be215a
BLAKE2b-256 b45479f91b39104fa882ef03ee43e199ca01c87f281709f36d93f2b86a503318

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.40-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a05709f92a556863abae2e659f108c04500a89e3ffe67168922d9b8fabd7c94
MD5 5dec3dd1a6ee78384cdc362255e58d6a
BLAKE2b-256 5ec32f03bbede7ae1fcf3d4725ae616305c0d35253494f196554cfa83599d80a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.40-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4a0a3350bccfcdce5cbb327d9df0560a98b66ade43435ae03aa19e8c05baa583
MD5 8c8969fa1f8e0bcfaad2f4caebea965a
BLAKE2b-256 710d43d7cd865d50fbf9d300806bb2db59321d3dc4dd0511bd14c84573f0a551

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