Scaler#
- class mvpy.preprocessing.Scaler(with_mean: bool = True, with_std: bool = True, dims: list | tuple | int | None = None)[source]#
A standard scaler akin to sklearn.preprocessing.StandardScaler. See notes for some differences.
- Parameters:
- with_meanbool, default=True
If True, center the data before scaling.
- with_stdbool, default=True
If True, scale the data to unit variance.
- dimsint, list or tuple of ints, default=None
The dimensions over which to scale (None for first dimension).
- copybool, default=False
If True, the data will be copied.
- Attributes:
- shape_tuple
The shape of the data.
- mean_Union[np.ndarray, torch.Tensor]
The mean of the data.
- var_Union[np.ndarray, torch.Tensor]
The variance of the data.
- scale_Union[np.ndarray, torch.Tensor]
The scale of the data.
rac{x - mu}{sigma}
where \(\mu\) is the mean and \(\sigma\) is the standard deviation of the data.
Examples
>>> import torch >>> from mvpy.estimators import Scaler >>> X = torch.normal(5, 10, (1000, 5)) >>> print(X.std(0)) tensor([ 9.7033, 10.2510, 10.2483, 10.1274, 10.2013]) >>> scaler = Scaler().fit(X) >>> X_s = scaler.transform(X) >>> print(X_s.std(0)) tensor([1.0000, 1.0000, 1.0000, 1.0000, 1.0000]) >>> X_i = scaler.inverse_transform(X_s) >>> print(X_i.std(0)) tensor([ 9.7033, 10.2510, 10.2483, 10.1274, 10.2013])
- fit(X: ndarray | Tensor, *args: Any, sample_weight: ndarray | Tensor | None = None) Any[source]#
Fit the scaler.
- Parameters:
- XUnion[np.ndarray, torch.Tensor]
The data.
- argsAny
Additional arguments.
- sample_weightUnion[np.ndarray, torch.Tensor], default=None
The sample weights.
- fit_transform(X: ndarray | Tensor, *args: Any, sample_weight: ndarray | Tensor | None = None) ndarray | Tensor[source]#
Fit and transform the data in one step.
- Parameters:
- XUnion[np.ndarray, torch.Tensor]
The data.
- argsAny
Additional arguments.
- sample_weightUnion[np.ndarray, torch.Tensor], default=None
The sample weights.
- Returns:
- Union[np.ndarray, torch.Tensor]
The transformed data.
- inverse_transform(X: ndarray | Tensor, *args: Any) ndarray | Tensor[source]#
Invert the transform of the data.
- Parameters:
- XUnion[np.ndarray, torch.Tensor]
The data.
- argsAny
Additional arguments.
- Returns:
- Union[np.ndarray, torch.Tensor]
The inverse transformed data.
- to_numpy()[source]#
Selet the numpy scaler. Note that this cannot be called for conversion.
- Returns:
- _Scaler_numpy
The numpy scaler.