# Custom metrics

This guide will show you how to automatically add custom metrics to your model from code using the Python SDK.&#x20;

For more information on the syntax of custom metrics, check the [custom-metric-syntax](https://docs.aporia.com/api-reference/custom-metric-syntax "mention") documentation.

## Defining Custom Metrics

To add new custom metrics:

```python
conversion_rate = aporia.CustomMetric(
    "Conversion Rate",
    code="""
        count(filter="purchased=TRUE") / count()
    """,
)

model_revenue = aporia.CustomMetric(
    "Model Revenue",
    code="""
        sum(
            column="candidate_item_price",
            filter="purchased=TRUE AND ranking_index<=4"
        ) / count()*2
    """,
)
```

In this example, we're adding two new custom metrics - **conversion rate** and **model revenue**. To add the custom metrics to your model, pass them to the model object:

```python
model = aporia.Model(
    "My Model",
    type=aporia.ModelType.RANKING,
    versions=[model_version],
    segments=[platform_segment, country_segments],
    custom_metrics=[conversion_rate, model_revenue]
)
```
