Skip to content

check_scorer_panel_subselection

yohou.testing.scorer.check_scorer_panel_subselection(scorer, y_truth_panel, y_pred_panel, groups)

Check groups filtering works correctly.

Parameters

Name Type Description Default
scorer BaseScorer

Scorer instance

required
y_truth_panel DataFrame

Panel ground truth

required
y_pred_panel DataFrame

Panel predictions

required
groups list of str

Panel group names to filter

required

Raises

Type Description
AssertionError

If panel subselection fails

Source Code

Show/Hide source
def check_scorer_panel_subselection(
    scorer,
    y_truth_panel: pl.DataFrame,
    y_pred_panel: pl.DataFrame,
    groups: list[str],
) -> None:
    """Check groups filtering works correctly.

    Parameters
    ----------
    scorer : BaseScorer
        Scorer instance
    y_truth_panel : pl.DataFrame
        Panel ground truth
    y_pred_panel : pl.DataFrame
        Panel predictions
    groups : list of str
        Panel group names to filter

    Raises
    ------
    AssertionError
        If panel subselection fails

    """
    scorer_filtered = clone(scorer)
    scorer_filtered.set_params(groups=groups)

    try:
        score = scorer_filtered.score(y_truth_panel, y_pred_panel)
        assert isinstance(score, int | float | np.number), "Panel-filtered score should be numeric"
    except Exception as e:
        raise AssertionError(f"groups={groups} filtering failed: {e}") from e