Compute the SpatialCorrelationCoefficient metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute SpatialCorrelationCoefficient, or asks how to score with SpatialCorrelationCoefficient.
Installs into .claude/skills of the current project.
Are you the author of Spatialcorrelationcoefficient?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-spatialcorrelationcoefficient)
---
name: spatialcorrelationcoefficient
description: Compute the SpatialCorrelationCoefficient metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute SpatialCorrelationCoefficient, or asks how to score with SpatialCorrelationCoefficient.
metadata:
skill_kind: metric
source_lib: torchmetrics
import_path: torchmetrics.image.SpatialCorrelationCoefficient
source: library_introspection
---
# spatialcorrelationcoefficient
> Metric `SpatialCorrelationCoefficient` from `torchmetrics` (torchmetrics.image.SpatialCorrelationCoefficient)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with SpatialCorrelationCoefficient, or
mentions `torchmetrics.image.SpatialCorrelationCoefficient` directly, or wants the standard torchmetrics implementation.
## Reference signature
```python
from torchmetrics.image import SpatialCorrelationCoefficient
# SpatialCorrelationCoefficient(high_pass_filter: Optional[torch.Tensor] = None, window_size: int = 8, **kwargs: Any) -> None
```
## Library docstring
```
Compute Spatial Correlation Coefficient (SCC_).
As input to ``forward`` and ``update`` the metric accepts the following input
- ``preds`` (:class:`~torch.Tensor`): Predictions from model of shape ``(N,C,H,W)`` or ``(N,H,W)``.
- ``target`` (:class:`~torch.Tensor`): Ground truth values of shape ``(N,C,H,W)`` or ``(N,H,W)``.
As output of `forward` and `compute` the metric returns the following output
- ``scc`` (:class:`~torch.Tensor`): Tensor with scc score
Args:
hp_filter: High-pass filter tensor. default: tensor([[-1,-1,-1],[-1,8,-1],[-1,-1,-1]]).
window_size: Local window size integer. default: 8.
kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.
Example:
>>> from torch import randn
>>> from torchmetrics.image import SpatialCorrelationCoefficient as SCC
>>> preds = randn([32, 3, 64, 64])
>>> target = randn([32, 3, 64, 64])
>>> scc = SCC()
>>> scc(preds, target)
tensor(0.0023)
```
## Quick recipe
```python
import torchmetrics.image as _m
score = _m.SpatialCorrelationCoefficient(y_true, y_pred)
```
## Don'ts
- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.