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

Method fit

numpy_ml/preprocessing/general.py:187–214  ·  view source on GitHub ↗

Store the feature-wise mean and standard deviation across the samples in `X` for future scaling. Parameters ---------- X : :py:class:`ndarray ` of shape `(N, C)` An array of N samples, each with dimensionality `C`

(self, X)

Source from the content-addressed store, hash-verified

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)
199
200 if X.shape[0] < 2:
201 raise ValueError("`X` must contain at least 2 samples")
202
203 std = np.ones(X.shape[1])
204 mean = np.zeros(X.shape[1])
205
206 if self.with_mean:
207 mean = np.mean(X, axis=0)
208
209 if self.with_std:
210 std = np.std(X, axis=0, ddof=0)
211
212 self._mean = mean
213 self._std = std
214 self._is_fit = True
215
216 def transform(self, X):
217 """

Callers 1

test_standardizerFunction · 0.95

Calls

no outgoing calls

Tested by 1

test_standardizerFunction · 0.76