load_gam()

Load a fitted GAM from a .npz archive created by save_gam.

Usage

Source

load_gam(path)

Reads back every piece of state that save_gam wrote — the formula, family, fitted coefficients and fit statistics, training design matrix and penalties, and each smooth’s basis state (restored via an internal _basis_from_state helper that reconstructs the original ~whittaker.smooths.base.SmoothBasis subclass without calling its constructor) — and assembles them into a fully fitted ~whittaker.gam.GAM. The returned model behaves exactly as it did before saving: predict(), summary(), plot(), and check() all work immediately, with no re-fitting or basis refitting performed.

Parameters

path: str or pathlib.Path
Path to the .npz file written by save_gam.

Returns

GAM
A fitted ~whittaker.gam.GAM ready for prediction and inference.

Examples

import numpy as np
import whittaker as wt
from whittaker.io import save_gam, load_gam

rng = np.random.default_rng(1)
x = np.sort(rng.uniform(0, 1, 150))
y = np.cos(3 * x) + rng.normal(scale=0.15, size=150)

model = wt.GAM("y ~ s(x)").fit({"x": x, "y": y})
save_gam(model, "gam_model.npz")

reloaded = load_gam("gam_model.npz")
reloaded.is_fitted
True