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.272

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.272
File Size Uploaded
gamfit-0.1.272.tar.gz 16.4 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for gamfit 0.1.272
File
gamfit-0.1.272-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details
gamfit-0.1.272-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.272-cp314-cp314t-musllinux_1_2_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64 Details
gamfit-0.1.272-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.272-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.272-cp314-cp314t-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 Details
gamfit-0.1.272-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.272-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
gamfit-0.1.272-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
gamfit-0.1.272-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
gamfit-0.1.272-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.272-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
gamfit-0.1.272-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
gamfit-0.1.272-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 611.8 MB

Release files / gamfit-0.1.272.tar.gz

Download URL gamfit-0.1.272.tar.gz
Size 16.4 MB
Tags Source
SHA-256 checksum
How to use checksums
5624ff687f56bc8bf4dfd5f1ea2baeb1f7633361487c8ee6b5c309103ec8f5fc
BLAKE2b-256 checksum
How to use checksums
9f78745ae3d0516a233d1ba99df4a5e4897a71af288ef72a1983ab4c3b6b010d
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.272-cp314-cp314t-win_amd64.whl

Download URL gamfit-0.1.272-cp314-cp314t-win_amd64.whl
Size 47.8 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
dc99db8f790a39e2a8fc6e3990311f639c3e1bd4ba8bdcf95c1a6b690c280773
BLAKE2b-256 checksum
How to use checksums
df571b4dca8da4cd235481fb4fa67a80084faa7216e9144ca0a8cb88df81ed9f
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.272-cp314-cp314t-musllinux_1_2_x86_64.whl

Download URL gamfit-0.1.272-cp314-cp314t-musllinux_1_2_x86_64.whl
Size 44.5 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
475acd14565a53b15795fbc46d66ace1f4e16376b916b85e6fbc89df47f83f62
BLAKE2b-256 checksum
How to use checksums
6a13f100bdf5c7fcda52889b81a6c9306ce5c61b15d7c9f720378344649c9434
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.272-cp314-cp314t-musllinux_1_2_aarch64.whl

Download URL gamfit-0.1.272-cp314-cp314t-musllinux_1_2_aarch64.whl
Size 40.0 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
2e83e1f6f827fbf99a6ab88f2ae592abb11e9e4ae3f9dfa7b1fa9b51281a4b9d
BLAKE2b-256 checksum
How to use checksums
547eeb4f66f65c0ee8a80ef29b82b855e308ccb963f3610f042dbb712dd9c736
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.272-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gamfit-0.1.272-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 44.5 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
d63bcf64ddd179fc89fe870c6a4e4acf19948a19d93b039723eb239657a53273
BLAKE2b-256 checksum
How to use checksums
9a1431664ffdc6c05ddd6463e85e4cba24be1a64eb41f5c2fb03a054cc2d7689
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.272-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL gamfit-0.1.272-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 39.9 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
5a7c79e102596ac6d8b91a10b24e69b1b17104b36b14bca8588a8d61607301bd
BLAKE2b-256 checksum
How to use checksums
d27bdc4a2c74ae424485589fc49e275159939b7d18b80fb431618a6cd962c937
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.272-cp314-cp314t-macosx_11_0_arm64.whl

Download URL gamfit-0.1.272-cp314-cp314t-macosx_11_0_arm64.whl
Size 38.5 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
82a542d9efc97275a13e9bbb937fbf4710fa82a6358b5496873f6245f80fc907
BLAKE2b-256 checksum
How to use checksums
854402d675437ddcc2eb305ebca5b0b075620bb962543d94d68b959270ce81fa
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.272-cp314-cp314t-macosx_10_12_x86_64.whl

Download URL gamfit-0.1.272-cp314-cp314t-macosx_10_12_x86_64.whl
Size 42.6 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d157e822e0b3c52af113d55fdc324cb557e43368ddf6ee24f1380d2207d379c4
BLAKE2b-256 checksum
How to use checksums
6820a5cc4c27fb2d1954888977ed1c88bc0ef4650350d164d5ec6ea82601ae34
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.272-cp310-abi3-win_amd64.whl

Download URL gamfit-0.1.272-cp310-abi3-win_amd64.whl
Size 47.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
db603dbc6102242f05c5096255707c08758661155831accfbe0afa2c2e5aab8c
BLAKE2b-256 checksum
How to use checksums
0db4d34adf72ba20d439484281b356e61e55b2011bd9f3ee2104e5e7285c73d1
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.272-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL gamfit-0.1.272-cp310-abi3-musllinux_1_2_x86_64.whl
Size 44.5 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
46b790d9d4d2fca6a75fe66eb744669d2ef35391a19841097ab1407d06e3f44c
BLAKE2b-256 checksum
How to use checksums
4dab554572057124e3f4a0bae949f23c8a761afe84419541edee5a7b46c8dee8
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.272-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL gamfit-0.1.272-cp310-abi3-musllinux_1_2_aarch64.whl
Size 40.1 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
c6d3313612b3ad3e9419c7b1e64cc646db414728c2494fd3e3605d06b3ede40f
BLAKE2b-256 checksum
How to use checksums
50f723045f2f17bd7940ce9fa0a3b04f96096f53c3e2b97a6663dbfb747d0b15
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.272-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gamfit-0.1.272-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 44.5 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
7f93b4483c540a1d26de2d4c0f373f163924750f557c91be95c716c4108cc28d
BLAKE2b-256 checksum
How to use checksums
f094d482e3e0f8ed4dc77c78d328329a2586d894dc4b72219bbaca4817d8540e
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.272-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL gamfit-0.1.272-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 39.9 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
db5fff12e2631849a946eca06a48e982ea2f7eb484514dcca6dc125733780ea2
BLAKE2b-256 checksum
How to use checksums
323776568f3e100805a155a4c69ccdee36774fb87a33f9c67329a3dc7528dd36
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.272-cp310-abi3-macosx_11_0_arm64.whl

Download URL gamfit-0.1.272-cp310-abi3-macosx_11_0_arm64.whl
Size 38.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
049ab881118a4e5fa3425fa91ed54bc6db77691075912d219747d6b2c596015b
BLAKE2b-256 checksum
How to use checksums
a1eef4475a6796bf2c9aa66d963ba742016ab3fb3bd42dedeae2c791388bf546
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.272-cp310-abi3-macosx_10_12_x86_64.whl

Download URL gamfit-0.1.272-cp310-abi3-macosx_10_12_x86_64.whl
Size 42.5 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
780f00265752921b667c48bedfa0c17fc330a4ab69292280311d8133837debdc
BLAKE2b-256 checksum
How to use checksums
b25ec0d0e1eeda41607f65f9c595998a0db44092fcca18bc7e4076b9cf821923
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.272 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