ClsMetric(
source_col,
target_cols_prefix,
function="accuracy",
name_suffix="",
use_multitarget=False,
use_probabilities=False,
)
Bases: DfMetric
Let's use calculate arbitrary classification
metrics as part of the DataframeAnalyzer(ResultAnalyzer).
Parameters
source_col: str
name of the column with the class
index or indexes (multitarget)
target_cols_prefix: str
starting name of the columns
containing the output of the model
function: str or dict, default "accuracy"
function to calculate the metric.
If str is given it must be a key of the cl_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.
name_suffix: str, default ""
can be used to add a str to the dict
output name (e.g. if the same metric should be applied
to multiple columns)
use_multitarget: bool, default false
allows to be more than one class present per sample
use_probabilities: bool, default false
if this is set true then the values are
not binarized before calculating the metric function
Source code in niceml/mlcomponents/resultanalyzers/dataframes/clsmetric.py
| def __init__(
self,
source_col: str,
target_cols_prefix: str,
function: Union[str, dict] = "accuracy",
name_suffix: str = "",
use_multitarget: bool = False,
use_probabilities: bool = False,
):
"""
Let's use calculate arbitrary classification
metrics as part of the DataframeAnalyzer(ResultAnalyzer).
Parameters
----------
source_col: str
name of the column with the class
index or indexes (multitarget)
target_cols_prefix: str
starting name of the columns
containing the output of the model
function: str or dict, default "accuracy"
function to calculate the metric.
If str is given it must be a key of the `cl_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.
name_suffix: str, default ""
can be used to add a str to the dict
output name (e.g. if the same metric should be applied
to multiple columns)
use_multitarget: bool, default false
allows to be more than one class present per sample
use_probabilities: bool, default false
if this is set true then the values are
not binarized before calculating the metric function
"""
self.source_col = source_col
self.target_cols_prefix = target_cols_prefix
self.multi_target = use_multitarget
self.name_suffix = name_suffix
self.use_probabilities = use_probabilities
if type(function) is str:
self.func_name = function
try:
self.function = cl_metric_dict[function]
except KeyError as e:
raise Exception(
f"Function with name {function} not "
f"supported! Available: {list(cl_metric_dict.keys())}"
) from e
else:
self.func_name = function["name"]
self.function = function["target"]
|
Functions