Skip to main content

gamfit

PyPI Python Docs License

gamfit fits generalized additive models from a formula, chooses every smoothing parameter by REML/LAML in one converged optimization, and returns posterior-mean predictions with credible bands and observation intervals, from a Rust engine.

uv add gamfit   # or: pip install gamfit

Wheels are published for Linux (x86_64, aarch64), macOS (x86_64, Apple silicon), and Windows. No Rust toolchain is required.

Example

import pandas as pd
import gamfit

# 133 rows: head acceleration of a crash-test dummy, milliseconds after impact.
mcycle = pd.read_csv("https://vincentarelbundock.github.io/Rdatasets/csv/MASS/mcycle.csv")

# The mean and the noise level are both smooth functions of time.
model = gamfit.fit(mcycle, "accel ~ s(times)", noise_formula="s(times)")

bands = model.predict(mcycle, interval=0.95, observation_interval=True)
print(bands[["posterior_mean", "posterior_mean_lower", "posterior_mean_upper",
             "observation_lower", "observation_upper"]].head())

mcycle location-scale fit: posterior mean, credible band and observation interval

Coming from pyGAM

  • Smoothness is estimated, not searched. REML/LAML picks every smoothing parameter, so there is no gridsearch() and no GCV. Against pyGAM's defaults gamfit wins 8, ties 28 and loses 13 of 49 held-out comparisons; the benchmarks list every loss.
  • Predictions carry their uncertainty. One predict call returns the posterior mean, a credible band for it and an observation interval (predictions).
  • The noise can be modelled too. noise_formula= fits a location-scale model like the one above, which pyGAM cannot express; on mcycle its 95% observation interval covers 97% of the data (tour).

Docs: https://gamfit.readthedocs.io/.

Scope

gamfit fits Gaussian, binomial (including Bernoulli marginal-slope), Poisson, negative-binomial, Gamma, Beta, Tweedie, and multinomial GLMs with smooth terms, random effects, bounded/constrained coefficients, location-scale extensions, survival likelihoods, and flexible/learnable links. Posterior sampling uses NUTS where supported, and a Gaussian Laplace approximation otherwise.

Manifold smooths handle predictor spaces that wrap or close: circles, cylinders, tori, and the sphere (intrinsic Wahba and spherical-harmonic kernels), plus periodic tensor products and boundary-conditioned B-splines. The Möbius example in the gallery is a 4π-periodic double-cover parameterization, not a twisted Möbius-strip basis.

rotating recovery of a trefoil knot, latent-free loop, wobbly cylinder, lumpy sphere, bumpy torus, and Möbius double-cover from noisy 3-D point clouds

Features

  • Polyharmonic / Duchon smooths combine magnitude, gradient, and curvature penalty operators on the same basis. P-spline and thin-plate smooths use their standard derivative penalties. Each penalized block has its own smoothing parameter.
  • Flexible link functions: flexible(base) adds a spline offset on a base link; blended(...) learns a mixture weight; sas and beta-logistic learn shape parameters.
  • Surface smooths in arbitrary dimension: thin-plate, Duchon (scale-free by default, hybrid with length_scale=...), and Matérn, with automatic knot placement.
  • Tensor-product and manifold smooths: te(...) / ti(...) B-spline tensors, periodic 1-D, cylinder / torus tensor products, intrinsic sphere (Wahba kernel or spherical harmonics), and boundary-conditioned B-splines.
  • Dispersion GAMLSS for Gamma, Beta, negative-binomial, and Tweedie via noise_formula=.
  • Per-axis anisotropy inside a single joint smooth.
  • Shape-constrained smooths: s(x, shape=monotone_increasing), convex, concave.
  • Difference smooths: by= factor smooths plus covariance-aware model.difference_smooth(...) contrasts with optional simultaneous bands.
  • Marginal-slope models that separate baseline risk from a calibrated score's effect, for Bernoulli and survival outcomes.
  • Survival in several likelihood modes (transformation, Weibull, location-scale, marginal-slope, latent-Gaussian frailty) plus competing-risks cumulative-incidence functions.
  • Response geometry for spherical and compositional outcomes via Fréchet-mean tangent-space GAMs.
  • Posterior sampling via NUTS where supported, Gaussian Laplace otherwise, behind one API; conformal prediction intervals via interval="conformal".

