From c999fad06fb6db471ecf165003fa80c079b2bcc1 Mon Sep 17 00:00:00 2001 From: jirka <6035284+Borda@users.noreply.github.com> Date: Mon, 2 Feb 2026 09:18:23 +0100 Subject: [PATCH] Convert `supervision/metrics/precision.py` docstrings to doctests --- Co-authored-by: copilot-swe-agent[bot] <198982749+copilot@users.noreply.github.com> --- supervision/metrics/precision.py | 48 +++++++++++--------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/supervision/metrics/precision.py b/supervision/metrics/precision.py index 04b4e256..f7947edb 100644 --- a/supervision/metrics/precision.py +++ b/supervision/metrics/precision.py @@ -39,37 +39,23 @@ class Precision(Metric): Here, `TP` is the number of true positives (correct detections), and `FP` is the number of false positive detections (detected, but incorrectly). - Example: - ```python - import supervision as sv - from supervision.metrics import Precision - - predictions = sv.Detections(...) - targets = sv.Detections(...) - - precision_metric = Precision() - precision_result = precision_metric.update(predictions, targets).compute() - - print(precision_result.precision_at_50) - # 0.8099 - - print(precision_result) - # PrecisionResult: - # Metric target: MetricTarget.BOXES - # Averaging method: AveragingMethod.WEIGHTED - # P @ 50: 0.8099 - # P @ 75: 0.7969 - # P @ thresh: [0.80992 0.80905 0.80905 ...] - # IoU thresh: [0.5 0.55 0.6 ...] - # Precision per class: - # 0: [0.64706 0.64706 0.64706 ...] - # ... - # Small objects: ... - # Medium objects: ... - # Large objects: ... - - print(precision_result.small_objects.precision_at_50) - ``` + Examples: + >>> import numpy as np + >>> import supervision as sv + >>> from supervision.metrics import Precision + >>> predictions = sv.Detections( + ... xyxy=np.array([[0, 0, 10, 10]]), + ... class_id=np.array([0]), + ... confidence=np.array([0.9]) + ... ) + >>> targets = sv.Detections( + ... xyxy=np.array([[0, 0, 10, 10]]), + ... class_id=np.array([0]) + ... ) + >>> precision_metric = Precision() + >>> precision_result = precision_metric.update(predictions, targets).compute() + >>> round(float(precision_result.precision_at_50), 2) + 1.0 ![example_plot](\ https://media.roboflow.com/supervision-docs/metrics/precision_plot_example.png\