Standardize features by removing the mean and scaling to unit variance. For a sample `x`, the standardized score is calculated as: .. math:: z = (x - u) / s where `u` is the mean of the training samples or zero if `with_mean` is False, and `s`
(self, X)
| 214 | self._is_fit = True |
| 215 | |
| 216 | def transform(self, X): |
| 217 | """ |
| 218 | Standardize features by removing the mean and scaling to unit variance. |
| 219 | |
| 220 | For a sample `x`, the standardized score is calculated as: |
| 221 | |
| 222 | .. math:: |
| 223 | |
| 224 | z = (x - u) / s |
| 225 | |
| 226 | where `u` is the mean of the training samples or zero if `with_mean` is |
| 227 | False, and `s` is the standard deviation of the training samples or 1 |
| 228 | if `with_std` is False. |
| 229 | |
| 230 | Parameters |
| 231 | ---------- |
| 232 | X : :py:class:`ndarray <numpy.ndarray>` of shape `(N, C)` |
| 233 | An array of N samples, each with dimensionality `C`. |
| 234 | |
| 235 | Returns |
| 236 | ------- |
| 237 | Z : :py:class:`ndarray <numpy.ndarray>` of shape `(N, C)` |
| 238 | The feature-wise standardized version of `X`. |
| 239 | """ |
| 240 | if not self._is_fit: |
| 241 | raise Exception("Must call `fit` before using the `transform` method") |
| 242 | return (X - self._mean) / self._std |
| 243 | |
| 244 | def inverse_transform(self, Z): |
| 245 | """ |
no outgoing calls