API examples

import numpy as np
import pandas as pd
import gamfit
from gamfit.sklearn import GAMRegressor, GAMClassifier

rng = np.random.default_rng(0)
train = pd.DataFrame({"x": rng.uniform(0, 10, 300), "site": rng.choice(["A", "B", "C"], 300)})
train["y"] = np.sin(train.x) + (train.site == "B") + rng.normal(0, 0.3, 300)
test = train.drop(columns="y").head(5)
X, y = train[["x"]], train["y"].to_numpy()

# Validate before you fit
gamfit.validate_formula(train, "y ~ s(x) + group(site)")
model = gamfit.fit(train, "y ~ s(x) + group(site)")

# Posterior sampling and mean bands
posterior = model.sample(train, seed=42)
bands = posterior.predict(test, level=0.95)

# Survival
age, bmi = rng.uniform(30, 80, 400), rng.normal(25, 4, 400)
t = 15 * rng.weibull(1.5, 400) * np.exp(-(age - 55) / 20 - (bmi - 25) / 10)
df = pd.DataFrame({"entry": 0.0, "exit": np.minimum(t, 25), "event": (t < 25) * 1.0, "age": age, "bmi": bmi})
gamfit.fit(df,
    "Surv(entry, exit, event) ~ s(age) + bmi + timewiggle(internal_knots=6)",
    survival_likelihood="transformation",
    baseline_target="weibull",
)

# scikit-learn
est = GAMRegressor(formula="y ~ s(x)")
est.fit(X, y)

# Diagnose, plot, report
model.diagnose(train).metrics
model.plot_terms()                        # each term's partial effect with bands
model.partial_dependence("s(x)").simultaneous_upper
model.report("report.html")

Public API

Symbol Purpose
gamfit.fit(data, formula, **kwargs) Fit a model.
gamfit.load(path) / gamfit.loads(bytes) Reload a saved model.
gamfit.validate_formula(data, formula, ...) Type-check a formula without fitting.
gamfit.build_info() Native extension build metadata.
gamfit.cuda.cuda_diagnostics() / gamfit.cuda.format_cuda_diagnostics() CUDA probe results.
gamfit.explain_error(exc) Human-readable hint for a gamfit exception.
gamfit.Model Fitted model: predict, summary, check, diagnose, plot, report, sample, save.
gamfit.results.SurvivalPrediction Per-row hazard / survival surface.
gamfit.results.CompetingRisksPrediction, competing_risks_cif Competing-risks CIF evaluation.
gamfit.MultinomialModel Multinomial-logit / softmax model.
gamfit.results.SamplingConfig, PosteriorSamples, PosteriorPredictive Posterior interface.
gamfit.ResponseGeometryModel, sphere_frechet_mean, simplex_frechet_mean, alr, clr, closure Response-geometry utilities.
gamfit.smooth.Duchon, Matern, BSpline, TensorBSpline, MeasureJet, Sphere Smooth descriptors for smooths= and torch.
gamfit.sklearn.GAMRegressor / GAMClassifier scikit-learn estimators.

Full reference: https://gamfit.readthedocs.io/en/latest/api-reference/.

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[cuda]"       # NVIDIA CUDA 12 wheel libraries on Linux x86_64
uv add "gamfit[all]"        # pandas + plot + sklearn extras
uv add torch                # PyTorch bridge dependency

GPU acceleration

