Skip to content

API Reference

Welcome to the infer-ci API reference documentation. This section provides detailed information about all available metrics, methods, and utilities.

Overview

The infer-ci package provides a unified interface for computing machine learning evaluation metrics with confidence intervals. All metrics support multiple methods for calculating confidence intervals, including bootstrap, analytical, and jackknife methods.

Core Interface

Metrics by Category

Classification Metrics

Metrics for evaluating classification models:

Regression Metrics

Metrics for evaluating regression models:

  • mae: Mean Absolute Error
  • mse: Mean Squared Error
  • rmse: Root Mean Squared Error
  • r2_score: Coefficient of Determination (R²)
  • mape: Mean Absolute Percentage Error
  • iou: Intersection over Union

Object Detection Metrics

Metrics for evaluating object detection models:

  • map: mean Average Precision @0.5:0.95
  • map50: mean Average Precision @0.5
  • precision: Detection Precision
  • recall: Detection Recall

Utilities

Quick Start

from infer_ci import MetricEvaluator

# Initialize evaluator
evaluator = MetricEvaluator()

# Evaluate a metric
value, ci = evaluator.evaluate(
    y_true=y_true,
    y_pred=y_pred,
    task='classification',
    metric='accuracy',
    method='wilson'
)

print(f"Accuracy: {value:.3f}")
print(f"95% CI: [{ci[0]:.3f}, {ci[1]:.3f}]")

Common Parameters

Most metric functions share these common parameters:

  • y_true (array-like): Ground truth labels/values
  • y_pred (array-like): Predicted labels/values
  • method (str): Method for computing CI (default: 'bootstrap_bca')
  • confidence_interval (float): Confidence level between 0 and 1 (default: 0.95)
  • n_resamples (int): Number of bootstrap resamples (default: 2000)
  • compute_ci (bool): Whether to compute confidence interval (default: True)
  • random_state (int, optional): Random seed for reproducibility

Available CI Methods

Bootstrap Methods

  • bootstrap_bca: Bootstrap Bias-Corrected and Accelerated (recommended)
  • bootstrap_percentile: Bootstrap Percentile method
  • bootstrap_basic: Basic Bootstrap method

Analytical Methods (Classification)

  • wilson: Wilson score interval
  • normal: Normal approximation
  • agresti_coull: Agresti-Coull interval
  • beta: Clopper-Pearson interval
  • jeffreys: Jeffreys interval
  • binom_test: Binomial test

Other Methods

  • jackknife: Jackknife resampling method
  • takahashi: Takahashi method for F1, precision, recall (multi-class)

Return Values

All metric functions return a tuple:

(metric_value, (lower_bound, upper_bound))
  • metric_value (float): The computed metric value
  • (lower_bound, upper_bound) (tuple): The confidence interval bounds