# Stratified Metrics

Often you want to get a more nuanced understanding of how your model performs on  specific slices of the labels. For example, in a self driving use case, you might want to understand how you perform on near vs far objects. Or you might have a fish-eye camera and what to understand how your model performs as objects approach the edge of the image.&#x20;

With stratified metrics, you can filter the metrics view based on per-label attributes, looking at a specific 'stratum' of your label set. For example, if you attach an attribute called “range,” you can evaluate performance on just large or small labels independently.

### Object Level Metadata Metrics Filtering

To enable label attributes metrics filtering, you can specify object metadata schema for the dataset or inference set using [`update_dataset_object_metadata_schema`](https://aquarium-not-pypi.web.app/aquariumlearning/docs/#aquariumlearning.Client.update_dataset_object_metadata_schema). For example,

```python
import aquariumlearning as al

al_client = al.Client()
al_client.set_credentials(api_key=API_KEY)

schema_fields = [
    {"name": "width_bucket", "type": "STRING"},
    {"name": "width", "type": "FLOAT"}
]
al_client.update_dataset_object_metadata_schema(<PROJECT>, <DATASET>, schema_fields)
```

Then, use the "Object Level Filters" option to select the attribute and enter a value (ie `medium`) or numeric range (ie `<10`, `<=10`, `=10`,`>=10`, `>10`).&#x20;

![](/files/DwTPnXZVaSjyK4JLtkw7)

### Example Usage (Deprecated)

```python
stratified_metrics_definitions = [
    al.StratifiedMetricsDefinition(
        name='range_bucket',
        ordered_values=['0-10', '10-20', '20-30', '30-40', '40-50', '50+']
    )
]

...

range_bucket = get_cuboid_range_bucket((0,0,0), label['position'])
frame.add_label_3d_cuboid(user_attrs={'range_bucket': range_bucket}, **label)

...

range_bucket = get_cuboid_range_bucket((0,0,0), inference['position'])
inf_frame.add_inference_3d_cuboid(user_attrs={'range_bucket': range_bucket}, **inference)

...

al_client.create_project(
    aquarium_project, 
    label_class_map, 
    stratified_metrics=stratified_metrics_definitions
)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://legacy-docs.aquariumlearning.com/aquarium/concepts/custom-metrics/stratified-metrics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
