-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathnormalizer.py
More file actions
37 lines (25 loc) · 939 Bytes
/
normalizer.py
File metadata and controls
37 lines (25 loc) · 939 Bytes
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
from abc import abstractmethod
class ScoreNormalizer:
_name = None
@abstractmethod
def __call__(self, score: float) -> float: ...
def __repr__(self):
return f"{self.__class__.__name__}({self.__dict__})"
def get_name(self) -> str | None:
return self._name
class ZScoreNormalizer(ScoreNormalizer):
_name = "zscore"
def __init__(self, mean: float, std: float) -> None:
super().__init__()
self.mean = mean
self.std = std
def __call__(self, score: float) -> float:
return (score - self.mean) / self.std
class MinMaxNormalizer(ScoreNormalizer):
_name = "minmax"
def __init__(self, min_score: float, max_score: float) -> None:
super().__init__()
self.min_score = min_score
self.max_score = max_score
def __call__(self, score: float) -> float:
return (score - self.min_score) / (self.max_score - self.min_score)