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.29.tar.gz (2.6 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.29-cp310-abi3-win_amd64.whl (10.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.29-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.29.tar.gz.

File metadata

  • Download URL: gamfit-0.1.29.tar.gz
  • Upload date:
  • Size: 2.6 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.29.tar.gz
Algorithm Hash digest
SHA256 f0d23daf4e871a1fbedf9c89f0266f6d8ec95c666f6b804675ef21fb99658b03
MD5 98f7aeb15c52778c1adaff7ce9b5f174
BLAKE2b-256 518ffcafbf3bd57a5b532415bc88674f48f75b3296ca8410c9f91d17cfa6795e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.29-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.29-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7f121059dc0b042f0a7353a744751af617489c21eb63f2a07ebd8378b6a8024c
MD5 3a4c9879fa5ea59bb256e46912444528
BLAKE2b-256 554e9cf309c2283fcbbb4b4fbae5249f1b613199fa63fbcc76f56aa52b8a1296

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.29-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c5350c52d9f141b55c2b97166f961c92aadb3f25c4f06a4d3731e8e7c6afd3c8
MD5 8bec02363b2feecfa666846dcbed155b
BLAKE2b-256 5645be4cc21a512dea205f7f8c8f36fa0fc6d3b4691d0aa8e2a9cecac3293960

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.29-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7333f29b41c00f55cd09feb5430b3ebd9c9cc09327f91d799367b86672c9f816
MD5 eede57e35c4ecbbeedc3b4cf6f9be6e9
BLAKE2b-256 14a06989298597933c8f99f3f1882f7481b22a47f630955d5b4a14b249a80733

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.29-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b6febfa92fd217007dcb679b8e09a8f2c733797953ea4b020248b19cfabbe90
MD5 af8524b1e42791839860201a07363c93
BLAKE2b-256 89a79c4ef8e2e4cf5b742fc8fe3c7ccdf4cb69b936c88670594989bfde1ad1ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.29-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7264e5bb26b0bd353d4b4245832d67f7468503b7e9541e0f7e86dd0fbb62b0ba
MD5 f577b02170fb54cf0d33a5bde3f81f1f
BLAKE2b-256 a3bbc130dfe1b478d1b59559254cb6dee2b3cbf8da8a1ab56210257be390fae1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.29-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3cac36bfbf501d793f143d77b148b578001426fd6c52a9ffa10089e051664610
MD5 caee0e4253c565282051aa92368dc2ec
BLAKE2b-256 22da6f00a5245c30054628df3edf37bbbdb4838187b5c8f2188feaf593c87a32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.29-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6e9e960555bb471799a637fa0832732e820724364b275b481ff3eecf1adb2cb3
MD5 0982a2587d91f781b2a4c6c5e2238c84
BLAKE2b-256 eb221738c297e3a0e3e3802e86a697dc7ee4f386c77e468975897f242c3d1bad

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