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

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.20-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.20-cp310-abi3-musllinux_1_2_aarch64.whl (8.2 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.20-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.20.tar.gz.

File metadata

  • Download URL: gamfit-0.1.20.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.20.tar.gz
Algorithm Hash digest
SHA256 42731a52217f21140558e552b62d37c76f6a061dfcffebb0cd113875138e3209
MD5 c9e1893c2e5c49a70d9c6aa968739271
BLAKE2b-256 d69d4865bab7c72abf0b4073be21bf513dc15fe6738b2b9461ffff9ed5992d05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.20-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.8 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.20-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ea6724abb3d7a3e767f84a35290ecfcadd918eea1a9d20695720852fe4aa54cf
MD5 74543dff3bc246ff736fe78c60bcde16
BLAKE2b-256 eb6a9b5a2a4a25386880a51f583567fa5cc68cd23409dd1a10caf374cd09aa2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.20-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 414ca2631dd0460918d966c3ff2094e5a4f39fd17e958b2ab64f3ca7b9d66629
MD5 9558338aa6d4e9937e1a1038c60640db
BLAKE2b-256 be75181452624f431a52baaec318229f780462c70366da890a2517611f06ff42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.20-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 dce9aa62cf62fed96c838cf4582f64fa4800aeff34678420a759f09febaf0b83
MD5 cefbb4b739e7ffb6519a5b01e333dc18
BLAKE2b-256 7cb50af46804ebec13c34302c31fe076d4a39aa0ac4fe6e56c852a4affb47a37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.20-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e50edf01f425383d217540d43d71791b61652f21b228dfa8214a373162b9e442
MD5 3b8ad95cabc9d4c3dfaf8d5f9cc57438
BLAKE2b-256 987886765e0d5340d9b701f50423665ea89a4a47c0072c2ecbc13c23b9e3980d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.20-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b01acb44dcf7b76245bd0be15724d724478042d4229d6fddf8c05878252acb67
MD5 a4a3755cf76484fb4646034695191fcb
BLAKE2b-256 1804f49c7ce3a7bf73c428df34e75de43f1ea3fc73c99bd29567cb0681daa4ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.20-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a271b996f8c5cbeb6711bc14de119870366de679460985c0cb1a38ca7e693e33
MD5 8828fb7e184051937bc55ebad116a69d
BLAKE2b-256 544a843ec2032227454b4431de70438caf68deda7d02ffd1ee68953b0985768f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.20-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ed71ff5aea980dc36c4a427a4c20f5dba69e25f0b2e69fc03c6178e804bad9f2
MD5 78560cb650e624680e0ada3cb0002f3c
BLAKE2b-256 266477373a921b2b5b7ff49d17e12c00d03222c84188f6b4cc1a35476fc7c112

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