Coverage for addmo/s3_model_tuning/scoring/abstract_scorer.py: 84%
19 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-08-31 13:05 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2025-08-31 13:05 +0000
1from abc import ABC, abstractmethod
3from addmo.s3_model_tuning.config.model_tuning_config import ModelTunerConfig
4from addmo.s3_model_tuning.models.abstract_model import AbstractMLModel
5from addmo.s3_model_tuning.scoring.metrics.abstract_metric import AbstractMetric
6from addmo.s3_model_tuning.scoring.metrics.metric_factory import MetricFactory
7from addmo.s3_model_tuning.scoring.validation_splitting.splitter_factory import (
8 SplitterFactory,
9)
12class Scoring:
13 """This class is used to score the model on the test period.
14 Currently I dont see any customizations that couldnt be implemented directly into the custom
15 metric class. Hence, this class is not designed as abstract class."""
17 def __init__(self, scoring_metric: str):
18 self.metric: AbstractMetric = MetricFactory.metric_factory(scoring_metric)
20 def score_test(self, model: AbstractMLModel, x, y):
21 """Returns a positive float value. The higher the better.
22 x and y include only test period. The model is already trained."""
23 return self.metric(model, x, y)
26class ValidationScoring(ABC):
27 def __init__(self, config: ModelTunerConfig):
28 self.metric: AbstractMetric = MetricFactory.metric_factory(
29 config.validation_score_metric, config.validation_score_metric_kwargs
30 )
31 self.splitter = SplitterFactory.splitter_factory(config)
33 @staticmethod
34 @abstractmethod
35 def score_validation(model: AbstractMLModel, x, y):
36 """Returns a positive float value. The higher the better.
37 x and y include train and evaluation period. The model will be trained on the corresponding
38 train period."""
39 pass