Coverage for tdaad/utils/local_elliptic_envelope.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-13 13:45 +0000

1"""Pandas Elliptic Envelope.""" 

2 

3# Author: Martin Royer 

4 

5import pandas as pd 

6 

7from sklearn.utils.validation import check_is_fitted 

8from sklearn.covariance import EllipticEnvelope 

9 

10 

11def pandas_mahalanobis(self, X): 

12 """Compute the negative Mahalanobis distances of embedding matrix X. 

13 

14 Parameters 

15 ---------- 

16 X : array-like of shape (n_samples, n_features) 

17 The embedding matrix. 

18 

19 Returns 

20 ------- 

21 negative_mahal_distances : pandas.DataFrame of shape (n_samples,) 

22 Opposite of the Mahalanobis distances. 

23 """ 

24 return pd.DataFrame(index=X.index, data=self.mahalanobis(X)) 

25 

26 

27def pandas_score_samples(self, X): 

28 """Compute the negative Mahalanobis distances. 

29 

30 Parameters 

31 ---------- 

32 X : array-like of shape (n_samples, n_features) 

33 The data matrix. 

34 

35 Returns 

36 ------- 

37 negative_mahal_distances : array-like of shape (n_samples,) 

38 Opposite of the Mahalanobis distances. 

39 """ 

40 check_is_fitted(self) 

41 return -pandas_mahalanobis(self, X) 

42 

43 

44EllipticEnvelope.score_samples = pandas_score_samples