-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbase.py
More file actions
32 lines (22 loc) · 842 Bytes
/
base.py
File metadata and controls
32 lines (22 loc) · 842 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
"""SHIFT base evaluation."""
from __future__ import annotations
from typing import Any
import numpy as np
class Evaluator:
"""Abstract evaluator class."""
METRICS: list[str] = []
def __init__(self) -> None:
"""Initialize evaluator."""
self.reset()
def reset(self) -> None:
"""Reset evaluator for new round of evaluation."""
self.metrics = {metric: [] for metric in self.METRICS}
def process(self, *args: Any) -> None: # type: ignore
"""Process a batch of data."""
raise NotImplementedError
def evaluate(self) -> dict[str, float]:
"""Evaluate all predictions according to given metric.
Returns:
dict[str, float]: Evaluation results.
"""
return {metric: np.nanmean(values) for metric, values in self.metrics.items()}