---
title: Group Fairness
description: >-
  Computes Demographic parity and Equal opportunity ratio for binary
  classification problems.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/classification/group_fairness'
---
# Group Fairness {#group-fairness}

## Module Interface {#module-interface}

### BinaryFairness {#binaryfairness}

### `class torchmetrics.classification.BinaryFairness(num_groups, task='all', threshold=0.5, ignore_index=None, validate_args=True, **kwargs)` {#torchmetrics.classification.BinaryFairness}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/group_fairness.py#L158-L326)

Computes [Demographic parity](http://www.fairmlbook.org/) and [Equal opportunity](https://arxiv.org/abs/1610.02413) ratio for binary classification problems.

Accepts the following input tensors:

*   `preds` (int or float tensor): `(N, ...)`. If preds is a floating point tensor with values outside \[0,1\] range we consider the input to be logits and will auto apply sigmoid per element. Additionally, we convert to int tensor with thresholding using the value in `threshold`.
    
*   `groups` (int tensor): `(N, ...)`. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    
*   `target` (int tensor): `(N, ...)`.
    

The additional dimensions are flatted along the batch dimension.

This class computes the ratio between positivity rates and true positives rates for different groups. If more than two groups are present, the disparity between the lowest and highest group is reported. A disparity between positivity rates indicates a potential violation of demographic parity, and between true positive rates indicates a potential violation of equal opportunity.

The lowest rate is divided by the highest, so a lower value means more discrimination against the numerator. In the results this is also indicated as the key of dict is {metric}\_{identifier\_low\_group}\_{identifier\_high\_group}.

Parameters:

*   **num\_groups** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – The number of groups.
    
*   **task** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'demographic_parity'`, `'equal_opportunity'`, `'all'`\]) – The task to compute. Can be either `demographic_parity` or `equal_opportunity` or `all`.
    
*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Threshold for transforming probability to binary {0,1} predictions.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Returns:

The metric returns a dict where the key identifies the metric and groups with the lowest and highest true positives rates as follows: {metric}\_\_{identifier\_low\_group}\_{identifier\_high\_group}. The value is a tensor with the disparity rate.

Example (preds is int tensor):

```python
>>> from torchmetrics.classification import BinaryFairness
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0, 1, 0, 1, 0, 1])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> metric = BinaryFairness(2)
>>> metric(preds, target, groups)
{'DP_0_1': tensor(0.), 'EO_0_1': tensor(0.)}
```

Example (preds is float tensor):

```python
>>> from torchmetrics.classification import BinaryFairness
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0.11, 0.84, 0.22, 0.73, 0.33, 0.92])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> metric = BinaryFairness(2)
>>> metric(preds, target, groups)
{'DP_0_1': tensor(0.), 'EO_0_1': tensor(0.)}
```

#### `plot(val=None, ax=None)` {#torchmetrics.classification.BinaryFairness.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/group_fairness.py#L286-L326)

Plot a single or multiple values from the metric.

Parameters:

*   **val** (`Union`\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)"), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence "(in Python v3.15)")\[[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\], [`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")\]) – Either a single result from calling metric.forward or metric.compute or a list of these results. If no value is provided, will automatically call metric.compute and plot that result.
    
*   **ax** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)")\]) – An matplotlib axis object. If provided will add plot to that axis
    

Return type:

