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

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.19-cp310-abi3-musllinux_1_2_x86_64.whl (9.4 MB view details)

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

gamfit-0.1.19-cp310-abi3-musllinux_1_2_aarch64.whl (8.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.19-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.2 MB view details)

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

gamfit-0.1.19-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (8.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gamfit-0.1.19-cp310-abi3-macosx_11_0_arm64.whl (7.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.19-cp310-abi3-macosx_10_12_x86_64.whl (8.9 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: gamfit-0.1.19.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.19.tar.gz
Algorithm Hash digest
SHA256 d29585a40783bd4157d59478bb805e8cb13ab7234eb27a9d39685ad1af08ecef
MD5 36686d60ee2e2f1ee73d1706a25cc058
BLAKE2b-256 0cd9e888422f4ace40be6754acf8d10a2def6cea94815f58397adf67e9cd23fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.19-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.7 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.19-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fde6889a62733b8b5014fc679f57b9cb4afd89cd4e2c5b5e829626315557e328
MD5 99321f65f74f1c1e770670cbe1489da9
BLAKE2b-256 e3737b76035f037266539f0b734ca21a791761145ff9bd79d4f7a0e93c3668cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.19-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2795785463281d8231f59edcfafc70e5e6f5a044f53b696ca01122ed1db72cfa
MD5 7a89cbdc7dc5d786a7d2d332ceaf85ca
BLAKE2b-256 b043f56473f70605e804855b9fb4213dc3b99e1f14916aa0b9f443d53e2b92f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.19-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f21fedc7806eac541a81919a2dacffb5b22e975da296105541e237452b5b7781
MD5 58964e6c09c71547eb05f22d0fd41422
BLAKE2b-256 10c95d459a8369cadae83f78c9c5c6e1c357216dc29a135ff9356216acae7865

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.19-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 89a7a9da612be8be8662ab699ce113f98f13bc390446dfff30157ea74a615744
MD5 165f175497fbbba27b638499cd5c983f
BLAKE2b-256 1b5b3ad02609a8b289c26031bcd1e68864c77fe2a093c902c36c41dec246cdb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.19-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e4a1efa6f31bd0e85af83a3257af74835e3e42e739d19bf09989d56ea135c776
MD5 9a7ab51bf37a8aebd44957d1147e296f
BLAKE2b-256 98b97e63ee0b12bff7a17706f5fb668d463d1e0eb9e2493231991437fb8dfdb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.19-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e252e9b9aa7672040abd14440afbfe2a3e170ced9ef43169b4c6579700da37d
MD5 5623b92377ac0855427d72261e20288b
BLAKE2b-256 054a4c637d4dd30f68e3d1a987014e764f1dda1474c8f6329eb77947c8282096

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.19-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ea99d5c4adc8e873f4fb1c8d3cfef5c3398a686e536cd428293f6dc2f398ddd5
MD5 b4a037bfe6998316edb14cf4285db3f8
BLAKE2b-256 c9da50396f487b8b060182f515833937cb0a0fc2baeecbf85cd8b7e42b476642

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