macrosynergy.learning.preprocessing.scalers.scalers#
- class PanelMinMaxScaler(type='panel')[source]#
Bases:
BasePanelScaler
Scale and translate panel features to lie within the range [0,1].
Notes
This class is designed to replicate scikit-learn’s MinMaxScaler() class, with the additional option to scale within cross-sections. Unlike the MinMaxScaler() class, dataframes are always returned, preserving the multi-indexing of the inputs.
- extract_statistics(X, feature)[source]#
Determine the minimum and maximum values of a feature in the input matrix.
- Parameters:
X (pandas.DataFrame) – The feature matrix.
feature (str) – The feature to extract statistics for.
- Returns:
statistics – List containing the minimum and maximum values of the feature.
- Return type:
- scale(X, feature, statistics)[source]#
Scale the ‘feature’ column in the design matrix ‘X’ based on the minimum and maximum values of the feature.
- Parameters:
X (pandas.DataFrame) – The feature matrix.
feature (str) – The feature to scale.
statistics (list) – List containing the minimum and maximum values of the feature, in that order.
- Returns:
X_transformed – The scaled feature.
- Return type:
- class PanelStandardScaler(type='panel', with_mean=True, with_std=True)[source]#
Bases:
BasePanelScaler
Scale and translate panel features to have zero mean and unit variance.
- Parameters:
Notes
This class is designed to replicate scikit-learn’s StandardScaler() class, with the additional option to scale within cross-sections. Unlike the StandardScaler() class, dataframes are always returned, preserving the multi-indexing of the inputs.
- extract_statistics(X, feature)[source]#
Determine the mean and standard deviation of values of a feature in the input matrix.
- Parameters:
X (pandas.DataFrame) – The feature matrix.
feature (str) – The feature to extract statistics for.
- Returns:
statistics – List containing the mean and standard deviation of values of the feature.
- Return type:
- scale(X, feature, statistics)[source]#
Scale the ‘feature’ column in the design matrix ‘X’ based on the mean and standard deviation values of the feature.
- Parameters:
X (pandas.DataFrame) – The feature matrix.
feature (str) – The feature to scale.
statistics (list) – List containing the mean and standard deviation of values of the feature, in that order.
- Returns:
X_transformed – The scaled feature.
- Return type: