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

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.25-cp310-abi3-musllinux_1_2_x86_64.whl (9.6 MB view details)

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

gamfit-0.1.25-cp310-abi3-musllinux_1_2_aarch64.whl (8.3 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.25-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.25.tar.gz.

File metadata

  • Download URL: gamfit-0.1.25.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.25.tar.gz
Algorithm Hash digest
SHA256 23ead777467131a69ce208bbb23d2d621cea97f2d5047e2b861ee786c0a7ae98
MD5 b1378f83ba72db28aa22ef53f2066372
BLAKE2b-256 0d832a16f189261b2ba86a4cc4daefef9ea43d667c4a6417a304fc0429e156a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.25-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.9 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.25-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9f53009c3ac50618b9eccf3012ebf6d1967d20e690443d9f536b7757b463638c
MD5 27ac1b1bd57fe6249a82f47283767a73
BLAKE2b-256 45540cd71ab67e65d8a04fee1f02c3f5b435d1e074a55eed638038836e053f0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.25-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 49d9cde68fd71c472108c8626dfeb12d67c441fa571fed32f4b6ae95cadaac7e
MD5 46db77c9e8cec2641ba0fbe7ad76a307
BLAKE2b-256 fafcc10d398f7270a8efcb7107778ee57fa57d4bd22c6a6a2a20cb6f6c62bc6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.25-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0cfec982bd5be510c953a4cea68c845560207e24de9778f557e0ce3edc847f6b
MD5 214a3acd4049bc81a5ca05e0a10616be
BLAKE2b-256 da4653efd8ac9917a53e7b2616752140458325eb674f37ed837e5ebb853ba948

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.25-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ea78ab4f8b7f1dd8ddd64f600109af7365f1b9b174b390ece0ab173bf7fd75c
MD5 8c8bf511472383b6354797571bc44a36
BLAKE2b-256 d6df226b254c350db4eb948d0c18852c5673599628d9568b0ad388b8f14d5857

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.25-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0dbf12dfcbd674b1bd23cb90b5ed1bb9210bd81a9f94c975a786312adfa094d7
MD5 5929e18a77711af5ea5a7044f36d9eb3
BLAKE2b-256 5f0856c2507c6ce86c8a589eea30c2048ce7c9b141725c77f20b30eff8d61f61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.25-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 307da7feafc086cbcdc12301e59bf94d114389cce8506c8e830c78346834cb6d
MD5 69bd4146584c1be973fdaf9ab6514405
BLAKE2b-256 6cc437b5afdec7e206972c4078cb02fd28f2794422e996c8e9f5a76b8b79b36b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.25-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 169f194d74085dd35e78b718e76f020d3697f33e39b2dd7f71090c5410c009fd
MD5 8248b4824f7497e9a6b77ec4caa6380d
BLAKE2b-256 ad0e83c6f7fcc4a3cc991f597e71911d30e3fd18f5efebf754403a66448ddfe8

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