CUDA support (cuBLAS / cuSOLVER / cuSPARSE) is built into the same wheel; there is no separate gamfit-gpu package. Install gamfit[cuda] on Linux x86_64 when you want PyPI's NVIDIA CUDA 12 runtime libraries instead of a system CUDA toolkit. Per-op dispatch thresholds are derived at probe time from measured GPU FP64 throughput, CPU FP64 throughput, and PCIe bandwidth, so small kernels stay on the CPU. Inspect the calibrated thresholds with gamfit.build_info()["cuda_diagnostics"] or gamfit.cuda.format_cuda_diagnostics().

The wheel uses the CUDA 12 ABI. If PyTorch has already mapped a complete CUDA stack, gamfit continues that same stack rather than preloading a second system toolkit. Without an existing stack it loads one complete system or packaged NVIDIA stack. The GPU probe refuses a partial or mixed mapped stack because CUDA context and library-handle ownership cannot be safely split across implementations.

License

AGPL-3.0-or-later. See LICENSE.

Metadata

Release files for gamfit 0.1.274

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gamfit 0.1.274
File Size Uploaded
gamfit-0.1.274.tar.gz 16.6 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for gamfit 0.1.274
File
gamfit-0.1.274-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
gamfit-0.1.274-cp314-cp314t-musllinux_1_2_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 Details
gamfit-0.1.274-cp314-cp314t-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64 Details
gamfit-0.1.274-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Details
gamfit-0.1.274-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64 Details
gamfit-0.1.274-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
gamfit-0.1.274-cp314-cp314t-macosx_10_12_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 Details
gamfit-0.1.274-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
gamfit-0.1.274-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
gamfit-0.1.274-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
gamfit-0.1.274-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
gamfit-0.1.274-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
gamfit-0.1.274-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
gamfit-0.1.274-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 614.3 MB

Release files / gamfit-0.1.274.tar.gz

Download URL gamfit-0.1.274.tar.gz
Size 16.6 MB
Tags Source
SHA-256 checksum
How to use checksums
48000d36b30bc6d05b6902c7d57f2fa94d42f7f99ce8c245ddf84fd41a8a6762
BLAKE2b-256 checksum
How to use checksums
f3bfd1b7508e1ef2f21503161eb73097abd9b436ce7fe8aedbc84a0401360e99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp314-cp314t-win_amd64.whl

Download URL gamfit-0.1.274-cp314-cp314t-win_amd64.whl
Size 48.0 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
1f96af9f69b9876de30a9f01eb16bdc54be8166f43d8d870a1da4bf598dc689f
BLAKE2b-256 checksum
How to use checksums
6ea1cf682900834cb65d49552d767def5e70407023af5de326c49d6fb67e7fbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp314-cp314t-musllinux_1_2_x86_64.whl

Download URL gamfit-0.1.274-cp314-cp314t-musllinux_1_2_x86_64.whl
Size 44.6 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
d2418b82e25f746b944829d640f8b274978aea31c2150c7303882ca41165606c
BLAKE2b-256 checksum
How to use checksums
74dd12a09fb602633f950be09de2cd787467870b370dd2bc0e6c5444ded73f63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp314-cp314t-musllinux_1_2_aarch64.whl

Download URL gamfit-0.1.274-cp314-cp314t-musllinux_1_2_aarch64.whl
Size 40.2 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
783b4279f5d520a0c27267c6a09f75ea5f00bbfe1654f36a92957df114dde9d9
BLAKE2b-256 checksum
How to use checksums
f70f9d3d7e95abf5a044304c34e471a7f36fe6a654035a91662aec3e01e524ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gamfit-0.1.274-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 44.7 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
bc31e9a87408a011c14349c3d7c12cece91a6abfc83fcaf301453004b3cee265
BLAKE2b-256 checksum
How to use checksums
10b7b3710c2e21a763f2c81317669af54d9164da8a1ad1d74aaf8442bebcfc53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL gamfit-0.1.274-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 40.0 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
117a01e8639f7ce85c609d6efa089de24b5cc7249e8df9a4725bc5880e3336c4
BLAKE2b-256 checksum
How to use checksums
c473386d51fe691640cbcb42d88d438d4b158b6fabe7add8741b2b0fcca9fa77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp314-cp314t-macosx_11_0_arm64.whl

