Skip to content

make_scorer

yohou.metrics.make_scorer(name, **params)

Create a scorer instance with custom parameters.

Parameters

Name Type Description Default
name str

Name of the scorer (e.g., "mae", "coverage").

required
**params dict

Parameters passed to the scorer constructor.

{}

Returns

Type Description
BaseScorer

A configured scorer instance.

Raises

Type Description
ValueError

If the name is not in the registry.

Examples

>>> scorer = make_scorer("mae", aggregation_method=["stepwise", "vintagewise"])
>>> scorer.aggregation_method
['stepwise', 'vintagewise']

Source Code

Show/Hide source
def make_scorer(name: str, **params: Any) -> BaseScorer:
    """Create a scorer instance with custom parameters.

    Parameters
    ----------
    name : str
        Name of the scorer (e.g., ``"mae"``, ``"coverage"``).
    **params : dict
        Parameters passed to the scorer constructor.

    Returns
    -------
    BaseScorer
        A configured scorer instance.

    Raises
    ------
    ValueError
        If the name is not in the registry.

    Examples
    --------
    >>> scorer = make_scorer("mae", aggregation_method=["stepwise", "vintagewise"])
    >>> scorer.aggregation_method
    ['stepwise', 'vintagewise']

    """
    if name not in _SCORER_REGISTRY:
        available = sorted(_SCORER_REGISTRY.keys())
        raise ValueError(f"Unknown scorer {name!r}. Available: {available}")
    return _SCORER_REGISTRY[name](**params)