Coverage for tadkit/utils/tadlearner_factory.py: 92%
13 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 15:09 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-04 15:09 +0000
1from typing import TypeVar, Sequence, Type, Optional
3from tadkit.base.tadlearner import TADLearner
4from tadkit.base.typing import KWParams, ParamsDescription
6Estimator = TypeVar("Estimator")
9def tadlearner_factory(
10 Model: Type[Estimator],
11 required_properties: Sequence[str],
12 params_description: ParamsDescription,
13 name: Optional[str] = None,
14) -> Type[TADLearner]:
15 """Wrap a sklearn anomaly detection model to a TADLearner.
17 Args:
18 Model: sklearn type model- to wrapp, possessing get_params, fit and score_samples methods.
19 required_properties: The properties that the input data must satisfies.
20 params_description: Description of the kwargs of the __init__ method that is exposed.
21 name: The Name of the class. Default name if None.
23 Returns:
24 A subclass of TADLearner wrapping Model with given required_properties, params_description
25 and __name__.
26 """
28 if name is None:
29 name = Model.__name__ + "Learner"
31 def __init__(self, **params: KWParams):
32 Model.__init__(self, **params)
34 Model.name = name
35 Model.required_properties = required_properties
36 Model.params_description = params_description
37 return Model