Coverage for source/model/model_blue_prints/general_sklearn_blue_print.py: 40%
15 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-07-30 20:59 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-07-30 20:59 +0000
1# model/model_blue_prints/general_sklearn_blue_print.py
3# global imports
4from sklearn.base import BaseEstimator
6# local imports
7from source.model import BluePrintBase, ModelAdapterBase, SklearnModelAdapter
9class GeneralSklearnBluePrint(BluePrintBase):
10 """
11 Implements a general blueprint for scikit-learn models. It provides a method to instantiate
12 a model based on the provided base estimator class and keyword arguments.
13 """
15 # local constants
16 __VERBOSE_KEY: str = "verbose"
18 def __init__(self, base_estimator_class: type, **kwargs) -> None:
19 """
20 Class constructor. Initializes the blueprint with a base estimator class and optional keyword arguments.
22 Parameters:
23 base_estimator_class (type): The base estimator class to use for model instantiation.
24 (**kwargs): Optional keyword arguments for the model.
25 """
27 if not issubclass(base_estimator_class, BaseEstimator):
28 raise TypeError(
29 f"Parameter base_estimator_class must be a subclass of BaseEstimator,"
30 f" got {base_estimator_class.__name__}"
31 )
33 self.__base_estimator_class = base_estimator_class
34 self.__kwargs = kwargs
36 if self.__VERBOSE_KEY not in self.__kwargs:
37 self.__kwargs[self.__VERBOSE_KEY] = True
39 def instantiate_model(self, **kwargs) -> ModelAdapterBase:
40 """
41 Instantiates a model based on the provided keyword arguments.
43 Parameters:
44 (**kwargs): Optional keyword arguments for the model.
46 Returns:
47 (ModelAdapterBase): The model adapter for the instantiated model.
48 """
50 if len(kwargs.keys()) == 0:
51 kwargs = self.__kwargs
53 return SklearnModelAdapter(self.__base_estimator_class(**kwargs))