chemotools 0.1.2__tar.gz → 0.1.4__tar.gz

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 (69) hide show
  1. {chemotools-0.1.2 → chemotools-0.1.4}/PKG-INFO +1 -1
  2. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/augmentation/uniform_noise.py +6 -6
  3. chemotools-0.1.4/chemotools/baseline/__init__.py +8 -0
  4. chemotools-0.1.2/chemotools/baseline/air_pls.py → chemotools-0.1.4/chemotools/baseline/_air_pls.py +2 -16
  5. chemotools-0.1.2/chemotools/baseline/ar_pls.py → chemotools-0.1.4/chemotools/baseline/_ar_pls.py +2 -15
  6. chemotools-0.1.2/chemotools/baseline/constant_baseline_correction.py → chemotools-0.1.4/chemotools/baseline/_constant_baseline_correction.py +6 -15
  7. chemotools-0.1.2/chemotools/baseline/cubic_spline_correction.py → chemotools-0.1.4/chemotools/baseline/_cubic_spline_correction.py +11 -13
  8. chemotools-0.1.2/chemotools/baseline/linear_correction.py → chemotools-0.1.4/chemotools/baseline/_linear_correction.py +2 -19
  9. chemotools-0.1.2/chemotools/baseline/non_negative.py → chemotools-0.1.4/chemotools/baseline/_non_negative.py +2 -16
  10. chemotools-0.1.2/chemotools/baseline/polynomial_correction.py → chemotools-0.1.4/chemotools/baseline/_polynomial_correction.py +13 -23
  11. chemotools-0.1.2/chemotools/baseline/subtract_reference.py → chemotools-0.1.4/chemotools/baseline/_subtract_reference.py +7 -19
  12. chemotools-0.1.4/chemotools/derivative/__init__.py +2 -0
  13. chemotools-0.1.2/chemotools/derivative/norris_william.py → chemotools-0.1.4/chemotools/derivative/_norris_william.py +4 -17
  14. chemotools-0.1.2/chemotools/derivative/savitzky_golay.py → chemotools-0.1.4/chemotools/derivative/_savitzky_golay.py +2 -16
  15. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/feature_selection/_index_selector.py +1 -7
  16. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/feature_selection/_range_cut.py +1 -0
  17. chemotools-0.1.4/chemotools/scale/__init__.py +3 -0
  18. chemotools-0.1.2/chemotools/scale/min_max_scaler.py → chemotools-0.1.4/chemotools/scale/_min_max_scaler.py +7 -20
  19. chemotools-0.1.2/chemotools/scale/norm_scaler.py → chemotools-0.1.4/chemotools/scale/_norm_scaler.py +5 -18
  20. chemotools-0.1.2/chemotools/scale/point_scaler.py → chemotools-0.1.4/chemotools/scale/_point_scaler.py +11 -22
  21. chemotools-0.1.4/chemotools/scatter/__init__.py +4 -0
  22. chemotools-0.1.2/chemotools/scatter/extended_multiplicative_scatter_correction.py → chemotools-0.1.4/chemotools/scatter/_extended_multiplicative_scatter_correction.py +2 -10
  23. chemotools-0.1.2/chemotools/scatter/multiplicative_scatter_correction.py → chemotools-0.1.4/chemotools/scatter/_multiplicative_scatter_correction.py +2 -8
  24. chemotools-0.1.2/chemotools/scatter/robust_normal_variate.py → chemotools-0.1.4/chemotools/scatter/_robust_normal_variate.py +2 -16
  25. chemotools-0.1.2/chemotools/scatter/standard_normal_variate.py → chemotools-0.1.4/chemotools/scatter/_standard_normal_variate.py +8 -19
  26. chemotools-0.1.4/chemotools/smooth/__init__.py +4 -0
  27. chemotools-0.1.2/chemotools/smooth/mean_filter.py → chemotools-0.1.4/chemotools/smooth/_mean_filter.py +5 -18
  28. chemotools-0.1.2/chemotools/smooth/median_filter.py → chemotools-0.1.4/chemotools/smooth/_median_filter.py +2 -16
  29. chemotools-0.1.2/chemotools/smooth/savitzky_golay_filter.py → chemotools-0.1.4/chemotools/smooth/_savitzky_golay_filter.py +3 -16
  30. chemotools-0.1.2/chemotools/smooth/whittaker_smooth.py → chemotools-0.1.4/chemotools/smooth/_whittaker_smooth.py +2 -16
  31. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools.egg-info/PKG-INFO +1 -1
  32. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools.egg-info/SOURCES.txt +21 -21
  33. {chemotools-0.1.2 → chemotools-0.1.4}/tests/test_functionality.py +2 -1
  34. chemotools-0.1.2/chemotools/baseline/__init__.py +0 -8
  35. chemotools-0.1.2/chemotools/derivative/__init__.py +0 -2
  36. chemotools-0.1.2/chemotools/scale/__init__.py +0 -3
  37. chemotools-0.1.2/chemotools/scatter/__init__.py +0 -4
  38. chemotools-0.1.2/chemotools/smooth/__init__.py +0 -4
  39. {chemotools-0.1.2 → chemotools-0.1.4}/LICENSE +0 -0
  40. {chemotools-0.1.2 → chemotools-0.1.4}/README.md +0 -0
  41. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/__init__.py +0 -0
  42. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/augmentation/__init__.py +0 -0
  43. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/augmentation/baseline_shift.py +0 -0
  44. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/augmentation/exponential_noise.py +0 -0
  45. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/augmentation/index_shift.py +0 -0
  46. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/augmentation/normal_noise.py +0 -0
  47. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/augmentation/spectrum_scale.py +0 -0
  48. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/__init__.py +0 -0
  49. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/_base.py +0 -0
  50. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/data/__init__.py +0 -0
  51. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/data/coffee_labels.csv +0 -0
  52. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/data/coffee_spectra.csv +0 -0
  53. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/data/fermentation_hplc.csv +0 -0
  54. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/data/fermentation_spectra.csv +0 -0
  55. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/data/train_hplc.csv +0 -0
  56. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/datasets/data/train_spectra.csv +0 -0
  57. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/feature_selection/__init__.py +0 -0
  58. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/utils/__init__.py +0 -0
  59. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools/utils/check_inputs.py +0 -0
  60. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools.egg-info/dependency_links.txt +0 -0
  61. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools.egg-info/requires.txt +0 -0
  62. {chemotools-0.1.2 → chemotools-0.1.4}/chemotools.egg-info/top_level.txt +0 -0
  63. {chemotools-0.1.2 → chemotools-0.1.4}/pyproject.toml +0 -0
  64. {chemotools-0.1.2 → chemotools-0.1.4}/setup.cfg +0 -0
  65. {chemotools-0.1.2 → chemotools-0.1.4}/setup.py +0 -0
  66. {chemotools-0.1.2 → chemotools-0.1.4}/tests/__init__.py +0 -0
  67. {chemotools-0.1.2 → chemotools-0.1.4}/tests/fixtures.py +0 -0
  68. {chemotools-0.1.2 → chemotools-0.1.4}/tests/test_datasets.py +0 -0
  69. {chemotools-0.1.2 → chemotools-0.1.4}/tests/test_sklearn_compliance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: chemotools
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: Package to integrate chemometrics in scikit-learn pipelines
5
5
  Home-page: https://github.com/paucablop/chemotools