Download URL gamfit-0.1.274-cp314-cp314t-macosx_11_0_arm64.whl
Size 38.6 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
24351e833878a62de3ff0ee2cd46bc65b9dd3accd1baace172b63b3f0fec40d8
BLAKE2b-256 checksum
How to use checksums
8a3a84985c253bcaee0ce00638d922e3d8c5ac3ac5ceacf788c774dd9d7e5386
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL gamfit-0.1.274-cp314-cp314t-macosx_10_12_x86_64.whl
Size 42.7 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
48c5adbd6087866e77a564b3f9afd5b95a2cdcee6cdc9a7e2262c32a3d0622e0
BLAKE2b-256 checksum
How to use checksums
899bf927418afaa2af3710cf1a9e640948836508437177da9cec9fe29dc2de66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp310-abi3-win_amd64.whl

Download URL gamfit-0.1.274-cp310-abi3-win_amd64.whl
Size 48.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
052694249e3fe38f9ecda5c6f6c8487a1e6ebea30870830ec3e587569c544cde
BLAKE2b-256 checksum
How to use checksums
3cf964c7220f86541860a91dc34f147dadfc3443cd4ae263c67ea2429867b83d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL gamfit-0.1.274-cp310-abi3-musllinux_1_2_x86_64.whl
Size 44.7 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
e0f505000585ba286d7a773c94a4759017ae522ce2db41fd7dcde6328108bd00
BLAKE2b-256 checksum
How to use checksums
3e57fcc49e3fa2e7ae5cb524a421f6295ea7ebc5b40bd0daff19f7f9fde4f106
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL gamfit-0.1.274-cp310-abi3-musllinux_1_2_aarch64.whl
Size 40.2 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
f848f1c8f8d6fd67e6d01e52e3d3cb25a908fdec0864c3d9fdd1c63d5f79227e
BLAKE2b-256 checksum
How to use checksums
f4c380ead808aaebdacf6e45b7fea7d8dce089f794c0dbbf609c9cbd97273d7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gamfit-0.1.274-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 44.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
6e6e6439d63c85aca18817d680c1801694a457de4733734033944428d8ccb6a4
BLAKE2b-256 checksum
How to use checksums
e00b7994fb994e7d23bd47e3c1f0293d97c46a3528c570bf10068238a7b4fc0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL gamfit-0.1.274-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 40.0 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
89d28034012be3c56d306d317819b699c912785ac18a2a4d656c8d00f52d4f0c
BLAKE2b-256 checksum
How to use checksums
1195fcee85a2eecca497cdf3a7c6c74260275315f5ed157a4fbcc77863d873f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp310-abi3-macosx_11_0_arm64.whl

Download URL gamfit-0.1.274-cp310-abi3-macosx_11_0_arm64.whl
Size 38.7 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
a9c9bfb0ffc9de4c00974e6c0d17cf9c6e37bfca93732356d400fdd4bd476612
BLAKE2b-256 checksum
How to use checksums
dd4cf8e53d343a3c729ff64c1d1b12068b5c331d0bbae19e901f3d25c17690c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / gamfit-0.1.274-cp310-abi3-macosx_10_12_x86_64.whl

Download URL gamfit-0.1.274-cp310-abi3-macosx_10_12_x86_64.whl
Size 42.6 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f52cb3841b000373de794201574d4fdf579418e001975c7d62c1fda70750ebfc
BLAKE2b-256 checksum
How to use checksums
8a6db0e45cf994d6e6039240f9a26600ca954079fbb0faa6630451f4da3c6c3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.1.274 This release

15 release files

0.1.222

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page