chemotools 0.1.1__py3-none-any.whl → 0.1.3__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.
Files changed (46) hide show
  1. chemotools/{augmenation → augmentation}/baseline_shift.py +1 -1
  2. chemotools/{augmenation → augmentation}/index_shift.py +4 -3
  3. chemotools/baseline/__init__.py +8 -8
  4. chemotools/baseline/{air_pls.py → _air_pls.py} +5 -19
  5. chemotools/baseline/{ar_pls.py → _ar_pls.py} +2 -15
  6. chemotools/baseline/{constant_baseline_correction.py → _constant_baseline_correction.py} +6 -15
  7. chemotools/baseline/{cubic_spline_correction.py → _cubic_spline_correction.py} +11 -13
  8. chemotools/baseline/{linear_correction.py → _linear_correction.py} +2 -19
  9. chemotools/baseline/{non_negative.py → _non_negative.py} +2 -16
  10. chemotools/baseline/{polynomial_correction.py → _polynomial_correction.py} +13 -23
  11. chemotools/baseline/{subtract_reference.py → _subtract_reference.py} +7 -19
  12. chemotools/derivative/__init__.py +2 -2
  13. chemotools/derivative/{norris_william.py → _norris_william.py} +4 -17
  14. chemotools/derivative/{savitzky_golay.py → _savitzky_golay.py} +2 -16
  15. chemotools/feature_selection/__init__.py +2 -0
  16. chemotools/{variable_selection/select_features.py → feature_selection/_index_selector.py} +17 -42
  17. chemotools/{variable_selection/range_cut.py → feature_selection/_range_cut.py} +15 -44
  18. chemotools/scale/__init__.py +3 -3
  19. chemotools/scale/{min_max_scaler.py → _min_max_scaler.py} +7 -20
  20. chemotools/scale/{norm_scaler.py → _norm_scaler.py} +5 -18
  21. chemotools/scale/{point_scaler.py → _point_scaler.py} +11 -22
  22. chemotools/scatter/__init__.py +4 -4
  23. chemotools/scatter/{extended_multiplicative_scatter_correction.py → _extended_multiplicative_scatter_correction.py} +2 -10
  24. chemotools/scatter/{multiplicative_scatter_correction.py → _multiplicative_scatter_correction.py} +2 -8
  25. chemotools/scatter/{robust_normal_variate.py → _robust_normal_variate.py} +2 -16
  26. chemotools/scatter/{standard_normal_variate.py → _standard_normal_variate.py} +8 -19
  27. chemotools/smooth/__init__.py +4 -4
  28. chemotools/smooth/{mean_filter.py → _mean_filter.py} +5 -18
  29. chemotools/smooth/{median_filter.py → _median_filter.py} +2 -16
  30. chemotools/smooth/{savitzky_golay_filter.py → _savitzky_golay_filter.py} +3 -16
  31. chemotools/smooth/{whittaker_smooth.py → _whittaker_smooth.py} +5 -19
  32. {chemotools-0.1.1.dist-info → chemotools-0.1.3.dist-info}/METADATA +1 -1
  33. chemotools-0.1.3.dist-info/RECORD +58 -0
  34. {chemotools-0.1.1.dist-info → chemotools-0.1.3.dist-info}/WHEEL +1 -1
  35. tests/test_functionality.py +88 -56
  36. tests/test_sklearn_compliance.py +26 -25
  37. chemotools/augmenation/spectrum_shift.py +0 -110
  38. chemotools/variable_selection/__init__.py +0 -2
  39. chemotools-0.1.1.dist-info/RECORD +0 -59
  40. /chemotools/{augmenation → augmentation}/__init__.py +0 -0
  41. /chemotools/{augmenation → augmentation}/exponential_noise.py +0 -0
  42. /chemotools/{augmenation → augmentation}/normal_noise.py +0 -0
  43. /chemotools/{augmenation → augmentation}/spectrum_scale.py +0 -0
  44. /chemotools/{augmenation → augmentation}/uniform_noise.py +0 -0
  45. {chemotools-0.1.1.dist-info → chemotools-0.1.3.dist-info}/LICENSE +0 -0
  46. {chemotools-0.1.1.dist-info → chemotools-0.1.3.dist-info}/top_level.txt +0 -0
