> For the complete documentation index, see [llms.txt](https://docs.tensorleap.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/leap_binder/add_custom_metric.md).

# add\_custom\_metric

The purpose of the `leap_binder.`add\_custom\_metric function is to add a [custom metric ](/tensorleap-integration/writing-integration-code/custom-metrics.md)suited to your needs to the tensorleap platform.

```python
code_loader.leap_binder.add_custom_metric(
    function=Callable[..., tf.Tensor],
    name=str
)
```

<table><thead><tr><th width="158.46928201888204">Args</th><th></th></tr></thead><tbody><tr><td><code>function</code></td><td>A function that returns the required metrics</td></tr><tr><td><code>name</code></td><td><em>The name of the the metric</em></td></tr></tbody></table>

### Examples

#### Basic Usage

```python
import tensorflow as tf

def custom_metric_mean_distance(y_true, y_pred):
    rank = len(y_true.shape)
    axis = range(1, rank)
    diff = y_true - y_pred
    return tf.reduce_mean(diff, axis=axis)

leap_binder.add_custom_metric(custom_metric_mean_distance, "mean distance")
```

Full script usage can be found at [**Integration Script**](/tensorleap-integration/writing-integration-code.md#dataset-script).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/leap_binder/add_custom_metric.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
