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

Uploaded CPython 3.10+Windows x86-64

gamfit-0.1.37-cp310-abi3-musllinux_1_2_x86_64.whl (10.8 MB view details)

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

gamfit-0.1.37-cp310-abi3-musllinux_1_2_aarch64.whl (9.3 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

gamfit-0.1.37-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.5 MB view details)

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

gamfit-0.1.37-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

gamfit-0.1.37-cp310-abi3-macosx_11_0_arm64.whl (8.9 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

gamfit-0.1.37-cp310-abi3-macosx_10_12_x86_64.whl (10.2 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: gamfit-0.1.37.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.37.tar.gz
Algorithm Hash digest
SHA256 fffd1ed1a8ede04ea9be1ff337f080536afd65b7abee87f6224ea76abe9ea082
MD5 d8829fb02e553d68e9a76f31b5aa9c88
BLAKE2b-256 deca5cae732021825a592740b100d2af9a7f77f1f2d926f916735eb729928c10

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gamfit-0.1.37-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 11.2 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.37-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1aada440f0348a1ad5ed5cf6010cd792b6431fc2145626d9580798b021d3b957
MD5 2ce8b5d495026e92631449c66c2d7332
BLAKE2b-256 7dfe27e661b1afe2e8b08f9f9058ade3e857a54e9f42337eecbc39dbfd1d09bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.37-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3f5b0b1893aaf508e26b8c80c79f772c984adcdf521100b045d937e8ece7b4a2
MD5 dc332ac056c0ee820fd996e791c433f3
BLAKE2b-256 18de5ab65cc812c9b6be4fa1a7aa52f5f582edfdaa93cb9fcec225924d76eb09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.37-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c24927e904ca295eae64830baa04bc7a8639108910024b14564c4e1c6c11c761
MD5 1651d2005abaea1d50e2f63f0f5e2d95
BLAKE2b-256 76383e44f0a5ddbd63244ca59e7e59d7fa7c86b0909c2d0dc6d1c65dfe3d708d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.37-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea628db90c7a9995d6e5448e0f47b5dac9a1dd990337069a71b2e6cec9150732
MD5 0975dd0f9efa624802482534c8b347df
BLAKE2b-256 e96358b3b736804dc4c923d602821eaf858c981c94c050d7254ec1a860c76c37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.37-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c5a302b82b9f83e0f10a1051b8fe7cf129d82785d0cdbc57347e8b00cf481d90
MD5 8003daabd9074d0bce742cbcfff556cb
BLAKE2b-256 3d386789a929b612e399b9574c69ec52a028ce20be4c8a26b8ec371078566793

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.37-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 99c6aff18da614685623cae866e0ae0604ee26cd579e239029b216f621575fd7
MD5 2c974ebebf0ff2f5490028445d29fd11
BLAKE2b-256 65f406cd1f3f51afe34cee144203c27519e6b90866c8e0a9383fc3ad6eedd141

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gamfit-0.1.37-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9e3e951b533b29406e6d873a46d3cced955e84798fda3faa01c6cce204612756
MD5 81275fb85ff25cbf6d9f5263fb111415
BLAKE2b-256 6d315ffc322164c06042669be9eda775b7531493af80613ec9a8e18fbb7fb01a

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