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.39.tar.gz (2.7 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.39-cp310-abi3-win_amd64.whl (11.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.39-cp310-abi3-musllinux_1_2_x86_64.whl (11.2 MB view details)

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

gamfit-0.1.39-cp310-abi3-musllinux_1_2_aarch64.whl (9.7 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.39-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view details)

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

gamfit-0.1.39-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gamfit-0.1.39-cp310-abi3-macosx_11_0_arm64.whl (9.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.39-cp310-abi3-macosx_10_12_x86_64.whl (10.5 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: gamfit-0.1.39.tar.gz
  • Upload date:
  • Size: 2.7 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.39.tar.gz
Algorithm Hash digest
SHA256 9c0b56cc450f4eac4d5b84eb6a1899495153c202559175000ac0dd00ec3e8d88
MD5 a49a043d7b99fabddef51c9df57309d1
BLAKE2b-256 9a4c91540b090cf228ee3e2da4975049444b482180636861321ca05b194766e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.39-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 11.4 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.39-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fe56796efba995ff3377eb1a7b93ae5b3d6e1bac52858ba39e633434b2a72062
MD5 b41444a5f13936ee2c9ba5fdffbe1e47
BLAKE2b-256 5783893fc9d876ffcf032185a7a1351729216f668b8093af1b30ec36c7d78f0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.39-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dff9d59326d58f1af355ce68f48eb7936a9fe1711b4b991852458830d51cbbc6
MD5 ae122eab479713f29fa96b2038d9f669
BLAKE2b-256 72220502faad6ee8983f10b9bc26fdd6fa8dad27874d8bcdcb82412be94512bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.39-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 96a92f4efa3e1a14685a18f1dd8a6237e61b79edfc36323148374b3216d89c99
MD5 20148a3e46c09ec66524c6de35840e8c
BLAKE2b-256 57a080e219183d0e86ab0c370555340fcd8fd67cf654967ed8776dcc80a8a263

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.39-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5354a17bdf1c673414b99f29d2effe1b0049b68f48530e2a0796ccd950a7e44d
MD5 c32fff189e9e485fb0ae604229838dce
BLAKE2b-256 de565e5aa55ac585061d67a7be9087cde98122f257fcee7fc4247fc9fe6f7f30

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.39-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0d936afdb4e88e74c99e5137bff54b21d3a7997c02ccdba5c95a7585c5da7a20
MD5 dddd2c696c3eee35414f4f374675ef3b
BLAKE2b-256 02aca393139cba3b8c1d1021fb5f1e92271db6dd40ee59b12e25668333f7abd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.39-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 980165a34cc631990fd20d2885c2b204530fee6bfaaacd834dfc63e64d474efd
MD5 0799f8a1e5564e9015f2125f26807f21
BLAKE2b-256 8ccedab982dc6998d2129b58d2a55394fe75860a4650630ebe1aed23b85a9e75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.39-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1de7c73c01f7b65b6eba206b310fd8372936b1d5969faf1c491468eea96ac85c
MD5 1f9e1f9dae04348fe9181356028e3c6a
BLAKE2b-256 55e2a6b8b0e052f52fbf2d50b5274a49e4730a006e4f10d2f7217e5eb2fd231a

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