[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple "(in Python v3.15)")\[[`Figure`](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure "(in Matplotlib v3.11.2)"), `Union`\[[`Axes`](https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes "(in Matplotlib v3.11.2)"), [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.5)")\]\]

Returns:

Figure object and Axes object

Raises:

[**ModuleNotFoundError**](https://docs.python.org/3/builtins/exceptions.html#ModuleNotFoundError "(in Python v3.15)") – If matplotlib is not installed

```python
>>> from torch import ones, rand, randint
>>> # Example plotting a single value
>>> from torchmetrics.classification import BinaryFairness
>>> metric = BinaryFairness(2)
>>> metric.update(rand(50), randint(2, (50,)), ones(50).long())
>>> fig_, ax_ = metric.plot()
```

[![../../\_images/group\_fairness-1.png](/docs/torchmetrics/1.9.0/static/_images/group_fairness-1.png)](/docs/torchmetrics/1.9.0/static/_images/group_fairness-1.png)

```python
>>> from torch import ones, rand, randint
>>> # Example plotting multiple values
>>> from torchmetrics.classification import BinaryFairness
>>> metric = BinaryFairness(2)
>>> values = [ ]
>>> for _ in range(10):
...     values.append(metric(rand(50), randint(2, (50,) ), ones(50).long()))
>>> fig_, ax_ = metric.plot(values)
```

[![../../\_images/group\_fairness-2.png](/docs/torchmetrics/1.9.0/static/_images/group_fairness-2.png)](/docs/torchmetrics/1.9.0/static/_images/group_fairness-2.png)

### BinaryGroupStatRates {#binarygroupstatrates}

### `class torchmetrics.classification.BinaryGroupStatRates(num_groups, threshold=0.5, ignore_index=None, validate_args=True, **kwargs)` {#torchmetrics.classification.BinaryGroupStatRates}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/classification/group_fairness.py#L60-L155)

Computes the true/false positives and true/false negatives rates for binary classification by group.

Related to [Type I and Type II errors](https://en.wikipedia.org/wiki/Type_I_and_type_II_errors).

Accepts the following input tensors:

*   `preds` (int or float tensor): `(N, ...)`. If preds is a floating point tensor with values outside \[0,1\] range we consider the input to be logits and will auto apply sigmoid per element. Additionally, we convert to int tensor with thresholding using the value in `threshold`.
    
*   `target` (int tensor): `(N, ...)`.
    
*   `groups` (int tensor): `(N, ...)`. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    

The additional dimensions are flatted along the batch dimension.

Parameters:

*   **num\_groups** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – The number of groups.
    
*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Threshold for transforming probability to binary {0,1} predictions.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    
*   **kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.15)")) – Additional keyword arguments, see [Advanced metric settings](/docs/torchmetrics/1.9.0/user-guide/overview.md#metric-kwargs) for more info.
    

Returns:

The metric returns a dict with a group identifier as key and a tensor with the tp, fp, tn and fn rates as value.

Example (preds is int tensor):

```python
>>> from torchmetrics.classification import BinaryGroupStatRates
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0, 1, 0, 1, 0, 1])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> metric = BinaryGroupStatRates(num_groups=2)
>>> metric(preds, target, groups)
{'group_0': tensor([0., 0., 1., 0.]), 'group_1': tensor([1., 0., 0., 0.])}
```

Example (preds is float tensor):

```python
>>> from torchmetrics.classification import BinaryGroupStatRates
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0.11, 0.84, 0.22, 0.73, 0.33, 0.92])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> metric = BinaryGroupStatRates(num_groups=2)
>>> metric(preds, target, groups)
{'group_0': tensor([0., 0., 1., 0.]), 'group_1': tensor([1., 0., 0., 0.])}
```

## Functional Interface {#functional-interface}

### binary_fairness {#binary-fairness}

### `torchmetrics.functional.classification.binary_fairness(preds, target, groups, task='all', threshold=0.5, ignore_index=None, validate_args=True)` {#torchmetrics.functional.classification.binary_fairness}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/classification/group_fairness.py#L326-L382)

Compute either [Demographic parity](http://www.fairmlbook.org/) and [Equal opportunity](https://arxiv.org/abs/1610.02413) ratio for binary classification problems.

This is done by setting the `task` argument to either `'demographic_parity'`, `'equal_opportunity'` or `all`. See the documentation of [`demographic_parity()`](#torchmetrics.functional.classification.demographic_parity "torchmetrics.functional.classification.demographic_parity") and [`equal_opportunity()`](#torchmetrics.functional.classification.equal_opportunity "torchmetrics.functional.classification.equal_opportunity") for the specific details of each argument influence and examples.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with predictions.
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with true labels (not required for demographic\_parity).
    
*   **groups** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with group identifiers. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    
*   **task** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal "(in Python v3.15)")\[`'demographic_parity'`, `'equal_opportunity'`, `'all'`\]) – The task to compute. Can be either `demographic_parity` or `equal_opportunity` or `all`.
    
*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Threshold for transforming probability to binary {0,1} predictions.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]

### demographic_parity {#demographic-parity}

### `torchmetrics.functional.classification.demographic_parity(preds, groups, threshold=0.5, ignore_index=None, validate_args=True)` {#torchmetrics.functional.classification.demographic_parity}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/classification/group_fairness.py#L177-L240)

[Demographic parity](http://www.fairmlbook.org/) compares the positivity rates between all groups.

If more than two groups are present, the disparity between the lowest and highest group is reported. The lowest positivity rate is divided by the highest, so a lower value means more discrimination against the numerator. In the results this is also indicated as the key of dict is DP\_{identifier\_low\_group}\_{identifier\_high\_group}.

```math
\text{DP} = \dfrac{\min_a PR_a}{\max_a PR_a}.
```

where $`\text{PR}`$ represents the positivity rate for group $`\text{a}`$.

Accepts the following input tensors:

*   `preds` (int or float tensor): `(N, ...)`. If preds is a floating point tensor with values outside \[0,1\] range we consider the input to be logits and will auto apply sigmoid per element. Additionally, we convert to int tensor with thresholding using the value in `threshold`.
    
*   `groups` (int tensor): `(N, ...)`. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    
*   `target` (int tensor): `(N, ...)`.
    

The additional dimensions are flatted along the batch dimension.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with predictions.
    
*   **groups** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with group identifiers. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    
*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Threshold for transforming probability to binary {0,1} predictions.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]

Returns:

The metric returns a dict where the key identifies the group with the lowest and highest positivity rates as follows: DP\_{identifier\_low\_group}\_{identifier\_high\_group}. The value is a tensor with the DP rate.

Example (preds is int tensor):

```python
>>> from torchmetrics.functional.classification import demographic_parity
>>> preds = torch.tensor([0, 1, 0, 1, 0, 1])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> demographic_parity(preds, groups)
{'DP_0_1': tensor(0.)}
```

Example (preds is float tensor):

```python
>>> from torchmetrics.functional.classification import demographic_parity
>>> preds = torch.tensor([0.11, 0.84, 0.22, 0.73, 0.33, 0.92])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> demographic_parity(preds, groups)
{'DP_0_1': tensor(0.)}
```

### equal_opportunity {#equal-opportunity}

### `torchmetrics.functional.classification.equal_opportunity(preds, target, groups, threshold=0.5, ignore_index=None, validate_args=True)` {#torchmetrics.functional.classification.equal_opportunity}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/classification/group_fairness.py#L258-L323)

[Equal opportunity](https://arxiv.org/abs/1610.02413) compares the true positive rates between all groups.

If more than two groups are present, the disparity between the lowest and highest group is reported. The lowest true positive rate is divided by the highest, so a lower value means more discrimination against the numerator. In the results this is also indicated as the key of dict is EO\_{identifier\_low\_group}\_{identifier\_high\_group}.

```math
\text{DP} = \dfrac{\min_a TPR_a}{\max_a TPR_a}.
```

where $`\text{TPR}`$ represents the true positives rate for group $`\text{a}`$.

Accepts the following input tensors:

*   `preds` (int or float tensor): `(N, ...)`. If preds is a floating point tensor with values outside \[0,1\] range we consider the input to be logits and will auto apply sigmoid per element. Additionally, we convert to int tensor with thresholding using the value in `threshold`.
    
*   `target` (int tensor): `(N, ...)`.
    
*   `groups` (int tensor): `(N, ...)`. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    

The additional dimensions are flatted along the batch dimension.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with predictions.
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with true labels.
    
*   **groups** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with group identifiers. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    
*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Threshold for transforming probability to binary {0,1} predictions.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]

Returns:

The metric returns a dict where the key identifies the group with the lowest and highest true positives rates as follows: EO\_{identifier\_low\_group}\_{identifier\_high\_group}. The value is a tensor with the EO rate.

Example (preds is int tensor):

```python
>>> from torchmetrics.functional.classification import equal_opportunity
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0, 1, 0, 1, 0, 1])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> equal_opportunity(preds, target, groups)
{'EO_0_1': tensor(0.)}
```

Example (preds is float tensor):

```python
>>> from torchmetrics.functional.classification import equal_opportunity
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0.11, 0.84, 0.22, 0.73, 0.33, 0.92])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> equal_opportunity(preds, target, groups)
{'EO_0_1': tensor(0.)}
```

### binary_groups_stat_rates {#binary-groups-stat-rates}

### `torchmetrics.functional.classification.binary_groups_stat_rates(preds, target, groups, num_groups, threshold=0.5, ignore_index=None, validate_args=True)` {#torchmetrics.functional.classification.binary_groups_stat_rates}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/classification/group_fairness.py#L105-L161)

Compute the true/false positives and true/false negatives rates for binary classification by group.

Related to [Type I and Type II errors](https://en.wikipedia.org/wiki/Type_I_and_type_II_errors).

Accepts the following input tensors:

*   `preds` (int or float tensor): `(N, ...)`. If preds is a floating point tensor with values outside \[0,1\] range we consider the input to be logits and will auto apply sigmoid per element. Additionally, we convert to int tensor with thresholding using the value in `threshold`.
    
*   `target` (int tensor): `(N, ...)`.
    
*   `groups` (int tensor): `(N, ...)`. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    

The additional dimensions are flatted along the batch dimension.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with predictions.
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with true labels.
    
*   **groups** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Tensor with group identifiers. The group identifiers should be `0, 1, ..., (num_groups - 1)`.
    
*   **num\_groups** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – The number of groups.
    
*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Threshold for transforming probability to binary {0,1} predictions.
    
*   **ignore\_index** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")\]) – Specifies a target value that is ignored and does not contribute to the metric calculation
    
*   **validate\_args** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – bool indicating if input arguments and tensors should be validated for correctness. Set to `False` for faster computations.
    

Return type:

[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict "(in Python v3.15)")\[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)"), [`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")\]

Returns:

The metric returns a dict with a group identifier as key and a tensor with the tp, fp, tn and fn rates as value.

Example (preds is int tensor):

```python
>>> from torchmetrics.functional.classification import binary_groups_stat_rates
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0, 1, 0, 1, 0, 1])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> binary_groups_stat_rates(preds, target, groups, 2)
{'group_0': tensor([0., 0., 1., 0.]), 'group_1': tensor([1., 0., 0., 0.])}
```

Example (preds is float tensor):

```python
>>> from torchmetrics.functional.classification import binary_groups_stat_rates
>>> target = torch.tensor([0, 1, 0, 1, 0, 1])
>>> preds = torch.tensor([0.11, 0.84, 0.22, 0.73, 0.33, 0.92])
>>> groups = torch.tensor([0, 1, 0, 1, 0, 1])
>>> binary_groups_stat_rates(preds, target, groups, 2)
{'group_0': tensor([0., 0., 1., 0.]), 'group_1': tensor([1., 0., 0., 0.])}
```

---

**Navigation**

- Parent: [Classification](/docs/torchmetrics/1.9.0/classification.md)