@@ -1,11 +1,13 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
2
+ from sklearn.base import BaseEstimator
3
+ from sklearn.feature_selection._base import SelectorMixin
4
+
3
5
  from sklearn.utils.validation import check_is_fitted
4
6
 
5
7
  from chemotools.utils.check_inputs import check_input
6
8
 
7
9
 
8
- class SelectFeatures(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
+ class IndexSelector(BaseEstimator, SelectorMixin):
9
11
  """
10
12
  A transformer that Selects the spectral data to a specified array of features. This
11
13
  array can be continuous or discontinuous. The array of features is specified by:
@@ -29,12 +31,6 @@ class SelectFeatures(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
29
31
  features_index_ : int
30
32
  The index of the features to select.
31
33
 
32
- n_features_in_ : int
33
- The number of features in the input data.
34
-
35
- _is_fitted : bool
36
- Whether the transformer has been fitted to data.
37
-
38
34
  Methods
39
35
  -------
40
36
  fit(X, y=None)
@@ -52,7 +48,7 @@ class SelectFeatures(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
52
48
  self.features = features
53
49
  self.wavenumbers = wavenumbers
54
50
 
55
- def fit(self, X: np.ndarray, y=None) -> "SelectFeatures":
51
+ def fit(self, X: np.ndarray, y=None) -> "IndexSelector":
56
52
  """
57
53
  Fit the transformer to the input data.
58
54
 
@@ -66,14 +62,11 @@ class SelectFeatures(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
66
62
 
67
63
  Returns
68
64
  -------
69
- self : SelectFeatures
65
+ self : IndexSelector
70
66
  The fitted transformer.
71
67
  """
72
- # Check that X is a 2D array and has only finite values
73
- X = check_input(X)
74
-
75
- # Set the number of features
76
- self.n_features_in_ = X.shape[1]
68
+ # validate that X is a 2D array and has only finite values
69
+ X = self._validate_data(X)
77
70
 
78
71
  # Set the fitted attribute to True
79
72
  self._is_fitted = True
@@ -91,41 +84,23 @@ class SelectFeatures(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
91
84
 
92
85
  return self
93
86
 
94
- def transform(self, X: np.ndarray, y=None) -> np.ndarray:
87
+ def _get_support_mask(self):
95
88
  """
96
- Transform the input data by cutting it to the specified range.
97
-
98
- Parameters
99
- ----------
100
- X : array-like of shape (n_samples, n_features)
101
- The input data to transform.
102
-
103
- y : None
104
- Ignored.
89
+ Get the boolean mask indicating which features are selected.
105
90
 
106
91
  Returns
107
92
  -------
108
- X_ : np.ndarray of shape (n_samples, n_features)
109
- The transformed data.
93
+ mask : ndarray of shape (n_features_in_,)
94
+ The mask indicating the selected features.
110
95
  """
111
96
  # Check that the estimator is fitted
112
- check_is_fitted(self, "_is_fitted")
97
+ check_is_fitted(self)
113
98
 
114
- # Check that X is a 2D array and has only finite values
115
- X = check_input(X)
116
- X_ = X.copy()
117
-
118
- # Check that the number of features is the same as the fitted data
119
- if X_.shape[1] != self.n_features_in_:
120
- raise ValueError(
121
- f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
122
- )
123
-
124
- # Select the features
125
- if self.features is None:
126
- return X_
99
+ # Create the mask
100
+ mask = np.zeros(self.n_features_in_, dtype=bool)
101
+ mask[self.features_index_] = True
127
102
 
128
- return X_[:, self.features_index_]
103
+ return mask
129
104
 
130
105
  def _find_index(self, target: float) -> int:
131
106
  if self.wavenumbers is None:
@@ -1,13 +1,12 @@
1
1
  import numpy as np
2
- from sklearn.base import BaseEstimator, TransformerMixin, OneToOneFeatureMixin
2
+ from sklearn.base import BaseEstimator
3
+ from sklearn.feature_selection._base import SelectorMixin
3
4
  from sklearn.utils.validation import check_is_fitted
4
5
 
5
- from chemotools.utils.check_inputs import check_input
6
6
 
7
-
8
- class RangeCut(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
7
+ class RangeCut(BaseEstimator, SelectorMixin):
9
8
  """
10
- A transformer that cuts the input data to a specified range. The range is specified:
9
+ A selector that cuts the input data to a specified range. The range is specified:
11
10
  - by the indices of the start and end of the range,
12
11
  - by the wavenumbers of the start and end of the range. In this case, the wavenumbers
13
12
  must be provided to the transformer when it is initialised. If the wavenumbers
@@ -35,19 +34,11 @@ class RangeCut(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
35
34
  end_index_ : int
36
35
  The index of the end of the range. It is -1 if the wavenumbers are not provided.
37
36
 
38
- n_features_in_ : int
39
- The number of features in the input data.
40
-
41
- _is_fitted : bool
42
- Whether the transformer has been fitted to data.
43
37
 
44
38
  Methods
45
39
  -------
46
40
  fit(X, y=None)
47
41
  Fit the transformer to the input data.
48
-
49
- transform(X, y=0, copy=True)
50
- Transform the input data by cutting it to the specified range.
51
42
  """
52
43
 
53
44
  def __init__(
@@ -78,13 +69,7 @@ class RangeCut(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
78
69
  The fitted transformer.
79
70
  """
80
71
  # Check that X is a 2D array and has only finite values
81
- X = check_input(X)
82
-
83
- # Set the number of features
84
- self.n_features_in_ = X.shape[1]
85
-
86
- # Set the fitted attribute to True
87
- self._is_fitted = True
72
+ X = self._validate_data(X)
88
73
 
89
74
  # Set the start and end indices
90
75
  if self.wavenumbers is None:
@@ -95,39 +80,25 @@ class RangeCut(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
95
80
  self.end_index_ = self._find_index(self.end)
96
81
 
97
82
  return self
83
+
98
84
 
99
- def transform(self, X: np.ndarray, y=None) -> np.ndarray:
85
+ def _get_support_mask(self):
100
86
  """
101
- Transform the input data by cutting it to the specified range.
102
-
103
- Parameters
104
- ----------
105
- X : array-like of shape (n_samples, n_features)
106
- The input data to transform.
107
-
108
- y : None
109
- Ignored.
87
+ Get the boolean mask indicating which features are selected.
110
88
 
111
89
  Returns
112
90
  -------
113
- X_ : np.ndarray of shape (n_samples, n_features)
114
- The transformed data.
91
+ mask : np.ndarray of shape (n_features,)
92
+ The boolean mask indicating which features are selected.
115
93
  """
116
94
  # Check that the estimator is fitted
117
- check_is_fitted(self, "_is_fitted")
118
-
119
- # Check that X is a 2D array and has only finite values
120
- X = check_input(X)
121
- X_ = X.copy()
95
+ check_is_fitted(self, ["start_index_", "end_index_"])
122
96
 
123
- # Check that the number of features is the same as the fitted data
124
- if X_.shape[1] != self.n_features_in_:
125
- raise ValueError(
126
- f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
127
- )
97
+ # Create the mask
98
+ mask = np.zeros(self.n_features_in_, dtype=bool)
99
+ mask[self.start_index_ : self.end_index_] = True
128
100
 
129
- # Range cut the spectra
130
- return X_[:, self.start_index_ : self.end_index_]
101
+ return mask
131
102
 
132
103
  def _find_index(self, target: float) -> int:
133
104
  wavenumbers = np.array(self.wavenumbers)
@@ -1,3 +1,3 @@
1
- from .min_max_scaler import MinMaxScaler
2
- from .norm_scaler import NormScaler
3
- from .point_scaler import PointScaler
1
+ from ._min_max_scaler import MinMaxScaler
2
+ from ._norm_scaler import NormScaler
3
+ from ._point_scaler import PointScaler
@@ -8,23 +8,15 @@ from chemotools.utils.check_inputs import check_input
8
8
  class MinMaxScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  """
10
10
  A transformer that scales the input data by subtracting the minimum and dividing by
11
- the difference between the maximum and the minimum. When the use_min parameter is False,
11
+ the difference between the maximum and the minimum. When the use_min parameter is False,
12
12
  the data is scaled by the maximum.
13
13
 
14
14
  Parameters
15
15
  ----------
16
16
  use_min : bool, default=True
17
- The normalization to use. If True, the data is subtracted by the minimum and
17
+ The normalization to use. If True, the data is subtracted by the minimum and
18
18
  scaled by the maximum. If False, the data is scaled by the maximum.
19
19
 
20
- Attributes
21
- ----------
22
- n_features_in_ : int
23
- The number of features in the input data.
24
-
25
- _is_fitted : bool
26
- Whether the transformer has been fitted to data.
27
-
28
20
  Methods
29
21
  -------
30
22
  fit(X, y=None)
@@ -55,13 +47,7 @@ class MinMaxScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
55
47
  The fitted transformer.
56
48
  """
57
49
  # Check that X is a 2D array and has only finite values
58
- X = check_input(X)
59
-
60
- # Set the number of features
61
- self.n_features_in_ = X.shape[1]
62
-
63
- # Set the fitted attribute to True
64
- self._is_fitted = True
50
+ X = self._validate_data(X)
65
51
 
66
52
  return self
67
53
 
@@ -83,7 +69,7 @@ class MinMaxScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
83
69
  The transformed data.
84
70
  """
85
71
  # Check that the estimator is fitted
86
- check_is_fitted(self, "_is_fitted")
72
+ check_is_fitted(self, "n_features_in_")
87
73
 
88
74
  # Check that X is a 2D array and has only finite values
89
75
  X = check_input(X)
@@ -97,8 +83,9 @@ class MinMaxScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
97
83
 
98
84
  # Normalize the data by the maximum value
99
85
  if self.use_min:
100
- X_ = (X_ - np.min(X_, axis=1, keepdims=True)) / (np.max(
101
- X_, axis=1, keepdims=True) - np.min(X_, axis=1, keepdims=True))
86
+ X_ = (X_ - np.min(X_, axis=1, keepdims=True)) / (
87
+ np.max(X_, axis=1, keepdims=True) - np.min(X_, axis=1, keepdims=True)
88
+ )
102
89
 
103
90
  else:
104
91
  X_ = X_ / np.max(X_, axis=1, keepdims=True)
@@ -12,15 +12,7 @@ class NormScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
12
12
  Parameters
13
13
  ----------
14
14
  l_norm : int, optional
15
- The L-norm to use. Default is 2.
16
-
17
- Attributes
18
- ----------
19
- n_features_in_ : int
20
- The number of features in the input data.
21
-
22
- _is_fitted : bool
23
- Whether the transformer has been fitted to data.
15
+ The L-norm to use. Default is 2.
24
16
 
25
17
  Methods
26
18
  -------
@@ -30,13 +22,14 @@ class NormScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
30
22
  transform(X, y=0, copy=True)
31
23
  Transform the input data by scaling by the L-norm.
32
24
  """
25
+
33
26
  def __init__(self, l_norm: int = 2):
34
27
  self.l_norm = l_norm
35
28
 
36
29
  def fit(self, X: np.ndarray, y=None) -> "NormScaler":
37
30
  """
38
31
  Fit the transformer to the input data.
39
-
32
+
40
33
  Parameters
41
34
  ----------
42
35
  X : np.ndarray of shape (n_samples, n_features)
@@ -51,13 +44,7 @@ class NormScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
51
44
  The fitted transformer.
52
45
  """
53
46
  # Check that X is a 2D array and has only finite values
54
- X = check_input(X)
55
-
56
- # Set the number of features
57
- self.n_features_in_ = X.shape[1]
58
-
59
- # Set the fitted attribute to True
60
- self._is_fitted = True
47
+ X = self._validate_data(X)
61
48
 
62
49
  return self
63
50
 
@@ -79,7 +66,7 @@ class NormScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
79
66
  The transformed data.
80
67
  """
81
68
  # Check that the estimator is fitted
82
- check_is_fitted(self, "_is_fitted")
69
+ check_is_fitted(self, "n_features_in_")
83
70
 
84
71
  # Check that X is a 2D array and has only finite values
85
72
  X = check_input(X)
@@ -7,12 +7,12 @@ from chemotools.utils.check_inputs import check_input
7
7
 
8
8
  class PointScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
9
  """
10
- A transformer that scales the input data by the intensity value at a given point.
10
+ A transformer that scales the input data by the intensity value at a given point.
11
11
  The point can be specified by an index or by a wavenumber.
12
12
 
13
13
  Parameters
14
14
  ----------
15
- point : int,
15
+ point : int,
16
16
  The point to scale the data by. It can be an index or a wavenumber.
17
17
 
18
18
  wavenumber : array-like, optional
@@ -25,12 +25,6 @@ class PointScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
25
25
  point_index_ : int
26
26
  The index of the point to scale the data by. It is 0 if the wavenumbers are not provided.
27
27
 
28
- n_features_in_ : int
29
- The number of features in the input data.
30
-
31
- _is_fitted : bool
32
- Whether the transformer has been fitted to data.
33
-
34
28
  Methods
35
29
  -------
36
30
  fit(X, y=None)
@@ -39,11 +33,11 @@ class PointScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
39
33
  transform(X, y=0, copy=True)
40
34
  Transform the input data by scaling by the value at a given Point.
41
35
  """
36
+
42
37
  def __init__(self, point: int = 0, wavenumbers: np.ndarray = None):
43
38
  self.point = point
44
39
  self.wavenumbers = wavenumbers
45
40
 
46
-
47
41
  def fit(self, X: np.ndarray, y=None) -> "PointScaler":
48
42
  """
49
43
  Fit the transformer to the input data.
@@ -62,13 +56,7 @@ class PointScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
62
56
  The fitted transformer.
63
57
  """
64
58
  # Check that X is a 2D array and has only finite values
65
- X = check_input(X)
66
-
67
- # Set the number of features
68
- self.n_features_in_ = X.shape[1]
69
-
70
- # Set the fitted attribute to True
71
- self._is_fitted = True
59
+ X = self._validate_data(X)
72
60
 
73
61
  # Set the point index
74
62
  if self.wavenumbers is None:
@@ -76,7 +64,6 @@ class PointScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
76
64
  else:
77
65
  self.point_index_ = self._find_index(self.point)
78
66
 
79
-
80
67
  return self
81
68
 
82
69
  def transform(self, X: np.ndarray, y=None) -> np.ndarray:
@@ -97,7 +84,7 @@ class PointScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
97
84
  The transformed data.
98
85
  """
99
86
  # Check that the estimator is fitted
100
- check_is_fitted(self, "_is_fitted")
87
+ check_is_fitted(self, "point_index_")
101
88
 
102
89
  # Check that X is a 2D array and has only finite values
103
90
  X = check_input(X)
@@ -105,14 +92,16 @@ class PointScaler(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
105
92
 
106
93
  # Check that the number of features is the same as the fitted data
107
94
  if X_.shape[1] != self.n_features_in_:
108
- raise ValueError(f"Expected {self.n_features_in_} features but got {X_.shape[1]}")
95
+ raise ValueError(
96
+ f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
97
+ )
109
98
 
110
99
  # Scale the data by Point
111
100
  for i, x in enumerate(X_):
112
101
  X_[i] = x / x[self.point_index_]
113
-
102
+
114
103
  return X_.reshape(-1, 1) if X_.ndim == 1 else X_
115
-
104
+
116
105
  def _find_index(self, target: float) -> int:
117
106
  wavenumbers = np.array(self.wavenumbers)
118
- return np.argmin(np.abs(wavenumbers - target))
107
+ return np.argmin(np.abs(wavenumbers - target))
@@ -1,4 +1,4 @@
1
- from .extended_multiplicative_scatter_correction import ExtendedMultiplicativeScatterCorrection
2
- from .multiplicative_scatter_correction import MultiplicativeScatterCorrection
3
- from .robust_normal_variate import RobustNormalVariate
4
- from .standard_normal_variate import StandardNormalVariate
1
+ from ._extended_multiplicative_scatter_correction import ExtendedMultiplicativeScatterCorrection
2
+ from ._multiplicative_scatter_correction import MultiplicativeScatterCorrection
3
+ from ._robust_normal_variate import RobustNormalVariate
4
+ from ._standard_normal_variate import StandardNormalVariate
@@ -37,8 +37,6 @@ class ExtendedMultiplicativeScatterCorrection(
37
37
  ----------
38
38
  reference_ : np.ndarray
39
39
  The reference spectrum used for the correction.
40
- n_features_in_ : int
41
- The number of features in the training data.
42
40
 
43
41
  References
44
42
  ----------
@@ -82,13 +80,7 @@ class ExtendedMultiplicativeScatterCorrection(
82
80
  The fitted transformer.
83
81
  """
84
82
  # Check that X is a 2D array and has only finite values
85
- X = check_input(X)
86
-
87
- # Set the number of features
88
- self.n_features_in_ = X.shape[1]
89
-
90
- # Set the fitted attribute to True
91
- self._is_fitted = True
83
+ X = self._validate_data(X)
92
84
 
93
85
  # Check that the length of the reference is the same as the number of features
94
86
  if self.reference is not None:
@@ -146,7 +138,7 @@ class ExtendedMultiplicativeScatterCorrection(
146
138
  The transformed data.
147
139
  """
148
140
  # Check that the estimator is fitted
149
- check_is_fitted(self, "_is_fitted")
141
+ check_is_fitted(self, "n_features_in_")
150
142
 
151
143
  # Check that X is a 2D array and has only finite values
152
144
  X = check_input(X)
@@ -68,13 +68,7 @@ class MultiplicativeScatterCorrection(
68
68
  The fitted transformer.
69
69
  """
70
70
  # Check that X is a 2D array and has only finite values
71
- X = check_input(X)
72
-
73
- # Set the number of features
74
- self.n_features_in_ = X.shape[1]
75
-
76
- # Set the fitted attribute to True
77
- self._is_fitted = True
71
+ X = self._validate_data(X)
78
72
 
79
73
  # Check that the length of the reference is the same as the number of features
80
74
  if self.reference is not None:
@@ -129,7 +123,7 @@ class MultiplicativeScatterCorrection(
129
123
  The transformed data.
130
124
  """
131
125
  # Check that the estimator is fitted
132
- check_is_fitted(self, "_is_fitted")
126
+ check_is_fitted(self, "n_features_in_")
133
127
 
134
128
  # Check that X is a 2D array and has only finite values
135
129
  X = check_input(X)
@@ -15,14 +15,6 @@ class RobustNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixin)
15
15
  The percentile to use for the robust normal variate. The value should be
16
16
  between 0 and 100. The default is 25.
17
17
 
18
- Attributes
19
- ----------
20
- n_features_in_ : int
21
- The number of features in the input data.
22
-
23
- _is_fitted : bool
24
- Whether the transformer has been fitted to data.
25
-
26
18
  Methods
27
19
  -------
28
20
  fit(X, y=None)
@@ -58,13 +50,7 @@ class RobustNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixin)
58
50
  The fitted transformer.
59
51
  """
60
52
  # Check that X is a 2D array and has only finite values
61
- X = check_input(X)
62
-
63
- # Set the number of features
64
- self.n_features_in_ = X.shape[1]
65
-
66
- # Set the fitted attribute to True
67
- self._is_fitted = True
53
+ X = self._validate_data(X)
68
54
 
69
55
  return self
70
56
 
@@ -86,7 +72,7 @@ class RobustNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixin)
86
72
  The transformed data.
87
73
  """
88
74
  # Check that the estimator is fitted
89
- check_is_fitted(self, "_is_fitted")
75
+ check_is_fitted(self, "n_features_in_")
90
76
 
91
77
  # Check that X is a 2D array and has only finite values
92
78
  X = check_input(X)
@@ -9,14 +9,6 @@ class StandardNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
9
9
  """
10
10
  A transformer that calculates the standard normal variate of the input data.
11
11
 
12
- Attributes
13
- ----------
14
- n_features_in_ : int
15
- The number of features in the input data.
16
-
17
- _is_fitted : bool
18
- Whether the transformer has been fitted to data.
19
-
20
12
  Methods
21
13
  -------
22
14
  fit(X, y=None)
@@ -25,10 +17,11 @@ class StandardNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
25
17
  transform(X, y=0, copy=True)
26
18
  Transform the input data by calculating the standard normal variate.
27
19
  """
20
+
28
21
  def fit(self, X: np.ndarray, y=None) -> "StandardNormalVariate":
29
22
  """
30
23
  Fit the transformer to the input data.
31
-
24
+
32
25
  Parameters
33
26
  ----------
34
27
  X : np.ndarray of shape (n_samples, n_features)
@@ -43,13 +36,7 @@ class StandardNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
43
36
  The fitted transformer.
44
37
  """
45
38
  # Check that X is a 2D array and has only finite values
46
- X = check_input(X)
47
-
48
- # Set the number of features
49
- self.n_features_in_ = X.shape[1]
50
-
51
- # Set the fitted attribute to True
52
- self._is_fitted = True
39
+ X = self._validate_data(X)
53
40
 
54
41
  return self
55
42
 
@@ -71,7 +58,7 @@ class StandardNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
71
58
  The transformed data.
72
59
  """
73
60
  # Check that the estimator is fitted
74
- check_is_fitted(self, "_is_fitted")
61
+ check_is_fitted(self, "n_features_in_")
75
62
 
76
63
  # Check that X is a 2D array and has only finite values
77
64
  X = check_input(X)
@@ -79,7 +66,9 @@ class StandardNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
79
66
 
80
67
  # Check that the number of features is the same as the fitted data
81
68
  if X_.shape[1] != self.n_features_in_:
82
- raise ValueError(f"Expected {self.n_features_in_} features but got {X_.shape[1]}")
69
+ raise ValueError(
70
+ f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
71
+ )
83
72
 
84
73
  # Calculate the standard normal variate
85
74
  for i, x in enumerate(X_):
@@ -88,4 +77,4 @@ class StandardNormalVariate(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
88
77
  return X_.reshape(-1, 1) if X_.ndim == 1 else X_
89
78
 
90
79
  def _calculate_standard_normal_variate(self, x) -> np.ndarray:
91
- return (x - x.mean()) / x.std()
80
+ return (x - x.mean()) / x.std()
@@ -1,4 +1,4 @@
1
- from .mean_filter import MeanFilter
2
- from .median_filter import MedianFilter
3
- from .savitzky_golay_filter import SavitzkyGolayFilter
4
- from .whittaker_smooth import WhittakerSmooth
1
+ from ._mean_filter import MeanFilter
2
+ from ._median_filter import MedianFilter
3
+ from ._savitzky_golay_filter import SavitzkyGolayFilter
4
+ from ._whittaker_smooth import WhittakerSmooth
@@ -14,19 +14,11 @@ class MeanFilter(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
14
14
  ----------
15
15
  window_size : int, optional
16
16
  The size of the window to use for the mean filter. Must be odd. Default is 3.
17
-
17
+
18
18
  mode : str, optional
19
19
  The mode to use for the mean filter. Can be "nearest", "constant", "reflect",
20
20
  "wrap", "mirror" or "interp". Default is "nearest".
21
21
 
22
- Attributes
23
- ----------
24
- n_features_in_ : int
25
- The number of features in the input data.
26
-
27
- _is_fitted : bool
28
- Whether the transformer has been fitted to data.
29
-
30
22
  Methods
31
23
  -------
32
24
  fit(X, y=None)
@@ -35,7 +27,8 @@ class MeanFilter(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
35
27
  transform(X, y=0, copy=True)
36
28
  Transform the input data by calculating the mean filter.
37
29
  """
38
- def __init__(self, window_size: int = 3, mode='nearest') -> None:
30
+
31
+ def __init__(self, window_size: int = 3, mode="nearest") -> None:
39
32
  self.window_size = window_size
40
33
  self.mode = mode
41
34
 
@@ -57,13 +50,7 @@ class MeanFilter(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
57
50
  The fitted transformer.
58
51
  """
59
52
  # Check that X is a 2D array and has only finite values
60
- X = check_input(X)
61
-
62
- # Set the number of features
63
- self.n_features_in_ = X.shape[1]
64
-
65
- # Set the fitted attribute to True
66
- self._is_fitted = True
53
+ X = self._validate_data(X)
67
54
 
68
55
  return self
69
56
 
@@ -85,7 +72,7 @@ class MeanFilter(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
85
72
  The transformed data.
86
73
  """
87
74
  # Check that the estimator is fitted
88
- check_is_fitted(self, "_is_fitted")
75
+ check_is_fitted(self, "n_features_in_")
89
76
 
90
77
  # Check that X is a 2D array and has only finite values
91
78
  X = check_input(X)