Spaces:
Build error
Build error
Update classification_report.py
Browse files- README.md +4 -3
- classification_report.py +30 -75
README.md
CHANGED
@@ -1,15 +1,16 @@
|
|
1 |
---
|
2 |
title: classification_report
|
3 |
-
datasets:
|
4 |
-
-
|
5 |
tags:
|
6 |
- evaluate
|
7 |
- metric
|
8 |
-
description:
|
|
|
|
|
9 |
sdk: gradio
|
10 |
sdk_version: 3.0.2
|
11 |
app_file: app.py
|
12 |
pinned: false
|
|
|
13 |
---
|
14 |
|
15 |
# Metric Card for classification_report
|
|
|
1 |
---
|
2 |
title: classification_report
|
|
|
|
|
3 |
tags:
|
4 |
- evaluate
|
5 |
- metric
|
6 |
+
description: >-
|
7 |
+
a classification report is a simple tool to compute multiple metrics such as:
|
8 |
+
accuracy precision/recall/f1-score by class. mean/weighted average.
|
9 |
sdk: gradio
|
10 |
sdk_version: 3.0.2
|
11 |
app_file: app.py
|
12 |
pinned: false
|
13 |
+
license: apache-2.0
|
14 |
---
|
15 |
|
16 |
# Metric Card for classification_report
|
classification_report.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# Copyright 2020 The HuggingFace
|
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.
|
@@ -11,85 +11,40 @@
|
|
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 |
-
"""
|
|
|
15 |
|
|
|
16 |
import evaluate
|
17 |
import datasets
|
18 |
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
"""
|
28 |
-
|
29 |
-
# TODO: Add description of the module here
|
30 |
-
_DESCRIPTION = """\
|
31 |
-
This new module is designed to solve this great ML task and is crafted with a lot of care.
|
32 |
-
"""
|
33 |
-
|
34 |
-
|
35 |
-
# TODO: Add description of the arguments of the module here
|
36 |
-
_KWARGS_DESCRIPTION = """
|
37 |
-
Calculates how good are predictions given some references, using certain scores
|
38 |
-
Args:
|
39 |
-
predictions: list of predictions to score. Each predictions
|
40 |
-
should be a string with tokens separated by spaces.
|
41 |
-
references: list of reference for each prediction. Each
|
42 |
-
reference should be a string with tokens separated by spaces.
|
43 |
-
Returns:
|
44 |
-
accuracy: description of the first score,
|
45 |
-
another_score: description of the second score,
|
46 |
-
Examples:
|
47 |
-
Examples should be written in doctest format, and should illustrate how
|
48 |
-
to use the function.
|
49 |
-
|
50 |
-
>>> my_new_module = evaluate.load("my_new_module")
|
51 |
-
>>> results = my_new_module.compute(references=[0, 1], predictions=[0, 1])
|
52 |
-
>>> print(results)
|
53 |
-
{'accuracy': 1.0}
|
54 |
-
"""
|
55 |
-
|
56 |
-
# TODO: Define external resources urls if needed
|
57 |
-
BAD_WORDS_URL = "http://url/to/external/resource/bad_words.txt"
|
58 |
-
|
59 |
-
|
60 |
-
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
61 |
-
class classification_report(evaluate.Metric):
|
62 |
-
"""TODO: Short description of my evaluation module."""
|
63 |
-
|
64 |
-
def _info(self):
|
65 |
-
# TODO: Specifies the evaluate.EvaluationModuleInfo object
|
66 |
return evaluate.MetricInfo(
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
reference_urls=["
|
82 |
)
|
83 |
|
84 |
-
def
|
85 |
-
|
86 |
-
# TODO: Download external resources if needed
|
87 |
-
pass
|
88 |
-
|
89 |
-
def _compute(self, predictions, references):
|
90 |
-
"""Returns the scores"""
|
91 |
-
# TODO: Compute the different scores of the module
|
92 |
-
accuracy = sum(i == j for i, j in zip(predictions, references)) / len(predictions)
|
93 |
-
return {
|
94 |
-
"accuracy": accuracy,
|
95 |
-
}
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Evaluate Authors.
|
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.
|
|
|
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 |
+
""" classification_report metric. """
|
15 |
+
from typing import Optional
|
16 |
|
17 |
+
import sklearn
|
18 |
import evaluate
|
19 |
import datasets
|
20 |
|
21 |
|
22 |
+
class ClassificationReportModule(evaluate.Metric):
|
23 |
+
"""
|
24 |
+
Local metric used for classification task based on sklearn classiication_report().
|
25 |
+
a classification report is a simple tool to compute multiple metrics such as:
|
26 |
+
- accuracy
|
27 |
+
- precision/recall/f1-score by class.
|
28 |
+
- mean/weighted average.
|
29 |
+
"""
|
30 |
+
def _info(self) -> evaluate.MetricInfo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
return evaluate.MetricInfo(
|
32 |
+
description="Metric based on sklearn classification_report() method.",
|
33 |
+
citation="",
|
34 |
+
inputs_description="",
|
35 |
+
features=datasets.Features(
|
36 |
+
{
|
37 |
+
"predictions": datasets.Sequence(datasets.Value("int32")),
|
38 |
+
"references": datasets.Sequence(datasets.Value("int32")),
|
39 |
+
}
|
40 |
+
if self.config_name == "multilabel"
|
41 |
+
else {
|
42 |
+
"predictions": datasets.Value("int32"),
|
43 |
+
"references": datasets.Value("int32"),
|
44 |
+
}
|
45 |
+
),
|
46 |
+
reference_urls=[""],
|
47 |
)
|
48 |
|
49 |
+
def _compute(self, *, predictions=None, references=None, **kwargs) -> Optional[dict]:
|
50 |
+
return sklearn.metrics.classification_report(references, predictions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|