Transformers
cesnet_tszoo.utils.transformer
Transformer
Bases: ABC
Base class for transformers, used for transforming data.
This class serves as the foundation for creating custom transformers. To implement a custom transformer, this class is recommended to be subclassed and extended.
Example:
import numpy as np
class LogTransformer(Transformer):
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)
def inverse_transform(self, transformed_data):
return np.exp(transformed_data)
Source code in cesnet_tszoo\utils\transformer.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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
fit
abstractmethod
fit(data: ndarray) -> None
Sets the transformer values for a given time series part.
This method must be implemented if using multiple transformers 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\transformer.py
37 38 39 40 41 42 43 44 45 46 47 |
|
inverse_transform
inverse_transform(transformed_data: ndarray) -> np.ndarray
Transforms the input transformed data to their original representation for a given time series part.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transformed_data
|
ndarray
|
A numpy array representing data for a single time series with shape |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The original representation of transformed data, with the same shape as the input |
Source code in cesnet_tszoo\utils\transformer.py
76 77 78 79 80 81 82 83 84 85 86 |
|
partial_fit
abstractmethod
partial_fit(data: ndarray) -> None
Partially sets the transformer values for a given time series part.
This method must be implemented if using a single transformer that is not pre-fitted for all time series, or when using pre-fitted transformer(s) with partial_fit_initialized_transformers
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\transformer.py
49 50 51 52 53 54 55 56 57 58 59 |
|
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\transformer.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
LogTransformer
Bases: Transformer
Tranforms data with natural logarithm. Zero or invalid values are set to np.nan
.
Corresponds to enum TransformerType.LOG_TRANSFORMER
or literal log_transformer
.
Source code in cesnet_tszoo\utils\transformer.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
L2Normalizer
Bases: Transformer
Tranforms data using Scikit L2Normalizer
.
Corresponds to enum TransformerType.L2_NORMALIZER
or literal l2_normalizer
.
Source code in cesnet_tszoo\utils\transformer.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
MinMaxScaler
Bases: Transformer
Tranforms data using Scikit MinMaxScaler
.
Corresponds to enum TransformerType.MIN_MAX_SCALER
or literal min_max_scaler
.
Source code in cesnet_tszoo\utils\transformer.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
StandardScaler
Bases: Transformer
Tranforms data using Scikit StandardScaler
.
Corresponds to enum TransformerType.STANDARD_SCALER
or literal standard_scaler
.
Source code in cesnet_tszoo\utils\transformer.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
MaxAbsScaler
Bases: Transformer
Tranforms data using Scikit MaxAbsScaler
.
Corresponds to enum TransformerType.MAX_ABS_SCALER
or literal max_abs_scaler
.
Source code in cesnet_tszoo\utils\transformer.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
PowerTransformer
Bases: Transformer
Tranforms data using Scikit PowerTransformer
.
Corresponds to enum TransformerType.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 transformer that needs to be fitted for multiple time series.
Source code in cesnet_tszoo\utils\transformer.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
QuantileTransformer
Bases: Transformer
Tranforms data using Scikit QuantileTransformer
.
Corresponds to enum TransformerType.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 transformer that needs to be fitted for multiple time series.
Source code in cesnet_tszoo\utils\transformer.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
RobustScaler
Bases: Transformer
Tranforms data using Scikit RobustScaler
.
Corresponds to enum TransformerType.ROBUST_SCALER
or literal robust_scaler
.
partial_fit not supported
Because this transformer does not support partial_fit it can't be used when using one transformer that needs to be fitted for multiple time series.
Source code in cesnet_tszoo\utils\transformer.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|