fit_reml#
- SuperGLM.fit_reml(
- X: object,
- y: NDArray,
- sample_weight: NDArray | None = None,
- offset: NDArray | None = None,
- *,
- max_reml_iter: int | None = None,
- reml_tol: float | None = None,
- pirls_tol: float | None = None,
- max_pirls_iter: int | None = None,
- lambda2_init: float | Mapping[str, float] | None = None,
- interaction_mode: str = 'full',
- runtime_validation: str | bool | None = None,
- verbose: bool = False,
- w_correction_order: int = 1,
Fit with REML estimation of per-term smoothing parameters.
It optimizes a Laplace approximate REML objective over per-term smoothing parameters, and does not support a selection penalty: configure
selection_penalty=Noneor0.0. For sparse/group selection, usefit()orfit_path(); to let REML shrink spline null spaces, useselect=Trueon the spline terms.A Tweedie power within about 0.005 of 1, or further out for repeated responses, makes the dispersion profile multimodal; each solve then searches it globally, and a power too close to 1 for that search raises
superglm.NearPoissonDispersionError.- Parameters:
- Xpandas or eager Polars DataFrame
Feature matrix. Lazy frames must be collected before fitting.
- yarray-like
Response variable.
- sample_weightarray-like, optional
Observation weights, read under the model’s declared
weight_semantics. Under"prior"(the default) they state a precision,Var(Y_i | x_i) = phi * V(mu_i) / w_i; under"frequency"they are replication counts and integer weights are likelihood-equivalent to row replication once feature geometry is fixed. The contract sets the likelihood size the REML criterion profiles against, and so reaches the selected smoothing parameters as well as the dispersion. Weights affect fitting but do not enter the linear predictor or automatically scale the conditional mean.- offsetarray-like, optional
Offset term.
- max_reml_iterint, optional
Maximum REML outer iterations. Unset, it is 20. A fit that reaches the cap is returned with a
ConvergenceWarning,reml_diagnostics()["converged"]readsFalseand the summary says why. A cold exact fit with at least eight smoothing parameters and noRandomEffectorFactorSmoothterm may first run up to this many cached-W updates (a pre-solve);reml_diagnostics()["n_reml_iter"]counts the exact loop and["n_presolve_iter"]the pre-solve.- reml_tolfloat, optional
Stopping tolerance for the smoothing-parameter optimizer. Unset, it is 1e-9 for both Newton engines (exact and discrete); the discrete engine floors an explicit value at 1e-12, and candidate-grade fits (
interaction_mode="fast_candidate"andestimate_p’s power-search candidates) use 1e-6. The engines stop when the projected log-lambda gradient and the objective change both fall belowreml_tol * (1 + |objective|)over the active directions, or when Newton’s step on those directions is at mostmin(1e-3, 1e6 * reml_tol)in log lambda on an unmodified positive definite Hessian (termination_reason="newton_step_tolerance"), with the distance left, the step over one minus its contraction rate, within that bar. The exact engine takes the step and reads the rate from the next gradient, or from the preceding uncapped Newton step on the same free terms when no trial verifies this one. The discrete engine reads it from two successive steps on the same terms at a settled working model. A direction whose gradient and relative row curvature are both negligible is frozen where it stands, as recorded inreml_diagnostics()underprofile["reml_freeze_decision"]. A tolerance tighter than the line search can resolve ends astermination_reason="converged_at_precision"withconverged=True;line_search_failedwithconverged=Falseis reserved for undetermined stalls. Looser values (1e-6) are faster, but leave standard errors less determined well before predictions move.- pirls_tolfloat, optional
Inner PIRLS/IRLS convergence tolerance. Defaults to constructor
tol(1e-6). Pass explicitly to override.- max_pirls_iterint, optional
Maximum inner PIRLS iterations per REML step. Defaults to constructor
max_iter(100).- lambda2_initfloat or mapping, optional
Where the smoothing-parameter search starts. A mapping keyed by smoothing component (or group) name, such as an earlier fit’s
reml_diagnostics()["lambdas"], is a warm start: each named component begins there, so a refit on similar data (a cross-validation fold, a later year) takes fewer outer iterations. Values must be finite and positive; unnamed and fixed-policy components start as usual. A term whose components are only partly named starts cold, and an unknown key is ignored, each with aUserWarning. Coefficients are not carried over, and where the criterion is flat a different start can stop at a different point of the flat region. A float, or leaving it unset, keeps the engines’ own start.- interaction_mode{“full”, “fast_candidate”}
"full"runs ordinary REML."fast_candidate"caps REML outer updates for interaction models and then runs the normal final refit, intended for screening candidate interactions before a full final model fit.- runtime_validationoptional
Deprecated and ignored. It controlled a post-fit check that re-scored the training rows; the check has been retired, so any value only raises a
FutureWarning. Remove the argument.- verbosebool
Print progress.
- w_correction_orderint
Order of the W(rho) implicit-differentiation correction. 1 gives the exact objective and gradient with a modified-Newton outer Hessian (default, fast). 2 also includes the available exact d²W/dη² Hessian cross-terms from Wood (2011, Appendix C). Only affects the exact REML path.
- Returns:
- SuperGLM
The fitted model (self).