6
6
  Author: Pau Cabaneros Lopez
@@ -11,10 +11,10 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
11
11
 
12
12
  Parameters
13
13
  ----------
14
- low : float, default=0.0
14
+ min : float, default=0.0
15
15
  The lower bound of the uniform distribution.
16
16
 
17
- high : float, default=0.0
17
+ max : float, default=0.0
18
18
  The upper bound of the uniform distribution.
19
19
 
20
20
  random_state : int, default=None
@@ -38,9 +38,9 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
38
38
  """
39
39
 
40
40
 
41
- def __init__(self, low: float = 0.0, high: float = 0.0, random_state: int = None):
42
- self.low = low
43
- self.high = high
41
+ def __init__(self, min: float = 0.0, max: float = 0.0, random_state: int = None):
42
+ self.min = min
43
+ self.max = max
44
44
  self.random_state = random_state
45
45
 
46
46
  def fit(self, X: np.ndarray, y=None) -> "UniformNoise":
@@ -109,4 +109,4 @@ class UniformNoise(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
109
109
  return X_.reshape(-1, 1) if X_.ndim == 1 else X_
110
110
 
111
111
  def _add_random_noise(self, x) -> np.ndarray:
112
- return x + self._rng.uniform(self.low, self.high, size=x.shape)
112
+ return x + self._rng.uniform(self.min, self.max, size=x.shape)
@@ -0,0 +1,8 @@
1
+ from ._air_pls import AirPls
2
+ from ._ar_pls import ArPls
3
+ from ._constant_baseline_correction import ConstantBaselineCorrection
4
+ from ._cubic_spline_correction import CubicSplineCorrection
5
+ from ._linear_correction import LinearCorrection
6
+ from ._non_negative import NonNegative
7
+ from ._polynomial_correction import PolynomialCorrection
8
+ from ._subtract_reference import SubtractReference
@@ -30,14 +30,6 @@ class AirPls(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
30
30
  The number of iterations used to calculate the baseline. Increasing the number of iterations can improve the
31
31
  accuracy of the baseline correction, but also increases the computation time.
32
32
 
33
- Attributes
34
- ----------
35
- n_features_in_ : int
36
- The number of features in the input data.
37
-
38
- _is_fitted : bool
39
- A flag indicating whether the estimator has been fitted to data.
40
-
41
33
  Methods
42
34
  -------
43
35
  fit(X, y=None)
@@ -85,13 +77,7 @@ class AirPls(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
85
77
  Returns the instance itself.
86
78
  """
