robpy 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of robpy might be problematic. Click here for more details.

Files changed (55) hide show
  1. robpy/__init__.py +0 -0
  2. robpy/covariance/__init__.py +6 -0
  3. robpy/covariance/base.py +82 -0
  4. robpy/covariance/cellmcd.py +621 -0
  5. robpy/covariance/initial_ddcw.py +133 -0
  6. robpy/covariance/kendall.py +21 -0
  7. robpy/covariance/mcd.py +470 -0
  8. robpy/covariance/ogk.py +95 -0
  9. robpy/covariance/utils/alter_covariance.py +31 -0
  10. robpy/covariance/utils/cellmcd_utils.py +38 -0
  11. robpy/covariance/utils/cellmcd_visualization_utils.py +96 -0
  12. robpy/covariance/wrapping.py +72 -0
  13. robpy/datasets/__init__.py +4 -0
  14. robpy/datasets/base.py +389 -0
  15. robpy/datasets/data/animals.csv +66 -0
  16. robpy/datasets/data/glass.csv +181 -0
  17. robpy/datasets/data/stars.csv +48 -0
  18. robpy/datasets/data/telephone.csv +25 -0
  19. robpy/datasets/data/topgear.csv +298 -0
  20. robpy/datasets/descr/animals.rst +26 -0
  21. robpy/datasets/descr/glass.rst +20 -0
  22. robpy/datasets/descr/stars.rst +28 -0
  23. robpy/datasets/descr/telephone.rst +23 -0
  24. robpy/datasets/descr/topgear.rst +51 -0
  25. robpy/outliers/__init__.py +4 -0
  26. robpy/outliers/ddc.py +296 -0
  27. robpy/pca/__init__.py +3 -0
  28. robpy/pca/base.py +97 -0
  29. robpy/pca/robpca.py +89 -0
  30. robpy/pca/spca.py +48 -0
  31. robpy/preprocessing/__init__.py +3 -0
  32. robpy/preprocessing/data_cleaner.py +214 -0
  33. robpy/preprocessing/scaling.py +57 -0
  34. robpy/preprocessing/transfo.py +591 -0
  35. robpy/preprocessing/utils.py +63 -0
  36. robpy/regression/__init__.py +3 -0
  37. robpy/regression/base.py +116 -0
  38. robpy/regression/lts.py +408 -0
  39. robpy/regression/mm_estimator.py +57 -0
  40. robpy/regression/s_estimator.py +188 -0
  41. robpy/univariate/__init__.py +9 -0
  42. robpy/univariate/base.py +53 -0
  43. robpy/univariate/mcd.py +84 -0
  44. robpy/univariate/onestep_m.py +143 -0
  45. robpy/univariate/qn.py +112 -0
  46. robpy/univariate/tau.py +63 -0
  47. robpy/utils/distance.py +24 -0
  48. robpy/utils/general.py +31 -0
  49. robpy/utils/logging.py +22 -0
  50. robpy/utils/median.py +62 -0
  51. robpy/utils/outlyingness.py +61 -0
  52. robpy/utils/rho.py +35 -0
  53. robpy-0.1.0.dist-info/METADATA +31 -0
  54. robpy-0.1.0.dist-info/RECORD +55 -0
  55. robpy-0.1.0.dist-info/WHEEL +4 -0
robpy/__init__.py ADDED
File without changes
@@ -0,0 +1,6 @@
1
+ from robpy.covariance.base import RobustCovarianceEstimator
2
+ from robpy.covariance.mcd import FastMCDEstimator
3
+ from robpy.covariance.wrapping import WrappingCovarianceEstimator
4
+ from robpy.covariance.ogk import OGKEstimator
5
+ from robpy.covariance.kendall import KendallTauEstimator
6
+ from robpy.covariance.cellmcd import CellMCDEstimator
@@ -0,0 +1,82 @@
1
+ from __future__ import annotations
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ from scipy.stats import chi2
7
+ from scipy.linalg import pinvh
8
+ from sklearn.covariance import EmpiricalCovariance
9
+ from sklearn.exceptions import NotFittedError
10
+ from robpy.utils.distance import mahalanobis_distance
11
+
12
+
13
+ class RobustCovarianceEstimator(EmpiricalCovariance):
14
+ def __init__(self, *, store_precision=True, assume_centered=False, nans_allowed=False):
15
+ super().__init__(
16
+ store_precision=store_precision,
17
+ assume_centered=assume_centered,
18
+ )
19
+ self.nans_allowed = nans_allowed
20
+
21
+ def fit(self, X: np.ndarray | pd.DataFrame) -> RobustCovarianceEstimator:
22
+ """Fit the covariance estimator."""
23
+ if isinstance(X, pd.DataFrame):
24
+ X = X.values
25
+ if self.nans_allowed:
26
+ self.n_features_in_ = X.shape[1]
27
+ else:
28
+ X = self._validate_data(X) # this sets n_features_in_ also
29
+
30
+ if self.assume_centered:
31
+ self.location_ = np.zeros(X.shape[1])
32
+ else:
33
+ self.location_ = X.mean(0)
34
+ covariance = self.calculate_covariance(X)
35
+ self._set_covariance(covariance)
36
+ if self.store_precision:
37
+ self.precision_ = pinvh(covariance)
38
+ self.default_covariance_ = np.cov(X, rowvar=False)
39
+ self._robust_distances = mahalanobis_distance(
40
+ X, location=self.location_, covariance=self.covariance_
41
+ )
42
+ self._mahalanobis_distances = mahalanobis_distance(
43
+ X, location=self.location_, covariance=self.default_covariance_
44
+ )
45
+
46
+ return self
47
+
48
+ def calculate_covariance(self, X) -> np.ndarray:
49
+ raise NotImplementedError
50
+
51
+ @property
52
+ def covariance(self) -> np.ndarray:
53
+ if not hasattr(self, "covariance_") or self.covariance_ is None:
54
+ raise NotFittedError()
55
+ return self.covariance_
56
+
57
+ @property
58
+ def correlation(self) -> np.ndarray:
59
+ if not hasattr(self, "correlation_"):
60
+ raise AttributeError("This estimator does not calculate correlation.")
61
+ return self.correlation_
62
+
63
+ def distance_distance_plot(
64
+ self, chi2_percentile: float = 0.975, figsize: tuple[int, int] = (10, 4)
65
+ ):
66
+ if not hasattr(self, "covariance_"):
67
+ raise NotFittedError()
68
+
69
+ fig, ax = plt.subplots(1, 1, figsize=figsize)
70
+
71
+ threshold = np.sqrt(chi2.ppf(chi2_percentile, self.n_features_in_))
72
+
73
+ ax.scatter(x=self._mahalanobis_distances, y=self._robust_distances)
74
+
75
+ ax.axhline(threshold, color="grey", linestyle="--")
76
+ ax.axvline(threshold, color="grey", linestyle="--")
77
+ ax.axline((0, 0), slope=1, color="grey", linestyle="-.")
78
+
79
+ ax.set_xlabel("Mahalanobis distance (default covariance)")
80
+ ax.set_ylabel("Robust distance")
81
+
82
+ return fig