Skip to main content

lib.evaluator.evaluator

TorchMetrics-based evaluator driven by EvaluatorConfig.

TorchMetricEvaluator groups the configured metrics into TorchMetrics MetricCollections keyed by the data they need, then evaluates a pandas DataFrame against all of them in one pass.

TorchMetricEvaluator Objects​

class TorchMetricEvaluator()

Evaluate a pandas DataFrame against a config's metrics.

Metrics are organized into TorchMetrics MetricCollections by their column configuration, filter, and tensor dtypes, so every metric that wants the same data computes from one extraction.

__init__​

def __init__(config: EvaluatorConfig | dict[str, Any] | str | Path)

Initialize the evaluator.

Arguments:

  • config - An EvaluatorConfig, a dict in the same shape, or a path to a YAML config file.

Raises:

  • TypeError - If config is none of those.

evaluate​

def evaluate(df: pd.DataFrame) -> dict[str, Any]

Compute every configured metric over a DataFrame.

Each collection is updated, computed, and reset in turn, so metric state for all collections is never held at once.

Arguments:

  • df - The rows to evaluate.

Returns:

Metric name -> computed value.

compute​

def compute() -> dict[str, Any]

Compute every collection from its currently accumulated state.

Use this when collections were updated incrementally rather than through evaluate.

Returns:

Metric name -> computed value.

get_metric_names​

def get_metric_names() -> list[str]

List every metric name this evaluator will compute.

Returns:

The metric names, in collection order.

validate_dataset​

def validate_dataset(df: pd.DataFrame) -> None

Check that a DataFrame carries every column the metrics need.

Arguments:

  • df - The DataFrame to validate.

Raises:

  • ValueError - If any required column is missing, naming all of them.

get_required_columns​

def get_required_columns() -> set[str]

Collect every column the configured metrics read.

Returns:

The column names that must be present in the input data, including the config's segment columns.

get_column_mappings​

def get_column_mappings() -> list[ColumnMapping]

List the column mappings the configured metrics use.

Returns:

One mapping per collection that has one.

__repr__​

def __repr__() -> str

Render the evaluator's metric and collection counts.

create_evaluator​

def create_evaluator(
config: EvaluatorConfig | dict[str, Any] | str | Path
) -> TorchMetricEvaluator

Create a TorchMetricEvaluator.

Arguments:

  • config - An EvaluatorConfig, a dict in the same shape, or a path to a YAML config file.

Returns:

The initialized evaluator.