Skip to content

Metrics Helper Functions

The metrics module provides convenient helper functions for calculating statistical metrics. These functions provide a simple, direct interface for interactive use.

All metric implementations are internal - users should only use these helper functions.

Available Metrics

Accuracy Metrics

  • default_accuracy() - Calculate default accuracy for binary classification models
  • ead_accuracy() - Calculate Exposure at Default (EAD) accuracy
  • hosmer_lemeshow() - Perform Hosmer-Lemeshow goodness-of-fit test
  • jeffreys_test() - Perform Jeffreys Bayesian calibration test
  • rmse() - Calculate Root Mean Squared Error for predicted vs observed values

Discrimination Metrics

  • auc() - Calculate Area Under the ROC Curve
  • kolmogorov_smirnov() - Calculate Kolmogorov-Smirnov statistic for discrimination testing

Summary Statistics

  • mean() - Calculate mean values with optional segmentation
  • median() - Calculate median values with optional segmentation

Function Reference

metrics

Metrics package - Public helper functions for statistical calculations.

This package provides the main public interface for calculating statistical metrics. All metric classes are internal implementations and should not be used directly.

Example usage
from tnp_statistic_library.metrics import default_accuracy, mean, median

result = default_accuracy(
    data=df, data_format="record",
    prob_def="prob", default="default"
)

describe

describe(
    metric_type: str, data_format: str | None = None
) -> dict[str, Any]

Describe a metric's inputs and outputs.

Parameters:

Name Type Description Default
metric_type str

The metric type name (e.g., "auc").

required
data_format str | None

Optional format filter ("record" or "summary").

None

Returns:

Type Description
dict[str, Any]

Dict with metric_type, data_formats, and per-format metadata.

list_metrics

list_metrics() -> dict[str, list[str]]

Return metric types mapped to supported data formats.

options: show_source: false heading_level: 3 group_by_category: false members_order: source filters: - "!^*"