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
- MetricEvaluator: Unified interface for evaluating all metrics
Metrics by Category
Classification Metrics
Metrics for evaluating classification models:
- accuracy_score: Overall classification accuracy
- precision_score: Positive Predictive Value (PPV)
- recall_score: True Positive Rate/Sensitivity (TPR)
- f1_score: F1 Score (harmonic mean of precision and recall)
- ppv_score: Positive Predictive Value
- tpr_score: True Positive Rate
- tnr_score: True Negative Rate/Specificity
- npv_score: Negative Predictive Value
- fpr_score: False Positive Rate
- roc_auc_score: ROC AUC Score
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
- classification_report_with_ci: Generate classification report with confidence intervals
- CI Methods: Available confidence interval calculation methods
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/valuesy_pred(array-like): Predicted labels/valuesmethod(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 methodbootstrap_basic: Basic Bootstrap method
Analytical Methods (Classification)
wilson: Wilson score intervalnormal: Normal approximationagresti_coull: Agresti-Coull intervalbeta: Clopper-Pearson intervaljeffreys: Jeffreys intervalbinom_test: Binomial test
Other Methods
jackknife: Jackknife resampling methodtakahashi: Takahashi method for F1, precision, recall (multi-class)
Return Values
All metric functions return a tuple:
metric_value(float): The computed metric value(lower_bound, upper_bound)(tuple): The confidence interval bounds