Skip to content

check_scorer_lower_is_better

yohou.testing.check_scorer_lower_is_better(scorer)

Check the lower_is_better tag is a boolean.

Validates only that the scorer exposes a boolean lower_is_better tag; it does not assert a particular value, so the caller is responsible for pinning the expected direction (e.g. via expected_tags) elsewhere.

Parameters

Name Type Description Default
scorer BaseScorer

Scorer instance

required

Raises

Type Description
AssertionError

If lower_is_better is not a boolean

Source Code

Source code in src/yohou/testing/scorer.py
def check_scorer_lower_is_better(scorer) -> None:
    """Check the ``lower_is_better`` tag is a boolean.

    Validates only that the scorer exposes a boolean ``lower_is_better`` tag;
    it does not assert a particular value, so the caller is responsible for
    pinning the expected direction (e.g. via ``expected_tags``) elsewhere.

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

    Raises
    ------
    AssertionError
        If lower_is_better is not a boolean

    """
    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)}"