Scalers
cesnet_tszoo.utils.scaler
Scaler
Bases: ABC
Base class for scalers, used for transforming data.
This class serves as the foundation for creating custom scalers. To implement a custom scaler, this class is recommended to be subclassed and extended.
Example:
import numpy as np
class LogScaler(Scaler):
def fit(self, data: np.ndarray):
...
def partial_fit(self, data: np.ndarray) -> None:
...
def transform(self, data: np.ndarray):
log_data = np.ma.log(data)
return log_data.filled(np.NaN)
Source code in cesnet_tszoo\utils\scaler.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
fit
abstractmethod
fit(data: ndarray) -> None
Sets the scaler values for a given time series part.
This method must be implemented if using multiple scalers that have not been pre-fitted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
A numpy array representing data for a single time series with shape |
required |
Source code in cesnet_tszoo\utils\scaler.py
34 35 36 37 38 39 40 41 42 43 44 |
|
partial_fit
abstractmethod
partial_fit(data: ndarray) -> None
Partially sets the scaler values for a given time series part.
This method must be implemented if using a single scaler that is not pre-fitted for all time series, or when using pre-fitted scaler(s) with partial_fit_initialized_scalers
set to True
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
A numpy array representing data for a single time series with shape |
required |
Source code in cesnet_tszoo\utils\scaler.py
46 47 48 49 50 51 52 53 54 55 56 |
|
transform
abstractmethod
transform(data: ndarray) -> np.ndarray
Transforms the input data for a given time series part.
This method must always be implemented.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
ndarray
|
A numpy array representing data for a single time series with shape |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The transformed data, with the same shape as the input |
Source code in cesnet_tszoo\utils\scaler.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
LogScaler
Bases: Scaler
Tranforms data with natural logarithm. Zero or invalid values are set to np.NaN
.
Corresponds to enum ScalerType.LOG_SCALER
or literal log_scaler
.
Source code in cesnet_tszoo\utils\scaler.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
L2Normalizer
Bases: Scaler
Tranforms data using Scikit L2Normalizer
.
Corresponds to enum ScalerType.L2_NORMALIZER
or literal l2_normalizer
.
Source code in cesnet_tszoo\utils\scaler.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
MinMaxScaler
Bases: Scaler
Tranforms data using Scikit MinMaxScaler
.
Corresponds to enum ScalerType.MIN_MAX_SCALER
or literal min_max_scaler
.
Source code in cesnet_tszoo\utils\scaler.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
StandardScaler
Bases: Scaler
Tranforms data using Scikit StandardScaler
.
Corresponds to enum ScalerType.STANDARD_SCALER
or literal standard_scaler
.
Source code in cesnet_tszoo\utils\scaler.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
MaxAbsScaler
Bases: Scaler
Tranforms data using Scikit MaxAbsScaler
.
Corresponds to enum ScalerType.MAX_ABS_SCALER
or literal max_abs_scaler
.
Source code in cesnet_tszoo\utils\scaler.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
PowerTransformer
Bases: Scaler
Tranforms data using Scikit PowerTransformer
.
Corresponds to enum ScalerType.POWER_TRANSFORMER
or literal power_transformer
.
partial_fit not supported
Because this transformer does not support partial_fit it can't be used when using one scaler that needs to be fitted for multiple time series.
Source code in cesnet_tszoo\utils\scaler.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
QuantileTransformer
Bases: Scaler
Tranforms data using Scikit QuantileTransformer
.
Corresponds to enum ScalerType.QUANTILE_TRANSFORMER
or literal quantile_transformer
.
partial_fit not supported
Because this transformer does not support partial_fit it can't be used when using one scaler that needs to be fitted for multiple time series.
Source code in cesnet_tszoo\utils\scaler.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
RobustScaler
Bases: Scaler
Tranforms data using Scikit RobustScaler
.
Corresponds to enum ScalerType.ROBUST_SCALER
or literal robust_scaler
.
partial_fit not supported
Because this scaler does not support partial_fit it can't be used when using one scaler that needs to be fitted for multiple time series.
Source code in cesnet_tszoo\utils\scaler.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|