87
79
  # Check that X is a 2D array and has only finite values
88
- X = check_input(X)
89
-
90
- # Set the number of features
91
- self.n_features_in_ = X.shape[1]
92
-
93
- # Set the fitted attribute to True
94
- self._is_fitted = True
80
+ X = self._validate_data(X)
95
81
 
96
82
  return self
97
83
 
@@ -113,7 +99,7 @@ class AirPls(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
113
99
  """
114
100
 
115
101
  # Check that the estimator is fitted
116
- check_is_fitted(self, "_is_fitted")
102
+ check_is_fitted(self, "n_features_in_")
117
103
 
118
104
  # Check that X is a 2D array and has only finite values
119
105
  X = check_input(X)
@@ -29,13 +29,6 @@ class ArPls(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
29
29
  nr_iterations : int, optional (default=100)
30
30
  The maximum number of iterations for the weight updating scheme.
31
31
 
32
- Attributes
33
- ----------
34
- n_features_in_ : int
35
- The number of input features.
36
-
37
- _is_fitted : bool
38
- Whether the estimator has been fitted.
39
32
 
40
33
  Methods
41
34
  -------
@@ -86,13 +79,7 @@ class ArPls(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
86
79
  """
87
80
 
88
81
  # Check that X is a 2D array and has only finite values
89
- X = check_input(X)
90
-
91
- # Set the number of features
92
- self.n_features_in_ = X.shape[1]
93
-
94
- # Set the fitted attribute to True
95
- self._is_fitted = True
82
+ X = self._validate_data(X)
96
83
 
97
84
  return self
98
85
 
@@ -114,7 +101,7 @@ class ArPls(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
114
101
  """
115
102
 
116
103
  # Check that the estimator is fitted
117
- check_is_fitted(self, "_is_fitted")
104
+ check_is_fitted(self, "n_features_in_")
118
105
 
119
106
  # Check that X is a 2D array and has only finite values
120
107
  X = check_input(X)
@@ -30,12 +30,6 @@ class ConstantBaselineCorrection(OneToOneFeatureMixin, BaseEstimator, Transforme
30
30
  end_index_ : int
31
31
  The index of the end of the range. It is 1 if the wavenumbers are not provided.
32
32
 
33
- n_features_in_ : int
34
- The number of features in the input data.
35
-
36
- _is_fitted : bool
37
- Whether the transformer has been fitted to data.
38
-
39
33
  Methods
40
34
  -------
41
35
  fit(X, y=None)
@@ -46,7 +40,10 @@ class ConstantBaselineCorrection(OneToOneFeatureMixin, BaseEstimator, Transforme
46
40
  """
47
41
 
48
42
  def __init__(
49
- self, start: int = 0, end: int = 1, wavenumbers: np.ndarray = None,
43
+ self,
44
+ start: int = 0,
45
+ end: int = 1,
46
+ wavenumbers: np.ndarray = None,
50
47
  ) -> None:
51
48
  self.start = start
52
49
  self.end = end
@@ -70,13 +67,7 @@ class ConstantBaselineCorrection(OneToOneFeatureMixin, BaseEstimator, Transforme
70
67
  The fitted transformer.
71
68
  """
72
69
  # 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]
77
-
78
- # Set the fitted attribute to True
79
- self._is_fitted = True
70
+ X = self._validate_data(X)
80
71
 
81
72
  # Set the start and end indices
82
73
  if self.wavenumbers is None:
@@ -109,7 +100,7 @@ class ConstantBaselineCorrection(OneToOneFeatureMixin, BaseEstimator, Transforme
109
100
  The transformed input data.
110
101
  """
111
102
  # Check that the estimator is fitted
112
- check_is_fitted(self, "_is_fitted")
103
+ check_is_fitted(self, ["start_index_", "end_index_"])
113
104
 
114
105
  # Check that X is a 2D array and has only finite values
115
106
  X = check_input(X)
@@ -5,9 +5,10 @@ from sklearn.utils.validation import check_is_fitted
5
5
 
6
6
  from chemotools.utils.check_inputs import check_input
7
7
 
8
+
8
9
  class CubicSplineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
9
10
  """
10
- A transformer that corrects a baseline by subtracting a cubic spline through the
11
+ A transformer that corrects a baseline by subtracting a cubic spline through the
11
12
  points defined by the indices.
12
13
 
13
14
  Parameters
@@ -32,6 +33,7 @@ class CubicSplineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
32
33
  Transform the input data by subtracting the constant baseline value.
33
34
 
34
35
  """
36
+
35
37
  def __init__(self, indices: list = None) -> None:
36
38
  self.indices = indices
37
39
 
@@ -53,13 +55,7 @@ class CubicSplineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
53
55
  The fitted transformer.
54
56
  """
55
57
  # Check that X is a 2D array and has only finite values
56
- X = check_input(X)
57
-
58
- # Set the number of features
59
- self.n_features_in_ = X.shape[1]
60
-
61
- # Set the fitted attribute to True
62
- self._is_fitted = True
58
+ X = self._validate_data(X)
63
59
 
64
60
  if self.indices is None:
65
61
  self.indices_ = [0, len(X[0]) - 1]
@@ -89,7 +85,7 @@ class CubicSplineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
89
85
  The transformed data.
90
86
  """
91
87
  # Check that the estimator is fitted
92
- check_is_fitted(self, "_is_fitted")
88
+ check_is_fitted(self, "indices_")
93
89
 
94
90
  # Check that X is a 2D array and has only finite values
95
91
  X = check_input(X)
@@ -97,7 +93,9 @@ class CubicSplineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
97
93
 
98
94
  # Check that the number of features is the same as the fitted data
99
95
  if X_.shape[1] != self.n_features_in_:
100
- raise ValueError(f"Expected {self.n_features_in_} features but got {X_.shape[1]}")
96
+ raise ValueError(
97
+ f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
98
+ )
101
99
 
102
100
  # Calculate spline baseline correction
103
101
  for i, x in enumerate(X_):
@@ -106,7 +104,7 @@ class CubicSplineCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixi
106
104
 
107
105
  def _spline_baseline_correct(self, x: np.ndarray) -> np.ndarray:
108
106
  indices = self.indices_
109
- intensity = x[indices]
107
+ intensity = x[indices]
110
108
  spl = CubicSpline(indices, intensity)
111
- baseline = spl(range(len(x)))
112
- return x - baseline
109
+ baseline = spl(range(len(x)))
110
+ return x - baseline
@@ -10,17 +10,6 @@ class LinearCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
10
10
  A transformer that corrects a baseline by subtracting a linear baseline through the
11
11
  initial and final points of the spectrum.
12
12
 
13
- Parameters
14
- ----------
15
-
16
- Attributes
17
- ----------
18
- n_features_in_ : int
19
- The number of features in the input data.
20
-
21
- _is_fitted : bool
22
- Whether the transformer has been fitted to data.
23
-
24
13
  Methods
25
14
  -------
26
15
  fit(X, y=None)
@@ -68,13 +57,7 @@ class LinearCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
68
57
  The fitted transformer.
69
58
  """
70
59
  # 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
60
+ X = self._validate_data(X)
78
61
 
79
62
  return self
80
63
 
@@ -99,7 +82,7 @@ class LinearCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
99
82
  The transformed data.
100
83
  """
101
84
  # Check that the estimator is fitted
102
- check_is_fitted(self, "_is_fitted")
85
+ check_is_fitted(self, "n_features_in_")
103
86
 
104
87
  # Check that X is a 2D array and has only finite values
105
88
  X = check_input(X)
@@ -14,14 +14,6 @@ class NonNegative(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
14
14
  mode : str, optional
15
15
  The mode to use for the non-negative values. Can be "zero" or "abs".
16
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.
24
-
25
17
  Methods
26
18
  -------
27
19
  fit(X, y=None)
@@ -52,13 +44,7 @@ class NonNegative(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
52
44
  The fitted transformer.
53
45
  """
54
46
  # Check that X is a 2D array and has only finite values
55
- X = check_input(X)
56
-
57
- # Set the number of features
58
- self.n_features_in_ = X.shape[1]
59
-
60
- # Set the fitted attribute to True
61
- self._is_fitted = True
47
+ X = self._validate_data(X)
62
48
 
63
49
  return self
64
50
 
@@ -80,7 +66,7 @@ class NonNegative(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
80
66
  The transformed data.
81
67
  """
82
68
  # Check that the estimator is fitted
83
- check_is_fitted(self, "_is_fitted")
69
+ check_is_fitted(self, "n_features_in_")
84
70
 
85
71
  # Check that X is a 2D array and has only finite values
86
72
  X = check_input(X)
@@ -4,9 +4,10 @@ from sklearn.utils.validation import check_is_fitted
4
4
 
5
5
  from chemotools.utils.check_inputs import check_input
6
6
 
7
+
7
8
  class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
8
9
  """
9
- A transformer that subtracts a polynomial baseline from the input data. The polynomial is
10
+ A transformer that subtracts a polynomial baseline from the input data. The polynomial is
10
11
  fitted to the points in the spectrum specified by the indices parameter.
11
12
 
12
13
  Parameters
@@ -18,14 +19,6 @@ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin
18
19
  The indices of the points in the spectrum to fit the polynomial to. Defaults to None,
19
20
  which fits the polynomial to all points in the spectrum (equivalent to detrend).
20
21
 
21
- Attributes
22
- ----------
23
- n_features_in_ : int
24
- The number of features in the input data.
25
-
26
- _is_fitted : bool
27
- Whether the transformer has been fitted to data.
28
-
29
22
  Methods
30
23
  -------
31
24
  fit(X, y=None)
@@ -37,6 +30,7 @@ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin
37
30
  _baseline_correct_spectrum(x)
38
31
  Subtract the polynomial baseline from a single spectrum.
39
32
  """
33
+
40
34
  def __init__(self, order: int = 1, indices: list = None) -> None:
41
35
  self.order = order
42
36
  self.indices = indices
@@ -59,13 +53,7 @@ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin
59
53
  The fitted transformer.
60
54
  """
61
55
  # Check that X is a 2D array and has only finite values
62
- X = check_input(X)
63
-
64
- # Set the number of features
65
- self.n_features_in_ = X.shape[1]
66
-
67
- # Set the fitted attribute to True
68
- self._is_fitted = True
56
+ X = self._validate_data(X)
69
57
 
70
58
  if self.indices is None:
71
59
  self.indices_ = range(0, len(X[0]))
@@ -73,8 +61,8 @@ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin
73
61
  self.indices_ = self.indices
74
62
 
75
63
  return self
76
-
77
- def transform(self, X: np.ndarray, y:int=0, copy:bool=True) -> np.ndarray:
64
+
65
+ def transform(self, X: np.ndarray, y: int = 0, copy: bool = True) -> np.ndarray:
78
66
  """
79
67
  Transform the input data by subtracting the polynomial baseline.
80
68
 
@@ -95,7 +83,7 @@ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin
95
83
  The transformed data.
96
84
  """
97
85
  # Check that the estimator is fitted
98
- check_is_fitted(self, "_is_fitted")
86
+ check_is_fitted(self, "indices_")
99
87
 
100
88
  # Check that X is a 2D array and has only finite values
101
89
  X = check_input(X)
@@ -103,13 +91,15 @@ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin
103
91
 
104
92
  # Check that the number of features is the same as the fitted data
105
93
  if X_.shape[1] != self.n_features_in_:
106
- raise ValueError(f"Expected {self.n_features_in_} features but got {X_.shape[1]}")
94
+ raise ValueError(
95
+ f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
96
+ )
107
97
 
108
98
  # Calculate polynomial baseline correction
109
99
  for i, x in enumerate(X_):
110
100
  X_[i] = self._baseline_correct_spectrum(x)
111
101
  return X_.reshape(-1, 1) if X_.ndim == 1 else X_
112
-
102
+
113
103
  def _baseline_correct_spectrum(self, x: np.ndarray) -> np.ndarray:
114
104
  """
115
105
  Subtract the polynomial baseline from a single spectrum.
@@ -126,5 +116,5 @@ class PolynomialCorrection(OneToOneFeatureMixin, BaseEstimator, TransformerMixin
126
116
  """
127
117
  intensity = x[self.indices_]
128
118
  poly = np.polyfit(self.indices_, intensity, self.order)
129
- baseline = [np.polyval(poly, i) for i in range(0, len(x))]
130
- return x - baseline
119
+ baseline = [np.polyval(poly, i) for i in range(0, len(x))]
120
+ return x - baseline
@@ -15,14 +15,6 @@ class SubtractReference(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
15
15
  The reference spectrum to subtract from the input data. If None, the original spectrum
16
16
  is returned.
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)
@@ -34,6 +26,7 @@ class SubtractReference(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
34
26
  _subtract_reference(x)
35
27
  Subtract the reference spectrum from a single spectrum.
36
28
  """
29
+
37
30
  def __init__(
38
31
  self,
39
32
  reference: np.ndarray = None,
@@ -58,20 +51,13 @@ class SubtractReference(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
58
51
  The fitted transformer.
59
52
  """
60
53
  # 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
54
+ X = self._validate_data(X)
68
55
 
69
56
  # Set the reference
70
-
71
57
  if self.reference is not None:
72
58
  self.reference_ = self.reference.copy()
73
59
  return self
74
-
60
+
75
61
  return self
76
62
 
77
63
  def transform(self, X: np.ndarray, y=None) -> np.ndarray:
@@ -92,7 +78,7 @@ class SubtractReference(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
92
78
  The transformed data.
93
79
  """
94
80
  # Check that the estimator is fitted
95
- check_is_fitted(self, "_is_fitted")
81
+ check_is_fitted(self, "n_features_in_")
96
82
 
97
83
  # Check that X is a 2D array and has only finite values
98
84
  X = check_input(X)
@@ -100,7 +86,9 @@ class SubtractReference(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
100
86
 
101
87
  # Check that the number of features is the same as the fitted data
102
88
  if X_.shape[1] != self.n_features_in_:
103
- raise ValueError(f"Expected {self.n_features_in_} features but got {X_.shape[1]}")
89
+ raise ValueError(
90
+ f"Expected {self.n_features_in_} features but got {X_.shape[1]}"
91
+ )
104
92
 
105
93
  if self.reference is None:
106
94
  return X_.reshape(-1, 1) if X_.ndim == 1 else X_
@@ -0,0 +1,2 @@
1
+ from ._norris_william import NorrisWilliams
2
+ from ._savitzky_golay import SavitzkyGolay
@@ -22,17 +22,9 @@ class NorrisWilliams(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
22
22
  The order of the derivative to calculate. Can be 1 or 2. Default is 1.
23
23
 
24
24
  mode : str, optional
25
- The mode to use for the derivative calculation. Can be "nearest", "constant",
25
+ The mode to use for the derivative calculation. Can be "nearest", "constant",
26
26
  "reflect", "wrap", "mirror" or "interp". Default is "nearest".
27
27
 
28
- Attributes
29
- ----------
30
- n_features_in_ : int
31
- The number of features in the input data.
32
-
33
- _is_fitted : bool
34
- Whether the transformer has been fitted to data.
35
-
36
28
  Methods
37
29
  -------
38
30
  fit(X, y=None)
@@ -41,6 +33,7 @@ class NorrisWilliams(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
41
33
  transform(X, y=0, copy=True)
42
34
  Transform the input data by calculating the Norris-Williams derivative.
43
35
  """
36
+
44
37
  def __init__(
45
38
  self,
46
39
  window_size: int = 5,
@@ -71,13 +64,7 @@ class NorrisWilliams(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
71
64
  The fitted transformer.
72
65
  """
73
66
  # Check that X is a 2D array and has only finite values
74
- X = check_input(X)
75
-
76
- # Set the number of features
77
- self.n_features_in_ = X.shape[1]
78
-
79
- # Set the fitted attribute to True
80
- self._is_fitted = True
67
+ X = self._validate_data(X)
81
68
 
82
69
  return self
83
70
 
@@ -99,7 +86,7 @@ class NorrisWilliams(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
99
86
  The transformed data.
100
87
  """
101
88
  # Check that the estimator is fitted
102
- check_is_fitted(self, "_is_fitted")
89
+ check_is_fitted(self, "n_features_in_")
103
90
 
104
91
  # Check that X is a 2D array and has only finite values
105
92
  X = check_input(X)
@@ -27,14 +27,6 @@ class SavitzkyGolay(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
27
27
  The mode to use for the derivative calculation. Can be "nearest", "constant",
28
28
  "reflect", "wrap", "mirror" or "interp". Default is "nearest".
29
29
 
30
- Attributes
31
- ----------
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
30
  Methods
39
31
  -------
40
32
  fit(X, y=None)
@@ -74,13 +66,7 @@ class SavitzkyGolay(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
74
66
  The fitted transformer.
75
67
  """
76
68
  # Check that X is a 2D array and has only finite values
77
- X = check_input(X)
78
-
79
- # Set the number of features
80
- self.n_features_in_ = X.shape[1]
81
-
82
- # Set the fitted attribute to True
83
- self._is_fitted = True
69
+ X = self._validate_data(X)
84
70
 
85
71
  return self
86
72
 
@@ -102,7 +88,7 @@ class SavitzkyGolay(OneToOneFeatureMixin, BaseEstimator, TransformerMixin):
102
88
  The transformed data.
103
89
  """
104
90
  # Check that the estimator is fitted
105
- check_is_fitted(self, "_is_fitted")
91
+ check_is_fitted(self, "n_features_in_")
106
92
 
107
93
  # Check that X is a 2D array and has only finite values
108
94
  X = check_input(X)
@@ -31,12 +31,6 @@ class IndexSelector(BaseEstimator, SelectorMixin):
31
31
  features_index_ : int
32
32
  The index of the features to select.
33
33
 
34
- n_features_in_ : int
35
- The number of features in the input data.
36
-
37
- _is_fitted : bool
38
- Whether the transformer has been fitted to data.
39
-
40
34
  Methods
41
35
  -------
42
36
  fit(X, y=None)
@@ -96,7 +90,7 @@ class IndexSelector(BaseEstimator, SelectorMixin):
96
90
 
97
91
  Returns
98
92
  -------
99
- mask : ndarray of shape (n_features,)
93
+ mask : ndarray of shape (n_features_in_,)
100
94
  The mask indicating the selected features.
101
95
  """
102
96
  # Check that the estimator is fitted
@@ -78,6 +78,7 @@ class RangeCut(BaseEstimator, SelectorMixin):
78
78
  else:
79
79
  self.start_index_ = self._find_index(self.start)
80
80
  self.end_index_ = self._find_index(self.end)
81
+ self.wavenumbers_ = self.wavenumbers[self.start_index_ : self.end_index_]
81
82
 
82
83
  return self
83
84
 
@@ -0,0 +1,3 @@
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)