Spaces:
Runtime error
Runtime error
Update Space (evaluate main: 828c6327)
Browse files- README.md +123 -4
- app.py +6 -0
- requirements.txt +4 -0
- spearmanr.py +124 -0
README.md
CHANGED
@@ -1,12 +1,131 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: blue
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.0.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
|
|
|
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
title: Spearman Correlation Coefficient Metric
|
3 |
+
emoji: 🤗
|
4 |
colorFrom: blue
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.0.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
tags:
|
11 |
+
- evaluate
|
12 |
+
- metric
|
13 |
---
|
14 |
|
15 |
+
# Metric Card for Spearman Correlation Coefficient Metric (spearmanr)
|
16 |
+
|
17 |
+
|
18 |
+
## Metric Description
|
19 |
+
The Spearman rank-order correlation coefficient is a measure of the
|
20 |
+
relationship between two datasets. Like other correlation coefficients,
|
21 |
+
this one varies between -1 and +1 with 0 implying no correlation.
|
22 |
+
Positive correlations imply that as data in dataset x increases, so
|
23 |
+
does data in dataset y. Negative correlations imply that as x increases,
|
24 |
+
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.
|
25 |
+
|
26 |
+
Unlike the Pearson correlation, the Spearman correlation does not
|
27 |
+
assume that both datasets are normally distributed.
|
28 |
+
|
29 |
+
The p-value roughly indicates the probability of an uncorrelated system
|
30 |
+
producing datasets that have a Spearman correlation at least as extreme
|
31 |
+
as the one computed from these datasets. The p-values are not entirely
|
32 |
+
reliable but are probably reasonable for datasets larger than 500 or so.
|
33 |
+
|
34 |
+
|
35 |
+
## How to Use
|
36 |
+
At minimum, this metric only requires a `list` of predictions and a `list` of references:
|
37 |
+
|
38 |
+
```python
|
39 |
+
>>> spearmanr_metric = evaluate.load("spearmanr")
|
40 |
+
>>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
|
41 |
+
>>> print(results)
|
42 |
+
{'spearmanr': -0.7}
|
43 |
+
```
|
44 |
+
|
45 |
+
### Inputs
|
46 |
+
- **`predictions`** (`list` of `float`): Predicted labels, as returned by a model.
|
47 |
+
- **`references`** (`list` of `float`): Ground truth labels.
|
48 |
+
- **`return_pvalue`** (`bool`): If `True`, returns the p-value. If `False`, returns
|
49 |
+
only the spearmanr score. Defaults to `False`.
|
50 |
+
|
51 |
+
### Output Values
|
52 |
+
- **`spearmanr`** (`float`): Spearman correlation coefficient.
|
53 |
+
- **`p-value`** (`float`): p-value. **Note**: is only returned
|
54 |
+
if `return_pvalue=True` is input.
|
55 |
+
|
56 |
+
If `return_pvalue=False`, the output is a `dict` with one value, as below:
|
57 |
+
```python
|
58 |
+
{'spearmanr': -0.7}
|
59 |
+
```
|
60 |
+
|
61 |
+
Otherwise, if `return_pvalue=True`, the output is a `dict` containing a the `spearmanr` value as well as the corresponding `pvalue`:
|
62 |
+
```python
|
63 |
+
{'spearmanr': -0.7, 'spearmanr_pvalue': 0.1881204043741873}
|
64 |
+
```
|
65 |
+
|
66 |
+
Spearman rank-order correlations can take on any value from `-1` to `1`, inclusive.
|
67 |
+
|
68 |
+
The p-values can take on any value from `0` to `1`, inclusive.
|
69 |
+
|
70 |
+
#### Values from Popular Papers
|
71 |
+
|
72 |
+
|
73 |
+
### Examples
|
74 |
+
A basic example:
|
75 |
+
```python
|
76 |
+
>>> spearmanr_metric = evaluate.load("spearmanr")
|
77 |
+
>>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
|
78 |
+
>>> print(results)
|
79 |
+
{'spearmanr': -0.7}
|
80 |
+
```
|
81 |
+
|
82 |
+
The same example, but that also returns the pvalue:
|
83 |
+
```python
|
84 |
+
>>> spearmanr_metric = evaluate.load("spearmanr")
|
85 |
+
>>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4], return_pvalue=True)
|
86 |
+
>>> print(results)
|
87 |
+
{'spearmanr': -0.7, 'spearmanr_pvalue': 0.1881204043741873
|
88 |
+
>>> print(results['spearmanr'])
|
89 |
+
-0.7
|
90 |
+
>>> print(results['spearmanr_pvalue'])
|
91 |
+
0.1881204043741873
|
92 |
+
```
|
93 |
+
|
94 |
+
## Limitations and Bias
|
95 |
+
|
96 |
+
|
97 |
+
## Citation
|
98 |
+
```bibtex
|
99 |
+
@book{kokoska2000crc,
|
100 |
+
title={CRC standard probability and statistics tables and formulae},
|
101 |
+
author={Kokoska, Stephen and Zwillinger, Daniel},
|
102 |
+
year={2000},
|
103 |
+
publisher={Crc Press}
|
104 |
+
}
|
105 |
+
@article{2020SciPy-NMeth,
|
106 |
+
author = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
|
107 |
+
Haberland, Matt and Reddy, Tyler and Cournapeau, David and
|
108 |
+
Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
|
109 |
+
Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
|
110 |
+
Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
|
111 |
+
Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
|
112 |
+
Kern, Robert and Larson, Eric and Carey, C J and
|
113 |
+
Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
|
114 |
+
{VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
|
115 |
+
Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
|
116 |
+
Harris, Charles R. and Archibald, Anne M. and
|
117 |
+
Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
|
118 |
+
{van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
|
119 |
+
title = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
|
120 |
+
Computing in Python}},
|
121 |
+
journal = {Nature Methods},
|
122 |
+
year = {2020},
|
123 |
+
volume = {17},
|
124 |
+
pages = {261--272},
|
125 |
+
adsurl = {https://rdcu.be/b08Wh},
|
126 |
+
doi = {10.1038/s41592-019-0686-2},
|
127 |
+
}
|
128 |
+
```
|
129 |
+
|
130 |
+
## Further References
|
131 |
+
*Add any useful further references.*
|
app.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import evaluate
|
2 |
+
from evaluate.utils import launch_gradio_widget
|
3 |
+
|
4 |
+
|
5 |
+
module = evaluate.load("spearmanr")
|
6 |
+
launch_gradio_widget(module)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# TODO: fix github to release
|
2 |
+
git+https://github.com/huggingface/evaluate.git@b6e6ed7f3e6844b297bff1b43a1b4be0709b9671
|
3 |
+
datasets~=2.0
|
4 |
+
scipy
|
spearmanr.py
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2021 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
"""Spearman correlation coefficient metric."""
|
15 |
+
|
16 |
+
import datasets
|
17 |
+
from scipy.stats import spearmanr
|
18 |
+
|
19 |
+
import evaluate
|
20 |
+
|
21 |
+
|
22 |
+
_DESCRIPTION = """
|
23 |
+
The Spearman rank-order correlation coefficient is a measure of the
|
24 |
+
relationship between two datasets. Like other correlation coefficients,
|
25 |
+
this one varies between -1 and +1 with 0 implying no correlation.
|
26 |
+
Positive correlations imply that as data in dataset x increases, so
|
27 |
+
does data in dataset y. Negative correlations imply that as x increases,
|
28 |
+
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.
|
29 |
+
|
30 |
+
Unlike the Pearson correlation, the Spearman correlation does not
|
31 |
+
assume that both datasets are normally distributed.
|
32 |
+
|
33 |
+
The p-value roughly indicates the probability of an uncorrelated system
|
34 |
+
producing datasets that have a Spearman correlation at least as extreme
|
35 |
+
as the one computed from these datasets. The p-values are not entirely
|
36 |
+
reliable but are probably reasonable for datasets larger than 500 or so.
|
37 |
+
"""
|
38 |
+
|
39 |
+
_KWARGS_DESCRIPTION = """
|
40 |
+
Args:
|
41 |
+
predictions (`List[float]`): Predicted labels, as returned by a model.
|
42 |
+
references (`List[float]`): Ground truth labels.
|
43 |
+
return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
|
44 |
+
only the spearmanr score. Defaults to `False`.
|
45 |
+
Returns:
|
46 |
+
spearmanr (`float`): Spearman correlation coefficient.
|
47 |
+
p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
|
48 |
+
Examples:
|
49 |
+
Example 1:
|
50 |
+
>>> spearmanr_metric = evaluate.load("spearmanr")
|
51 |
+
>>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
|
52 |
+
>>> print(results)
|
53 |
+
{'spearmanr': -0.7}
|
54 |
+
|
55 |
+
Example 2:
|
56 |
+
>>> spearmanr_metric = evaluate.load("spearmanr")
|
57 |
+
>>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
|
58 |
+
... predictions=[10, 9, 2.5, 6, 4],
|
59 |
+
... return_pvalue=True)
|
60 |
+
>>> print(results['spearmanr'])
|
61 |
+
-0.7
|
62 |
+
>>> print(round(results['spearmanr_pvalue'], 2))
|
63 |
+
0.19
|
64 |
+
"""
|
65 |
+
|
66 |
+
_CITATION = r"""\
|
67 |
+
@book{kokoska2000crc,
|
68 |
+
title={CRC standard probability and statistics tables and formulae},
|
69 |
+
author={Kokoska, Stephen and Zwillinger, Daniel},
|
70 |
+
year={2000},
|
71 |
+
publisher={Crc Press}
|
72 |
+
}
|
73 |
+
@article{2020SciPy-NMeth,
|
74 |
+
author = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
|
75 |
+
Haberland, Matt and Reddy, Tyler and Cournapeau, David and
|
76 |
+
Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
|
77 |
+
Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
|
78 |
+
Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
|
79 |
+
Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
|
80 |
+
Kern, Robert and Larson, Eric and Carey, C J and
|
81 |
+
Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
|
82 |
+
{VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
|
83 |
+
Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
|
84 |
+
Harris, Charles R. and Archibald, Anne M. and
|
85 |
+
Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
|
86 |
+
{van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
|
87 |
+
title = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
|
88 |
+
Computing in Python}},
|
89 |
+
journal = {Nature Methods},
|
90 |
+
year = {2020},
|
91 |
+
volume = {17},
|
92 |
+
pages = {261--272},
|
93 |
+
adsurl = {https://rdcu.be/b08Wh},
|
94 |
+
doi = {10.1038/s41592-019-0686-2},
|
95 |
+
}
|
96 |
+
"""
|
97 |
+
|
98 |
+
|
99 |
+
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
100 |
+
class Spearmanr(evaluate.EvaluationModule):
|
101 |
+
def _info(self):
|
102 |
+
return evaluate.EvaluationModuleInfo(
|
103 |
+
description=_DESCRIPTION,
|
104 |
+
citation=_CITATION,
|
105 |
+
inputs_description=_KWARGS_DESCRIPTION,
|
106 |
+
features=datasets.Features(
|
107 |
+
{
|
108 |
+
"predictions": datasets.Value("float"),
|
109 |
+
"references": datasets.Value("float"),
|
110 |
+
}
|
111 |
+
),
|
112 |
+
reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"],
|
113 |
+
)
|
114 |
+
|
115 |
+
def _compute(self, predictions, references, return_pvalue=False):
|
116 |
+
if return_pvalue:
|
117 |
+
return {
|
118 |
+
"spearmanr": spearmanr(references, predictions)[0],
|
119 |
+
"spearmanr_pvalue": spearmanr(references, predictions)[1],
|
120 |
+
}
|
121 |
+
else:
|
122 |
+
return {
|
123 |
+
"spearmanr": spearmanr(references, predictions)[0],
|
124 |
+
}
|