pyMAISE.preprocessing.scale_data

pyMAISE.preprocessing.scale_data(train_data, test_data, scaler)[source]

Scale training and testing data using the scaler provided. This method returns the fit scalar which can be used to scale any additional data.

Example

Given the following 2D xarray.DataArrays of shape (samples, features/labels), xtrain and xtest, we can apply the pyMAISE.preprocessing.scale_data() method,

from pyMAISE.preprocessing import scale_data
from sklearn.preprocessing import MinMaxScaler

xtrain, xtest, xscaler = scale_data(xtrain, xtest, MinMaxScaler)

We can then scale an additional dataset, xvalid, that matches the format of xtrain and xtest by running

xvalid.values = xscaler.transform(xvalid.values)
Parameters:
  • train_data (xarray.DataArray) – Training data.

  • test_data (xarray.DataArray) – Testing data.

  • scaler (callable) – An object with fit_transform and transform methods such as min-max scaler from sklearn [PVG+11].

Returns:

  • train_data (xarray.DataArray) – Scaled training data.

  • test_data (xarray.DataArray) – Scaled testing data based on scaler fit on train_data.

  • scaler (callable) – The scaler given, fit and used to scale the given data.