MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / Standardizer

Class Standardizer

numpy_ml/preprocessing/general.py:141–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141class Standardizer:
142 def __init__(self, with_mean=True, with_std=True):
143 """
144 Feature-wise standardization for vector inputs.
145
146 Notes
147 -----
148 Due to the sensitivity of empirical mean and standard deviation
149 calculations to extreme values, `Standardizer` cannot guarantee
150 balanced feature scales in the presence of outliers. In particular,
151 note that because outliers for each feature can have different
152 magnitudes, the spread of the transformed data on each feature can be
153 very different.
154
155 Similar to sklearn, `Standardizer` uses a biased estimator for the
156 standard deviation: ``numpy.std(x, ddof=0)``.
157
158 Parameters
159 ----------
160 with_mean : bool
161 Whether to scale samples to have 0 mean during transformation.
162 Default is True.
163 with_std : bool
164 Whether to scale samples to have unit variance during
165 transformation. Default is True.
166 """
167 self.with_mean = with_mean
168 self.with_std = with_std
169 self._is_fit = False
170
171 @property
172 def hyperparameters(self):
173 H = {"with_mean": self.with_mean, "with_std": self.with_std}
174 return H
175
176 @property
177 def parameters(self):
178 params = {
179 "mean": self._mean if hasattr(self, "mean") else None,
180 "std": self._std if hasattr(self, "std") else None,
181 }
182 return params
183
184 def __call__(self, X):
185 return self.transform(X)
186
187 def fit(self, X):
188 """
189 Store the feature-wise mean and standard deviation across the samples
190 in `X` for future scaling.
191
192 Parameters
193 ----------
194 X : :py:class:`ndarray <numpy.ndarray>` of shape `(N, C)`
195 An array of N samples, each with dimensionality `C`
196 """
197 if not isinstance(X, np.ndarray):
198 X = np.array(X)

Callers 1

test_standardizerFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_standardizerFunction · 0.72