Module for scaling data before and after interpolation.
- class posydon.interpolation.data_scaling.DataScaler[source]
Bases:
object
Data Normalization class.
This class provides normalizing tools for float 1D arrays. Features can be standarized or scaled to a range depending on the method chosen when calling the fit ot fit_and_transform functions.
Initialize the data scaler.
No parameters are expected. After instantiation use methods fit or fit_and_transform first to fit a scaling object to a given vector of values.
Example
>>> sc = DataScaler()
- fit(x, method='none', lower=- 1.0, upper=1.0)[source]
Fit a transform of 1D numpy array x.
Computes the parameters that define the transform.
- Parameters
x (numpy.ndarray) – expects a 1D array and finds norm values of columns
method (str) – Scaling method. Possible values: ‘min_max’, ‘max_abs’, ‘standarize’ and their log versions ‘log_min_max’, ‘neg_log_min_max’, ‘log_max_abs’, ‘log_standarize’, ‘neg_log_standarize’.
lower (float) – lower range value of x_t after (log_)min_max scaling
upper (float) – upper range value of x_t after (log_)min_max scaling
- fit_and_transform(x, method='none', lower=- 1, upper=1)[source]
Fit and transform the array x according to the chosen scaling.
lower/upper will only be taken into account for (log_)min_max normalization. In this case, the transformed x will have min(x_transf) = lower, max(x_transf) = upper
- Parameters
x (numpy.ndarray) – expects a 1D array and finds norm values of columns
method (str) – scaling method. Possible values: ‘min_max’, ‘max_abs’, ‘standarize’ and the log versions ‘log_min_max’, ‘log_max_abs’, ‘log_standarize’
lower (float) – lower range value of x_t after (log_)min_max scaling
upper (float) – upper range value of x_t after (log_)min_max scaling
- Returns
transformed version of x
- Return type
- inv_transform(x_t)[source]
Revert the scaling using the stored transform parameters.
- Parameters
x_t (numpy.ndarray) – expects a 1D array to unnormalize given the fitted transform.
- Returns
denormalized x using the stored parameters.
- Return type
- transform(x)[source]
Transform x using the already obtained normalization values.
self.fit()` must be called first. lower/upper will only be taken into account for (log_)min_max normalization. In this case, the transformed x will have min(x_transf) = lower, max(x_transf) = upper
- Parameters
x (numpy.ndarray) – values to normalize
- Returns
transformed version of x
- Return type