Aggregate Comparison¶
Compare metric results across multiple models side-by-side — as a table or a grouped bar chart.
Install the metrics extra before using these APIs:
Compare Metric Results¶
Compute the same metric for each model, then aggregate the resulting scores in a table or a grouped bar chart.
import numpy as np
import supervision as sv
from supervision.metrics import (
F1Score,
aggregate_metric_results,
plot_aggregate_metric_results,
)
targets = sv.Detections(
xyxy=np.array([[0, 0, 10, 10]]),
class_id=np.array([0]),
)
model_a_predictions = sv.Detections(
xyxy=np.array([[0, 0, 10, 10]]),
class_id=np.array([0]),
confidence=np.array([0.9]),
)
model_b_predictions = sv.Detections(
xyxy=np.array([[3, 3, 10, 10]]),
class_id=np.array([0]),
confidence=np.array([0.9]),
)
metric_results = [
F1Score().update(model_a_predictions, targets).compute(),
F1Score().update(model_b_predictions, targets).compute(),
]
model_names = ["Model A", "Model B"]
comparison = aggregate_metric_results(metric_results, model_names=model_names)
print(comparison[["F1@50", "F1@75"]])
plot_aggregate_metric_results(
metric_results,
model_names=model_names,
show=True,
)
Functions¶
supervision.metrics.utils.aggregate.aggregate_metric_results(metric_results: list[MetricResult], *, model_names: list[str] | None = None, include_object_sizes: bool = False) -> pd.DataFrame
¶
Combine several :class:MetricResult objects into a single DataFrame.
Each row corresponds to one result (one model). All results must be of the
same concrete type (e.g. all :class:F1ScoreResult).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[MetricResult]
|
A list of metric results to aggregate. |
required |
|
list[str] | None
|
Optional display names for each result. When provided, the DataFrame index is set to these names. Must have the same length as metric_results. |
None
|
|
bool
|
When |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DataFrame
|
class: |
DataFrame
|
each metric value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the list is empty or model_names length does not match metric_results. |
TypeError
|
If the list contains mixed result types. |
Source code in src/supervision/metrics/utils/aggregate.py
supervision.metrics.utils.aggregate.plot_aggregate_metric_results(metric_results: list[MetricResult], *, model_names: list[str] | None = None, include_object_sizes: bool = False, show: bool = False) -> None
¶
Plot multiple :class:MetricResult objects on a single grouped bar chart.
Each group of bars corresponds to a metric label (e.g. "F1@50"), and
each bar within the group corresponds to one model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list[MetricResult]
|
A list of metric results to plot. |
required |
|
list[str] | None
|
Optional display names for each result (used in the
legend). When |
None
|
|
bool
|
When |
False
|
|
bool
|
When |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the list is empty, model_names length does not match metric_results, or results have mismatched plot details. |
TypeError
|
If the list contains mixed result types. |
Source code in src/supervision/metrics/utils/aggregate.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
Supporting Types¶
supervision.metrics.core.MetricResult
¶
Bases: ABC
Abstract base class shared by all metric result dataclasses.
Source code in src/supervision/metrics/core.py
supervision.metrics.core.PlotDetails
dataclass
¶
Container for bar-chart data returned by MetricResult._get_plot_details.
Attributes:
| Name | Type | Description |
|---|---|---|
labels |
list[str]
|
Bar labels (x-axis tick labels). |
values |
list[float]
|
Bar heights (metric values). |
colors |
list[str]
|
One hex color string per bar (e.g. |
title |
str
|
Chart title. |