Skip to content

regmetric

regmetric

Module for regression metric

Classes

RegMetric

RegMetric(
    source_col,
    target_col,
    function_name,
    function,
    normalization_file="external_infos/normalization_info.yml",
)

Bases: DfMetric

Regression metric for dataframes

This class let's you calculate arbitrary regression metrics. It could be integrated as DfMetric in the DataframeAnalyzer(ResultAnalyzer).

Parameters

source_col: str column name in the dataframe where the ground truth is stored. target_col: str column name where the predictions are stored function: str or dict function to calculate the metric. If str is given it must be a key of the metric dict. Otherwise the given dict is initialized with init_object and additional the key name must be available to define the output name in the result dict. function_name: str Name of the function normalization_file: str, default "normalization_info.yml" This is a image_location relative to the experiment output folder. If a key exists with the same name as source_col the metric result is normalized and additionaly stored.

Source code in niceml/mlcomponents/resultanalyzers/dataframes/regmetric.py
def __init__(  # pylint: disable = too-many-arguments
    self,
    source_col: str,
    target_col: str,
    function_name: str,
    function: Union[str, Callable],
    normalization_file: str = "external_infos/normalization_info.yml",
):
    """
    This class let's you calculate arbitrary
    regression metrics. It could be integrated
    as DfMetric in the DataframeAnalyzer(ResultAnalyzer).

    Parameters
    ----------
    source_col: str
        column name in the dataframe where the ground truth is stored.
    target_col: str
        column name where the predictions are stored
    function: str or dict
        function to calculate the metric.
        If str is given it must be a key of the metric dict.
        Otherwise the given dict is initialized with `init_object`
         and additional the key `name`
        must be available to define the
        output name in the result dict.
    function_name: str
        Name of the function
    normalization_file: str, default "normalization_info.yml"
        This is a image_location relative to the experiment
        output folder. If a key exists with the same
        name as `source_col` the metric result is
        normalized and additionaly stored.
    """
    self.source_col = source_col
    self.target_col = target_col
    self.normalization_file: str = normalization_file
    self.func_name = function_name
    if isinstance(function, str):
        try:
            self.function = metric_dict[function]
        except KeyError as error:
            raise Exception(
                f"Function with name {function}"
                f" not supported! Available: {list(metric_dict.keys())}"
            ) from error
    else:
        self.function = function
Functions