Search code examples
matlabnormalization

Normalizing data to [-1, 1] range


I have a training dataset which is of size NxD and a test dataset which is of size AxD. The rows are the data points and the columns are the features.

Now I would like to transform each feature (column) to be in the range [-1, 1]. Moreover, the scaling of the features in the test set should be done with the parameters estimated on the training set. For example, if I do the standardization by subtracting the mean and dividing the standard deviation, I would calculate the mean and standard deviation on the training set and use them to standardize the test set. The same I want to do now for scaling to the range [-1, 1].

How can this be done?


Solution

  • Something like this:

    mins = min(trainingDataset);
    maxs = max(trainingDataset);
    testDataset = 2*bsxfun(@rdivide, bsxfun(@minus,testDataset,mins), maxs-mins)-1;