MetricResults

class MetricResults(data: Mapping[MetricKeyType | str, float])[source]

Bases: Generic[MetricKeyType]

Results from computing metrics.

Initialize the result wrapper.

Methods Summary

get_metric(name)

Get the given metric from the results.

key_from_string(s)

Parse the metric key from a (un-normalized) string.

key_to_string(s)

Convert a key to a normalized key.

string_or_key_to_key(s)

Convert a key to a named tuple.

to_df()

Output the metrics as a pandas dataframe.

to_dict()

Extract a (potentially nested) JSON-compatible dictionary.

to_flat_dict()

Get the results as a flattened dictionary.

Methods Documentation

Parameters:

data (Mapping[MetricKeyType, float])

get_metric(name: str | MetricKeyType) float[source]

Get the given metric from the results.

Parameters:

name (str | MetricKeyType) – The name of the metric

Returns:

The value for the metric

Return type:

float

abstract classmethod key_from_string(s: str | None) MetricKeyType[source]

Parse the metric key from a (un-normalized) string.

Parameters:

s (str | None) – the metric key, or None to get the default key.

Returns:

the fully resolved key as a named tuple

Return type:

MetricKeyType

classmethod key_to_string(s: str | MetricKeyType | None) str[source]

Convert a key to a normalized key.

Parameters:

s (str | MetricKeyType | None)

Return type:

str

classmethod string_or_key_to_key(s: str | MetricKeyType | None) MetricKeyType[source]

Convert a key to a named tuple.

Parameters:

s (str | MetricKeyType | None)

Return type:

MetricKeyType

to_df() DataFrame[source]

Output the metrics as a pandas dataframe.

Return type:

DataFrame

to_dict() Mapping[str, Any][source]

Extract a (potentially nested) JSON-compatible dictionary.

Return type:

Mapping[str, Any]

to_flat_dict() Mapping[str, Any][source]

Get the results as a flattened dictionary.

Return type:

Mapping[str, Any]