CrossValidationResult#

class superglm.CrossValidationResult(
fold_scores: DataFrame,
mean_scores: dict[str, float],
pooled_scores: dict[str, float],
std_scores: dict[str, float],
fold_indices: list[tuple[NDArray, NDArray]] | None = None,
curve_similarity: dict[str, Any] | None = None,
oof_predictions: NDArray | None = None,
estimators: list | None = None,
n_rows: int | None = None,
data_fingerprint: str | None = None,
splitter: str | None = None,
fingerprint_columns: tuple[str, ...] | None = None,
fit_mode: str | None = None,
fingerprint_version: int | None = None,
builtin_scores: tuple[str, ...] | None = None,
warm_start: bool | None = None,
fit_kwargs: dict[str, Any] | None = None,
refused_scores: tuple[tuple[int, str], ...] | None = None,
)#

Bases: object

Structured result from superglm.cross_validate().

Attributes:
fold_scoresDataFrame

One row per fold with columns: fold, n_train, n_test, fit_time_s, score_time_s, converged, n_iter, effective_df, plus one column per requested metric. Under fit_mode="fit_reml" a fold is converged only when both its smoothing-parameter selection and its final coefficient fit converged, and two more columns say how it got there: n_reml_iter (outer REML iterations) and warm_started. A "score refused" column appears when a fold’s held-out rows of positive weight had no predicted mean: it holds the reason, naming the rows by their position in the frame (a custom scorer that reads other rows, or changes their offsets, has them named among the rows it read), and that fold’s refused scores hold error_score.

mean_scoresdict

Equal-weight mean of each per-fold metric across folds. Built-in deviance and negative log-likelihood are normalized within each fold by the likelihood size the model’s declared weight_semantics implies: sum(sample_weight) under "frequency", the count of positive-weight validation rows under "prior". A refused score ("score refused") is not in it, whatever error_score it reads: the mean is of the folds scored, and cross_validate warns how many those are. The fold left out is one whose held-out rows have no predicted mean, so compare two runs’ means only on the same folds.

pooled_scoresdict

Supported overall pooled metrics, computed as ratio-of-sums rather than mean-of-fold-ratios, with the same denominator. Like mean_scores, they leave out the refused scores.

std_scoresdict

Standard deviation of each metric across folds, without the refused scores, as mean_scores.

fold_indiceslist[tuple[ndarray, ndarray]] or None

Per-fold (train_idx, test_idx) pairs from the CV splitter.

curve_similaritydict or None

Fold-by-fold term similarity diagnostics for comparable main effects. A correlation is NaN where two curves share fewer than two finite points or either is flat there, as for a term a fold’s penalty zeroes. A fold’s distance to the fold mean is NaN where it shares no point with another fold: the mean is taken where two or more folds have a value. None for a SuperLSS, whose fold curves superglm.editor.edit(model, cv=result) draws.

oof_predictionsndarray or None

Out-of-fold predictions (response scale; a SuperLSS’s conditional mean), same length as y. None unless return_oof=True. A SuperLSS’s held-out row of weight zero that cannot be priced reads NaN, as does a held-out row with no predicted mean (a SuperLSS’s: no value of a parameter). Vector means have shape (n, K) in the family’s component order; an unpriced vector row has NaN in all its components.

estimatorslist or None

Fitted model per fold. None unless return_estimators=True.

n_rowsint or None

Number of rows the folds index: the length of y.

data_fingerprintstr or None

SHA-256 of the rows the folds index: the row count, the frame library and the columns of X the model reads (fingerprint_columns), then the response, sample weights and offsets as little-endian float64, with unit weights standing in for sample_weight=None and zeros for offset=None. Equal fingerprints mean the same rows in the same order, which is what lets a later consumer, such as the editor’s Run CV, replay fold_indices on data it holds. The recipe reads values, never a library’s row hash or dtype text, so a pandas or polars upgrade does not change it.

splitterstr or None

Class name of the splitter that drew the folds.

fingerprint_columnstuple of str or None

The columns of X the fingerprint covers: the model’s declared features and interaction parents, or every column when the model takes its features from X. Other columns may hold anything. data_fingerprint is None when these columns cannot be hashed.

fit_mode{“fit”, “fit_reml”} or None

The fit method each fold was fitted with.

fingerprint_versionint or None

The version of the recipe data_fingerprint was made with. A fingerprint of another version cannot be compared with these rows. A version beside no data_fingerprint means the columns the model reads could not be fingerprinted, so no rows can be checked against the folds.

builtin_scorestuple of str or None

The score columns the built-in scorers computed, in scoring order. A column a callable wrote is not one of them, even one named "deviance", "nll" or "gini".

warm_startbool or None

The warm_start the folds were fitted with.

fit_kwargsdict or None

The fit_kwargs every fold’s fit received, copied.

refused_scorestuple of (int, str) or None

The (fold, score) cells whose score was refused ("score refused"), in fold order. A fold’s other scores stand.

``n_rows`` through ``refused_scores`` are ``None`` on a result made before
they were recorded; such a result without ``warm_start`` and
``fit_kwargs`` was fitted cold, with no extra fit arguments.
plot_terms_by_fold(
X: object,
*,
y: NDArray | None = None,
sample_weight: NDArray | None = None,
offset: NDArray | None = None,
terms: str | list[str] | None = None,
engine: str = 'plotly',
**kwargs,
)#

Plot fold-specific main effects using the shared comparison engine.

The stored folds are replayed on X and sample_weight, so they must be the data given to cross_validate(), in the same order. Their row count is always checked. Pass y (and offset, if the cross-validation had one) to check the rows themselves against data_fingerprint; without y a reordered X of the same length cannot be told apart.

Raises:
ValueError

If X or sample_weight has another row count than the folds index, or, when y is passed, the data differ from the data the folds were drawn on.