---
title: Critical Success Index (CSI)
description: Calculate critical success index (CSI).
canonical: >-
  https://lightning.ai/docs/torchmetrics/stable/regression/critical_success_index
---
# Critical Success Index (CSI) {#critical-success-index-csi}

## Module Interface {#module-interface}

### `class torchmetrics.regression.CriticalSuccessIndex(threshold, keep_sequence_dim=None, **kwargs)` {#torchmetrics.regression.CriticalSuccessIndex}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/regression/csi.py#L24-L112)

Calculate critical success index (CSI).

Critical success index (also known as the threat score) is a statistic used weather forecasting that measures forecast performance over inputs binarized at a specified threshold. It is defined as:

```math
\text{CSI} = \frac{\text{TP}}{\text{TP}+\text{FN}+\text{FP}}
```

Where $`\text{TP}`$, $`\text{FN}`$ and $`\text{FP}`$ represent the number of true positives, false negatives and false positives respectively after binarizing the input tensors.

Parameters:

*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Values above or equal to threshold are replaced with 1, below by 0
    
*   **keep\_sequence\_dim** ([`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)")\]) – Index of the sequence dimension if the inputs are sequences of images. If specified, the score will be calculated separately for each image in the sequence. If `None`, the score will be calculated across all dimensions.
    

Example

```python
>>> import torch
>>> from torchmetrics.regression import CriticalSuccessIndex
>>> x = torch.Tensor([[0.2, 0.7], [0.9, 0.3]])
>>> y = torch.Tensor([[0.4, 0.2], [0.8, 0.6]])
>>> csi = CriticalSuccessIndex(0.5)
>>> csi(x, y)
tensor(0.3333)
```

Example

```python
>>> import torch
>>> from torchmetrics.regression import CriticalSuccessIndex
>>> x = torch.Tensor([[[0.2, 0.7], [0.9, 0.3]], [[0.2, 0.7], [0.9, 0.3]]])
>>> y = torch.Tensor([[[0.4, 0.2], [0.8, 0.6]], [[0.4, 0.2], [0.8, 0.6]]])
>>> csi = CriticalSuccessIndex(0.5, keep_sequence_dim=0)
>>> csi(x, y)
tensor([0.3333, 0.3333])
```

## Functional Interface {#functional-interface}

### `torchmetrics.functional.regression.critical_success_index(preds, target, threshold, keep_sequence_dim=None)` {#torchmetrics.functional.regression.critical_success_index}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/functional/regression/csi.py#L77-L112)

Compute critical success index.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Predicted tensor
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – Ground truth tensor
    
*   **threshold** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Values above or equal to threshold are replaced with 1, below by 0
    
*   **keep\_sequence\_dim** ([`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)")\]) – Index of the sequence dimension if the inputs are sequences of images. If specified, the score will be calculated separately for each image in the sequence. If `None`, the score will be calculated across all dimensions.
    

Return type:

[`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")

Returns:

If `keep_sequence_dim` is specified, the metric returns a vector of with CSI scores for each image in the sequence. Otherwise, it returns a scalar tensor with the CSI score.

Example

```python
>>> import torch
>>> from torchmetrics.functional.regression import critical_success_index
>>> x = torch.Tensor([[0.2, 0.7], [0.9, 0.3]])
>>> y = torch.Tensor([[0.4, 0.2], [0.8, 0.6]])
>>> critical_success_index(x, y, 0.5)
tensor(0.3333)
```

Example

```python
>>> import torch
>>> from torchmetrics.functional.regression import critical_success_index
>>> x = torch.Tensor([[[0.2, 0.7], [0.9, 0.3]], [[0.2, 0.7], [0.9, 0.3]]])
>>> y = torch.Tensor([[[0.4, 0.2], [0.8, 0.6]], [[0.4, 0.2], [0.8, 0.6]]])
>>> critical_success_index(x, y, 0.5, keep_sequence_dim=0)
tensor([0.3333, 0.3333])
```

---

**Navigation**

- Parent: [Regression](/docs/torchmetrics/1.9.0/regression.md)
