-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathrecall.py
More file actions
92 lines (68 loc) · 2.71 KB
/
recall.py
File metadata and controls
92 lines (68 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Class definition of the payload used to send a recall metric to ``hub``."""
from __future__ import annotations
from typing import ClassVar, Literal
from .metric import CrossValidationReportMetric, EstimatorReportMetric, cast_to_float
class Recall(EstimatorReportMetric): # noqa: D101
accessor: ClassVar[str] = "metrics.recall"
name: str = "recall"
verbose_name: str = "Recall (macro)"
greater_is_better: bool = True
position: None = None
def compute(self) -> None:
"""Compute the value of the metric."""
try:
function = self.report.metrics.recall
except AttributeError:
self.value = None
else:
self.value = cast_to_float(
function(data_source=self.data_source, average="macro")
)
class RecallTrain(Recall): # noqa: D101
data_source: Literal["train"] = "train"
class RecallTest(Recall): # noqa: D101
data_source: Literal["test"] = "test"
class RecallMean(CrossValidationReportMetric): # noqa: D101
accessor: ClassVar[str] = "metrics.recall"
aggregate: ClassVar[Literal["mean"]] = "mean"
name: str = "recall_mean"
verbose_name: str = "Recall (macro) - MEAN"
greater_is_better: bool = True
position: None = None
def compute(self) -> None:
"""Compute the value of the metric."""
try:
function = self.report.metrics.recall
except AttributeError:
self.value = None
else:
dataframe = function(
data_source=self.data_source, aggregate=self.aggregate, average="macro"
)
self.value = cast_to_float(dataframe.iloc[0, 0])
class RecallTrainMean(RecallMean): # noqa: D101
data_source: Literal["train"] = "train"
class RecallTestMean(RecallMean): # noqa: D101
data_source: Literal["test"] = "test"
class RecallStd(CrossValidationReportMetric): # noqa: D101
accessor: ClassVar[str] = "metrics.recall"
aggregate: ClassVar[Literal["std"]] = "std"
name: str = "recall_std"
verbose_name: str = "Recall (macro) - STD"
greater_is_better: bool = False
position: None = None
def compute(self) -> None:
"""Compute the value of the metric."""
try:
function = self.report.metrics.recall
except AttributeError:
self.value = None
else:
dataframe = function(
data_source=self.data_source, aggregate=self.aggregate, average="macro"
)
self.value = cast_to_float(dataframe.iloc[0, 0])
class RecallTrainStd(RecallStd): # noqa: D101
data_source: Literal["train"] = "train"
class RecallTestStd(RecallStd): # noqa: D101
data_source: Literal["test"] = "test"