pyopmnearwell.ml.scaler_layers module
Provide MinMax scaler layers for tensorflow.keras.
Warning: Tensorflow 2.17 and Keras 3.0 introduce many pylint errors, hence we disable linting completely. It is possible that the module is not functional at the moment.
- class pyopmnearwell.ml.scaler_layers.MinMaxScalerLayer(*args, **kwargs)
Bases:
ScalerLayer,LayerScales the input according to MinMaxScaling.
See https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html for an explanation of the transform.
- call(inputs: Tensor) Tensor
- compute_output_shape(input_shape)
Calculate the output shape.
- classmethod from_config(config)
Reconstruct the layer from its config.
- get_config()
Return the config for serialization.
- class pyopmnearwell.ml.scaler_layers.MinMaxUnScalerLayer(*args, **kwargs)
Bases:
ScalerLayer,LayerUnscales the input by applying the inverse transform of
MinMaxScalerLayer.See https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html for an explanation of the transformation.
- call(inputs: Tensor) Tensor
- compute_output_shape(input_shape)
Calculate the output shape.
- classmethod from_config(config)
Reconstruct the layer from its config.
- get_config()
Return the config for serialization.
- class pyopmnearwell.ml.scaler_layers.ScalerLayer(*args, **kwargs)
Bases:
LayerMixIn to provide functionality for the Scaler Layer.
- _adapt() None
- adapt(data: ArrayLike) None
Fit the layer to the min and max of the data. This is done individually for each input feature.
Note
So far, this is only tested for 1 dimensional input and output. For higher dimensional input and output some functionality might need to be added.
- Parameters:
data – _description_
- build(input_shape: tuple[int, ...]) None
Initialize
data_minanddata_maxwith the default values if they have not been initialized yet.- Parameters:
input_shape (tuple[int, ...]) – _description_
- property data_max
- property data_min
- property feature_range
- get_weights() list[ArrayLike]
Return parameters of the scaling.
- Returns:
List with three elements in the following order:
self.data_min_,self.data_max_,self.feature_range_- Return type:
list[ArrayLike]
- property is_adapted
- min: Tensor
- scalar: Tensor
- set_weights(weights: list[ArrayLike]) None
Set parameters of the scaling.
- Parameters:
weights (list[ArrayLike]) – List with three elements in the following order:
data_min
data_max
feature_range
- Raises:
ValueError – If
feature_range[0] >= feature_range[1].