---
title: Continuous Ranked Probability Score (CRPS)
description: Computes continuous ranked probability score.
canonical: 'https://lightning.ai/docs/torchmetrics/stable/regression/crps'
---
# Continuous Ranked Probability Score (CRPS) {#continuous-ranked-probability-score-crps}

## Module Interface {#module-interface}

### `class torchmetrics.regression.crps.ContinuousRankedProbabilityScore(**kwargs)` {#torchmetrics.regression.crps.ContinuousRankedProbabilityScore}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/regression/crps.py#L29-L133)

Computes continuous ranked probability score.

```math
CRPS(F, y) = \int_{-\infty}^{\infty} (F(x) - 1_{x \geq y})^2 dx
```

where $`F`$ is the predicted cumulative distribution function and $`y`$ is the true target. The metric is usually used to evaluate probabilistic regression models, such as forecasting models. A lower CRPS indicates a better forecast, meaning that forecasted probabilities are closer to the true observed values. CRPS can also be seen as a generalization of the brier score for non binary classification problems.

As input to `forward` and `update` the metric accepts the following input:

*   `preds` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Predicted float tensor with shape `(N,d)`
    
*   `target` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): Ground truth float tensor with shape `(N,d)`
    

As output of `forward` and `compute` the metric returns the following output:

*   `cosine_similarity` ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")): A float tensor with the cosine similarity
    

Parameters:

*   **reduction** – how to reduce over the batch dimension using ‘sum’, ‘mean’ or ‘none’ (taking the individual scores)
    
*   **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.
    

Example

```python
>>> from torch import randn
>>> from torchmetrics.regression import ContinuousRankedProbabilityScore
>>> preds = randn(10, 5)
>>> target = randn(10)
>>> crps = ContinuousRankedProbabilityScore()
>>> crps(preds, target)
tensor(0.7731)
```

#### `plot(val=None, ax=None)` {#torchmetrics.regression.crps.ContinuousRankedProbabilityScore.plot}

[\[source\]](https://github.com/Lightning-AI/torchmetrics/blob/v1.9.0/src/torchmetrics/regression/crps.py#L93-L133)

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/typing.html#typing.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 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 randn
>>> # Example plotting a single value
>>> from torchmetrics.regression import ContinuousRankedProbabilityScore
>>> metric = ContinuousRankedProbabilityScore()
>>> metric.update(randn(10,5), randn(10))
>>> fig_, ax_ = metric.plot()
```

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

```python
>>> from torch import randn
>>> # Example plotting multiple values
>>> from torchmetrics.regression import ContinuousRankedProbabilityScore
>>> metric = ContinuousRankedProbabilityScore()
>>> values = []
>>> for _ in range(10):
...     values.append(metric(randn(10,5), randn(10)))
>>> fig, ax = metric.plot(values)
```

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

## Functional Interface {#functional-interface}

### `torchmetrics.functional.regression.continuous_ranked_probability_score(preds, target)` {#torchmetrics.functional.regression.continuous_ranked_probability_score}

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

Computes continuous ranked probability score.

```math
CRPS(F, y) = \int_{-\infty}^{\infty} (F(x) - 1_{x \geq y})^2 dx
```

where $`F`$ is the predicted cumulative distribution function and $`y`$ is the true target. The metric is usually used to evaluate probabilistic regression models, such as forecasting models. A lower CRPS indicates a better forecast, meaning that forecasted probabilities are closer to the true observed values. CRPS can also be seen as a generalization of the brier score for non binary classification problems.

Parameters:

*   **preds** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – a 2d tensor of shape (batch\_size, ensemble\_members) with predictions. The second dimension represents the ensemble members.
    
*   **target** ([`Tensor`](https://docs.pytorch.org/docs/stable/tensors.html#torch.Tensor "(in PyTorch v2.15)")) – a 1d tensor of shape (batch\_size) with the target values.
    

Return type:

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

Returns:

Tensor with CRPS

Raises:

*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If the number of ensemble members is less than 2.
    
*   [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError "(in Python v3.15)") – If the first dimension of preds and target do not match.
    

Example::

```python
>>> from torchmetrics.functional.regression import continuous_ranked_probability_score
>>> from torch import randn
>>> preds = randn(10, 5)
>>> target = randn(10)
>>> continuous_ranked_probability_score(preds, target)
tensor(0.7731)
```

---

**Navigation**

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