Source code for dffml.accuracy.accuracy

import abc

from ..feature import Feature
from ..model import ModelContext
from ..source.source import SourcesContext
from ..util.entrypoint import base_entry_point
from ..base import (
    config,
    BaseDataFlowFacilitatorObjectContext,
    BaseDataFlowFacilitatorObject,
)


[docs]class InvalidNumberOfFeaturesError(Exception): pass
[docs]@config class AccuracyConfig: pass
[docs]class AccuracyContext(abc.ABC, BaseDataFlowFacilitatorObjectContext): def __init__(self, parent: "Accuracy") -> None: self.parent = parent
[docs] @abc.abstractmethod async def score( self, mctx: ModelContext, sources: SourcesContext, *args: Feature ) -> float: """ Abstract method to get the score Parameters ---------- mctx : ModelContext The Model which needs to be used. sources : SourcesContext The sources to use to get the accuracy Returns ------- float The score value """ raise NotImplementedError()
[docs]@base_entry_point("dffml.accuracy", "accuracy") class AccuracyScorer(BaseDataFlowFacilitatorObject): """ Abstract base class which should be derived from and implemented using various accuracy scorer. """ CONFIG = AccuracyConfig CONTEXT = AccuracyContext def __call__(self) -> AccuracyContext: return self.CONTEXT(self)