Coverage for tadkit/base/tadlearner.py: 100%
8 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 Sequence, Optional, Protocol, runtime_checkable
3from tadkit.base.typing import ParamsDescription, Array
6@runtime_checkable
7class TADLearner(Protocol):
8 """Abstract class of Time Anomaly Detection Learner (model).
10 Avoid explicit inheritance from this class. Better to simply do it implicitly.
12 Methods:
13 fit: Fit the learner on input data.
14 score_samples: The measure of normality of an observation according to the fitted model.
15 The lower, the more abnormal.
16 predict: Predict if a particular sample is an outlier or not. For each observation, tells
17 whether or not (+1 or -1) it should be considered as an inlier according to the fitted model.
19 Class attributes:
20 params_description: Description of the arguments of the __init__ method. See examples in the catalog.
21 required_properties: Get the properties that the input data must satisfies. See examples in the catalog.
23 Example:
24 >>> assert isinstance(MyLearner, TADLearner)
25 >>> MyLearner.required_properties # The required property of input data
26 >>> MyLearner.params_description # The description of the params
27 >>> params = ... # Params to initiate learner
28 >>> learner = MyLearner(**params)
29 >>> learner.fit(X) # X, y must satisfy MyLearner.required_properties
30 >>> score_sample_pred = learner.score_samples(X_test)
31 """
33 required_properties: Sequence[str] = []
34 params_description: ParamsDescription = {}
36 def fit(self, X: Array, y: Optional[Array] = None) -> "TADLearner": ...
38 def score_samples(self, X: Array) -> Array:
39 """
40 The measure of normality of an observation according to the fitted model.
41 Scikit-learn compatible.
43 Parameters
44 ----------
45 X : {array-like, sparse matrix} of shape (n_samples, n_features)
46 The input samples.
48 Returns
49 -------
50 scores : ndarray of shape (n_samples,)
51 The anomaly score of the input samples.
52 The lower, the more abnormal.
53 """
54 ...
56 def predict(self, X: Array) -> Array:
57 """
58 Predict if a particular sample is an outlier or not.
59 Scikit-learn compatible.
61 Parameters
62 ----------
63 X : {array-like, sparse matrix} of shape (n_samples, n_features)
64 The input samples.
66 Returns
67 -------
68 is_inlier : ndarray of shape (n_samples,)
69 For each observation, tells whether or not (+1 or -1) it should
70 be considered as an inlier according to the fitted model.
71 """
72 ...