-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathprecision.py
More file actions
90 lines (66 loc) · 2.68 KB
/
precision.py
File metadata and controls
90 lines (66 loc) · 2.68 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
"""Class definition of the payload used to send a precision metric to ``hub``."""
from __future__ import annotations
from typing import ClassVar, Literal
from .metric import CrossValidationReportMetric, EstimatorReportMetric, cast_to_float
class Precision(EstimatorReportMetric): # noqa: D101
accessor: ClassVar[str] = "metrics.precision"
name: str = "precision"
verbose_name: str = "Precision (macro)"
greater_is_better: bool = True
position: None = None
def compute(self) -> None:
"""Compute the value of the metric."""
try:
function = self.report.metrics.precision
except AttributeError:
self.value = None
else:
self.value = cast_to_float(
function(data_source=self.data_source, average="macro")
)
class PrecisionTrain(Precision): # noqa: D101
data_source: Literal["train"] = "train"
class PrecisionTest(Precision): # noqa: D101
data_source: Literal["test"] = "test"
class PrecisionMean(CrossValidationReportMetric): # noqa: D101
accessor: ClassVar[str] = "metrics.precision"
name: str = "precision_mean"
verbose_name: str = "Precision (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.precision
except AttributeError:
self.value = None
else:
dataframe = function(
data_source=self.data_source, aggregate="mean", average="macro"
)
self.value = cast_to_float(dataframe.iloc[0, 0])
class PrecisionTrainMean(PrecisionMean): # noqa: D101
data_source: Literal["train"] = "train"
class PrecisionTestMean(PrecisionMean): # noqa: D101
data_source: Literal["test"] = "test"
class PrecisionStd(CrossValidationReportMetric): # noqa: D101
accessor: ClassVar[str] = "metrics.precision"
name: str = "precision_std"
verbose_name: str = "Precision (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.precision
except AttributeError:
self.value = None
else:
dataframe = function(
data_source=self.data_source, aggregate="std", average="macro"
)
self.value = cast_to_float(dataframe.iloc[0, 0])
class PrecisionTrainStd(PrecisionStd): # noqa: D101
data_source: Literal["train"] = "train"
class PrecisionTestStd(PrecisionStd): # noqa: D101
data_source: Literal["test"] = "test"