Skip to content

check_scorer_lower_is_better

yohou.testing.scorer.check_scorer_lower_is_better(scorer)

Check lower_is_better convention matches scoring direction.

Validates that the lower_is_better tag is a boolean and that the tag's value is consistent with the scorer's actual behavior: for lower_is_better=True scorers, a perfect prediction should yield a score less than or equal to a noisy prediction; for lower_is_better=False scorers, the opposite.

Parameters

Name Type Description Default
scorer BaseScorer

Scorer instance

required

Raises

Type Description
AssertionError

If lower_is_better doesn't match expected convention

Source Code

Show/Hide source
def check_scorer_lower_is_better(scorer) -> None:
    """Check lower_is_better convention matches scoring direction.

    Validates that the ``lower_is_better`` tag is a boolean and that
    the tag's value is consistent with the scorer's actual behavior:
    for ``lower_is_better=True`` scorers, a perfect prediction should
    yield a score less than or equal to a noisy prediction; for
    ``lower_is_better=False`` scorers, the opposite.

    Parameters
    ----------
    scorer : BaseScorer
        Scorer instance

    Raises
    ------
    AssertionError
        If lower_is_better doesn't match expected convention

    """
    tags = scorer.__sklearn_tags__()
    lower_is_better = tags.scorer_tags.lower_is_better

    # Most error metrics have lower_is_better=True
    # Most score metrics (R², etc.) have lower_is_better=False
    assert isinstance(lower_is_better, bool), f"lower_is_better should be bool, got {type(lower_is_better)}"