lvwerra HF staff commited on
Commit
73158fb
1 Parent(s): ccda481

Update Space (evaluate main: e4a27243)

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -1
  2. spearmanr.py +18 -3
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- git+https://github.com/huggingface/evaluate@80448674f5447a9682afe051db243c4a13bfe4ff
2
  scipy
 
1
+ git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
2
  scipy
spearmanr.py CHANGED
@@ -13,6 +13,8 @@
13
  # limitations under the License.
14
  """Spearman correlation coefficient metric."""
15
 
 
 
16
  import datasets
17
  from scipy.stats import spearmanr
18
 
@@ -96,13 +98,26 @@ _CITATION = r"""\
96
  """
97
 
98
 
 
 
 
 
 
 
 
 
99
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
100
  class Spearmanr(evaluate.Metric):
101
- def _info(self):
 
 
 
 
102
  return evaluate.MetricInfo(
103
  description=_DESCRIPTION,
104
  citation=_CITATION,
105
  inputs_description=_KWARGS_DESCRIPTION,
 
106
  features=datasets.Features(
107
  {
108
  "predictions": datasets.Value("float"),
@@ -112,9 +127,9 @@ class Spearmanr(evaluate.Metric):
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
  results = spearmanr(references, predictions)
117
- if return_pvalue:
118
  return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
119
  else:
120
  return {"spearmanr": results[0]}
 
13
  # limitations under the License.
14
  """Spearman correlation coefficient metric."""
15
 
16
+ from dataclasses import dataclass
17
+
18
  import datasets
19
  from scipy.stats import spearmanr
20
 
 
98
  """
99
 
100
 
101
+ @dataclass
102
+ class SpearmanrConfig(evaluate.info.Config):
103
+
104
+ name: str = "default"
105
+
106
+ return_pvalue: bool = False
107
+
108
+
109
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
110
  class Spearmanr(evaluate.Metric):
111
+
112
+ CONFIG_CLASS = SpearmanrConfig
113
+ ALLOWED_CONFIG_NAMES = ["default"]
114
+
115
+ def _info(self, config):
116
  return evaluate.MetricInfo(
117
  description=_DESCRIPTION,
118
  citation=_CITATION,
119
  inputs_description=_KWARGS_DESCRIPTION,
120
+ config=config,
121
  features=datasets.Features(
122
  {
123
  "predictions": datasets.Value("float"),
 
127
  reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"],
128
  )
129
 
130
+ def _compute(self, predictions, references):
131
  results = spearmanr(references, predictions)
132
+ if self.config.return_pvalue:
133
  return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
134
  else:
135
  return {"spearmanr": results[0]}