Scalers

TransformMixin

class TransformMixin[source]

Bases: object

Abstract base class for transformation mixins.

This class defines the interface for transformation mixins, which are classes that can be used to normalize or denormalize data. The transformations that a subclass must implement are defined as abstract methods.

abstract fit(data: Tensor)[source]

Fits the transformation to the data.

This method computes and stores any necessary statistics from the data needed to perform the transformation.

Parameters:

data (torch.Tensor) – The data to fit the transformation to.

abstract inverse_transform(data: Tensor)[source]

Applies the inverse transformation to the data.

This method undoes the transformation applied in the transform method, returning the data to its original state. It should be called after the transform method.

Parameters:

data (torch.Tensor) – The data to apply the inverse transformation to.

Returns:

The inverse-transformed data.

Return type:

torch.Tensor

abstract transform(data: Tensor)[source]

Applies the transformation to the data.

This method transforms the data based on the statistics computed in the fit method. It should be called after the fit method.

Parameters:

data (torch.Tensor) – The data to apply the transformation to.

Returns:

The transformed data.

Return type:

torch.Tensor

ZScoreNormalizer

class ZScoreNormalizer[source]

Bases: TransformMixin

Z-Score Normalizer.

This class normalizes and denormalizes data using Z-score normalization, which scales the data to have a mean of 0 and a standard deviation of 1. It inherits from the TransformMixin class.

mean

The mean of the data. Calculated when fit method is called.

Type:

torch.Tensor or None

std

The standard deviation of the data. Calculated when fit method is called.

Type:

torch.Tensor or None

fit(data: Tensor)[source]

Fits the normalizer to the data.

This method computes and stores the mean and standard deviation of the data.

Parameters:

data (torch.Tensor) – The data to fit the normalizer to.

inverse_transform(data: Tensor)[source]

Applies the inverse normalizer to the data.

This method transforms the data by multiplying by the standard deviation and adding the mean. The fit and transform methods must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the inverse normalizer to.

Returns:

The denormalized data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.

transform(data: Tensor)[source]

Applies the normalizer to the data.

This method transforms the data by subtracting the mean and dividing by the standard deviation. The fit method must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the normalizer to.

Returns:

The normalized data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.

MinMaxNormalizer

class MinMaxNormalizer[source]

Bases: TransformMixin

Min-Max Normalizer.

This class normalizes and denormalizes data using Min-Max normalization, which scales the data to fit within a specified range. It inherits from the TransformMixin class.

min

The minimum value of the data. Calculated when fit method is called.

Type:

torch.Tensor or None

max

The maximum value of the data. Calculated when fit method is called.

Type:

torch.Tensor or None

fit(data: Tensor)[source]

Fits the normalizer to the data.

This method computes and stores the minimum and maximum values of the data.

Parameters:

data (torch.Tensor) – The data to fit the normalizer to.

inverse_transform(data: Tensor)[source]

Applies the inverse normalizer to the data.

This method transforms the data by multiplying by the range of the data and adding the minimum. The fit and transform methods must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the inverse normalizer to.

Returns:

The denormalized data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.

transform(data: Tensor)[source]

Applies the normalizer to the data.

This method transforms the data by subtracting the minimum and dividing by the range of the data. The fit method must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the normalizer to.

Returns:

The normalized data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.

RobustScaler

class RobustScaler[source]

Bases: TransformMixin

Robust Scaler.

This class normalizes and denormalizes data using Robust Scaling, which scales data using statistics that are robust to outliers. It inherits from the TransformMixin class.

median

The median of the data. Calculated when fit method is called.

Type:

torch.Tensor or None

iqr

The interquartile range of the data. Calculated when fit method is called.

Type:

torch.Tensor or None

fit(data: Tensor)[source]

Fits the scaler to the data.

This method computes and stores the median and interquartile range of the data.

Parameters:

data (torch.Tensor) – The data to fit the scaler to.

inverse_transform(data: Tensor)[source]

Applies the inverse scaler to the data.

This method transforms the data by multiplying by the interquartile range and adding the median. The fit and transform methods must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the inverse scaler to.

Returns:

The rescaled data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.

transform(data: Tensor)[source]

Applies the scaler to the data.

This method transforms the data by subtracting the median and dividing by the interquartile range. The fit method must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the scaler to.

Returns:

The scaled data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.

MaxAbsScaler

class MaxAbsScaler[source]

Bases: TransformMixin

Max Absolute Scaler.

This class normalizes and denormalizes data using Max Absolute Scaling, which scales data to lie within the range [-1,1] by dividing each sample by its maximum absolute value. It inherits from the TransformMixin class.

max_abs

The maximum absolute value of the data. Calculated when fit method is called.

Type:

torch.Tensor or None

fit(data: Tensor)[source]

Fits the scaler to the data.

This method computes and stores the maximum absolute value of the data.

Parameters:

data (torch.Tensor) – The data to fit the scaler to.

inverse_transform(data: Tensor)[source]

Applies the inverse scaler to the data.

This method transforms the data by multiplying by the maximum absolute value. The fit and transform methods must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the inverse scaler to.

Returns:

The rescaled data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.

transform(data: Tensor)[source]

Applies the scaler to the data.

This method transforms the data by dividing by the maximum absolute value. The fit method must be called before this method.

Parameters:

data (torch.Tensor) – The data to apply the scaler to.

Returns:

The scaled data.

Return type:

torch.Tensor

Raises:

RuntimeError – If the fit method has not been called before this method.