Metrics System¶

The metrics module provides built-in classification metrics and a flexible system for registering custom metrics.

Metric Functions¶

optimal_cutoffs.metrics.get(name: str)[source]¶

Get metric function by name.

optimal_cutoffs.metrics.register(name: str, func, *, maximize: bool = True, is_piecewise: bool = False, **kwargs)[source]¶

Register a new metric.

optimal_cutoffs.metrics.list_available()[source]¶

List all available metric names.

optimal_cutoffs.metrics.info(name: str)[source]¶

Get information about a metric.

Usage Example¶

from optimal_cutoffs import metrics

# List all available metrics
print(metrics.list_available())

# Get information about a metric
print(metrics.info('f1'))

# Register a custom metric
def custom_metric(tp, tn, fp, fn):
    return tp / (tp + fp + fn) if (tp + fp + fn) > 0 else 0

metrics.register('custom', custom_metric)

# Use the custom metric
metric_fn = metrics.get('custom')
score = metric_fn(10, 5, 2, 3)