Coverage for tests / test_sklearners.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-03 15:41 +0000

1import numpy as np 

2import pandas as pd 

3from tadkit.catalog.sklearners import ( 

4 KDEOutlierDetector, 

5 GMMOutlierDetector, 

6 CustomScoreOutlierDetector, 

7) 

8 

9 

10from tadkit.utils.param_spec import ( 

11 get_param_descriptions, 

12 get_default_class_values, 

13 params_from_class, 

14) 

15 

16get_param_descriptions(KDEOutlierDetector) 

17get_default_class_values(KDEOutlierDetector) 

18 

19params_from_class(KDEOutlierDetector) 

20 

21 

22n_timestamps = 100 

23n_sensors = 5 

24timestamps = pd.to_datetime("2024-01-01", utc=True) + pd.Timedelta(1, "h") * np.arange( 

25 n_timestamps 

26) 

27X = pd.DataFrame(np.random.random(size=(n_timestamps, n_sensors)), index=timestamps) 

28 

29 

30detector = KDEOutlierDetector(contamination=0.1) 

31detector.fit(X) 

32print(detector.predict(X)) 

33 

34detector = GMMOutlierDetector(contamination=0.1) 

35detector.fit(X) 

36print(detector.predict(X)) 

37 

38 

39detector_custom = CustomScoreOutlierDetector( 

40 score_func=lambda X: -np.linalg.norm(X, axis=1) 

41) 

42detector_custom.fit(X) 

43print(detector_custom.predict(X))