A class for scaling data using standardization with torch tensors. This scaler computes the mean and standard deviation on a dataset so that it can later be used to scale the data using the computed mean and standard deviation.
Attributes
Name
Type
Description
mean
torch.Tensor
The mean value computed over the fitted data.
std
torch.Tensor
The standard deviation computed over the fitted data.
Examples
>>>import torch>>>from spotoptim.utils.scaler import TorchStandardScaler>>># Create a sample tensor>>> tensor = torch.rand((10, 3)) # Random tensor with shape (10, 3)>>> scaler = TorchStandardScaler()>>># Fit the scaler to the data>>> scaler.fit(tensor)>>># Transform the data using the fitted scaler>>> transformed_tensor = scaler.transform(tensor)>>>print(transformed_tensor.shape)torch.Size([10, 3])>>># Using fit_transform method to fit and transform in one step>>> another_tensor = torch.rand((10, 3))>>> scaled_tensor = scaler.fit_transform(another_tensor)