CoolFace
Apppublic

kumar6591/data-quality-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
base.py48 linesDownload Raw Back to tasks
1from abc import ABC, abstractmethod2 3from env.models import AuditReport4 5 6SCORE_EPS = 1e-67 8 9class BaseTask(ABC):10    @abstractmethod11    def get_description(self) -> str:12        ...13 14    @abstractmethod15    def get_table_names(self) -> list[str]:16        ...17 18    @abstractmethod19    def grade(self, report: AuditReport, gold: dict) -> tuple[float, dict]:20        ...21 22    @staticmethod23    def brier_adjust(base: float, confidence: float, correct: bool) -> float:24        c = 1.0 if correct else 0.025        brier = (confidence - c) ** 226        return base * (1.0 - 0.3 * brier)27 28    @staticmethod29    def strict_score(value: float, epsilon: float = SCORE_EPS) -> float:30        try:31            score = float(value)32        except Exception:33            score = epsilon34        if not (score > 0.0):35            return epsilon36        if not (score < 1.0):37            return 1.0 - epsilon38        return score39 40    @staticmethod41    def count_accuracy(reported: int, actual: int, tolerance: float = 0.15) -> float:42        if actual == 0:43            return 1.0 if reported == 0 else 0.044        ratio = abs(reported - actual) / actual45        if ratio <= tolerance:46            return max(0.0, 1.0 - ratio / tolerance)47        return max(0.0, 1.0 - ratio)48