Spaces:
Runtime error
Runtime error
Update Space (evaluate main: e4a27243)
Browse files- brier_score.py +22 -3
- requirements.txt +1 -1
brier_score.py
CHANGED
@@ -13,6 +13,9 @@
|
|
13 |
# limitations under the License.
|
14 |
"""Brier Score Metric"""
|
15 |
|
|
|
|
|
|
|
16 |
import datasets
|
17 |
from sklearn.metrics import brier_score_loss
|
18 |
|
@@ -84,13 +87,27 @@ Examples:
|
|
84 |
"""
|
85 |
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
88 |
class BrierScore(evaluate.Metric):
|
89 |
-
|
|
|
|
|
|
|
|
|
90 |
return evaluate.MetricInfo(
|
91 |
description=_DESCRIPTION,
|
92 |
citation=_CITATION,
|
93 |
inputs_description=_KWARGS_DESCRIPTION,
|
|
|
94 |
features=self._get_feature_types(),
|
95 |
reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.brier_score_loss.html"],
|
96 |
)
|
@@ -127,8 +144,10 @@ class BrierScore(evaluate.Metric):
|
|
127 |
),
|
128 |
]
|
129 |
|
130 |
-
def _compute(self, references, predictions
|
131 |
|
132 |
-
brier_score = brier_score_loss(
|
|
|
|
|
133 |
|
134 |
return {"brier_score": brier_score}
|
|
|
13 |
# limitations under the License.
|
14 |
"""Brier Score Metric"""
|
15 |
|
16 |
+
from dataclasses import dataclass
|
17 |
+
from typing import List, Optional, Union
|
18 |
+
|
19 |
import datasets
|
20 |
from sklearn.metrics import brier_score_loss
|
21 |
|
|
|
87 |
"""
|
88 |
|
89 |
|
90 |
+
@dataclass
|
91 |
+
class BrierScoreConfig(evaluate.info.Config):
|
92 |
+
|
93 |
+
name: str = "default"
|
94 |
+
|
95 |
+
pos_label: Union[str, int] = 1
|
96 |
+
sample_weight: Optional[List[float]] = None
|
97 |
+
|
98 |
+
|
99 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
100 |
class BrierScore(evaluate.Metric):
|
101 |
+
|
102 |
+
CONFIG_CLASS = BrierScoreConfig
|
103 |
+
ALLOWED_CONFIG_NAMES = ["default", "multilist"]
|
104 |
+
|
105 |
+
def _info(self, config):
|
106 |
return evaluate.MetricInfo(
|
107 |
description=_DESCRIPTION,
|
108 |
citation=_CITATION,
|
109 |
inputs_description=_KWARGS_DESCRIPTION,
|
110 |
+
config=config,
|
111 |
features=self._get_feature_types(),
|
112 |
reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.brier_score_loss.html"],
|
113 |
)
|
|
|
144 |
),
|
145 |
]
|
146 |
|
147 |
+
def _compute(self, references, predictions):
|
148 |
|
149 |
+
brier_score = brier_score_loss(
|
150 |
+
references, predictions, sample_weight=self.config.sample_weight, pos_label=self.config.pos_label
|
151 |
+
)
|
152 |
|
153 |
return {"brier_score": brier_score}
|
requirements.txt
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
git+https://github.com/huggingface/evaluate@
|
2 |
sklearn
|
|
|
1 |
+
git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
|
2 |
sklearn
|