cross_validate#
- superglm.cross_validate(
- model,
- X: object,
- y: NDArray,
- *,
- cv,
- sample_weight: NDArray | None = None,
- offset: NDArray | None = None,
- groups: NDArray | None = None,
- fit_mode: str = 'fit',
- scoring: str | Callable | Sequence[str | Callable] = ('deviance',),
- return_estimators: bool = False,
- return_oof: bool = False,
- error_score: float | str = nan,
Cross-validate a SuperGLM model with a pluggable splitter.
- Parameters:
- modelSuperGLM
An unfitted (or fitted) model. A fresh clone is created for each fold; the input model is never mutated.
- Xpandas or eager Polars DataFrame
Feature matrix.
- yarray-like
Response variable.
- cvsplitter
Object with a
.split(X, y, groups)method yielding(train_idx, test_idx)tuples. Any sklearn splitter works.- sample_weightarray-like, optional
Sliced per fold; splitters operate on the physical compact rows, and they are read under the model’s declared
weight_semantics. Under"frequency", integer values are likelihood-equivalent to literal row replication within a fixed train/validation partition and fixed feature geometry. Under"prior"they state a precision,Var(Y_i) = phi * V(mu_i) / w_i; a Tweedie fit additionally requires them finite and strictly positive.- offsetarray-like, optional
Offset term, sliced per fold.
- groupsarray-like, optional
Group labels forwarded to
cv.split().- fit_mode{“fit”, “fit_reml”}
Which fit method to call on each fold estimator.
- scoringstr, callable, or sequence thereof
Metrics to evaluate. Built-in:
"deviance","nll","gini". Built-in deviance and NLL divide their weighted totals by the likelihood size the declared contract implies:sum(sample_weight)under"frequency", the count of positive-weight rows under"prior". Gini remains a separately weighted ranking metric. Callables must followscorer(model, X, y, *, sample_weight, offset) -> float | dict.- return_estimatorsbool
If True, keep the fitted model from each fold.
- return_oofbool
If True, collect out-of-fold predictions.
- error_scorefloat or “raise”
Value to assign when a fold fails.
"raise"propagates the error.
- Returns:
- CrossValidationResult
Per-fold scores, mean/std aggregates, and optionally out-of-fold predictions and fitted estimators.