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

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.18-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.18-cp310-abi3-musllinux_1_2_aarch64.whl (8.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.18-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (9.1 MB view details)

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

gamfit-0.1.18-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gamfit-0.1.18-cp310-abi3-macosx_11_0_arm64.whl (7.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.18-cp310-abi3-macosx_10_12_x86_64.whl (8.8 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: gamfit-0.1.18.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.18.tar.gz
Algorithm Hash digest
SHA256 804336b7d2371f97842469a08ee447af74cc9ea450353b85716e3b05535e688f
MD5 1ee89600bde3f8a1d270269c7e977f60
BLAKE2b-256 47ee6fc4be4b0557ce1c871107396b61fb9ea21ab33bcfda914d41553d11699e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.18-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.18-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 3b83ffa2db2374ad8315e23194b2e16e685b95282ad7217437d8b753dceb9de4
MD5 5a7cc96b47092cd3dc0c91bae82fd861
BLAKE2b-256 b5ab15e6ccf03a68c7f4d841652f3ce005fc845fda86bf6bedf7799f8973bb3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.18-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a041945bd6aba87b21ccd3e1bf4033d08c3152f11d9161645c7db867b56fd124
MD5 226cb5cf9f0185f4ad3c2e0804158646
BLAKE2b-256 1a0f7fad787e40f90a4f85ee9dad501b55400f78688ae192f39fe0bb3a0ec37b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.18-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 ee7905ebf0190e74197aeb81fe5474d5a5c9d4c232a313bcad3a8c3be71bd554
MD5 9d13a6de1d7838c9df1ff1d3c25acbf6
BLAKE2b-256 11dbf4881848f44de8544f84d298399a7c878d66089e5cb8700e9b06c1259512

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.18-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2197e39ed55cf75946aba110f30174f653fa51ac63398307d57276bf01b9c652
MD5 10ca5f8e805fd6548d5515aec5147f50
BLAKE2b-256 3d1d368d495033296226104b42bb81481626c04ba8791f6cb243c765be0e2cff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.18-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 35a0f56296ceeb2966c0a6d28f34e16288fd5e733e1a117e45daf307993cce45
MD5 66687a1ff092fd288a13a18520461434
BLAKE2b-256 f54caaf2bc084aadaee854be187b8b910edcb86bc601a72f93561a9ab21f1aa5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.18-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bcf6ce8d935821e2af10a1510ebfa60b4a781baaa3987a4884bc63579ede9560
MD5 33bfaff705e5e26db7d4d432b20b39ba
BLAKE2b-256 9e79d0ce5b66a97adf13297de2b1236e43e33826bf393dd167f57889211fb16a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.18-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fa7e62cb0858435a86bd270ce6229adbb2287c6011cccfa96550c4522ae01196
MD5 248b11405c39175b3defd84995fbd130
BLAKE2b-256 82890a4f4bbf12fba0dfa4d850c862e5f5eacf97f337f22904f9219a3682676f

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