Compute the pearsonr metric — provided by scipy.stats. Use when the user has predictions and ground-truth and needs to compute pearsonr, or asks how to score with pearsonr.
Scanned 9/11/2026
Install to Claude Code
npx -y skills add qhjqhj00/research-skills-pool --skill pearsonr --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Pearsonr?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/qhjqhj00-pearsonr)More formats (shields.io, HTML) on the badges page.
---
name: pearsonr
description: Compute the pearsonr metric — provided by scipy.stats. Use when the user has predictions and ground-truth and needs to compute pearsonr, or asks how to score with pearsonr.
metadata:
skill_kind: metric
source_lib: scipy.stats
import_path: scipy.stats.pearsonr
source: library_introspection
---
# pearsonr
> Metric `pearsonr` from `scipy.stats` (scipy.stats.pearsonr)
## When to invoke this skill
The user has predictions + ground truth and asks to evaluate with pearsonr, or
mentions `scipy.stats.pearsonr` directly, or wants the standard scipy.stats implementation.
## Reference signature
```python
from scipy.stats import pearsonr
# pearsonr(x, y, *, alternative='two-sided', method=None, axis=0)
```
## Library docstring
```
Pearson correlation coefficient and p-value for testing non-correlation.
The Pearson correlation coefficient [1]_ measures the linear relationship
between two datasets. Like other correlation
coefficients, this one varies between -1 and +1 with 0 implying no
correlation. Correlations of -1 or +1 imply an exact linear relationship.
Positive correlations imply that as x increases, so does y. Negative
correlations imply that as x increases, y decreases.
This function also performs a test of the null hypothesis that the
distributions underlying the samples are uncorrelated and normally
distributed. (See Kowalski [3]_
for a discussion of the effects of non-normality of the input on the
distribution of the correlation coefficient.)
The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Pearson correlation at least as extreme
as the one computed from these datasets.
Parameters
----------
x : array_like
Input array.
y : array_like
Input array.
axis : int or None, default
Axis along which to perform the calculation. Default is 0.
If None, ravel both arrays before performing the calculation.
.. versionadded:: 1.14.0
alternative : {'two-sided', 'greater', 'less'}, optional
Defines the alternative hypothesis. Default is 'two-sided'.
The following options are available:
* 'two-sided': the correlation is nonzero
* 'less': the correlation is negative (less than zero)
* 'greater': the correlation is positive (greater than zero)
.. versionadded:: 1.9.0
method : ResamplingMethod, optional
Defines the method used to compute the p-value. If `method` is an
instance of `PermutationMethod`/`MonteCarloMethod`, the p-value is
computed using
`scipy.stats.permutation_test`/`scipy.stats.monte_carlo_test` with the
provided configuration options and other appropriate settings.
Otherwise, the p-value is computed as documented in the notes.
.. versionadded:: 1.11.0
Returns
-------
result : `~scipy.stats._result_classes.PearsonRResult`
An object with the following attributes:
statistic : float
Pearson product-moment correlation coefficient.
pvalue
```
## Quick recipe
```python
import scipy.stats as _m
score = _m.pearsonr(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)`.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!