I have samples with each sample has n features, how to normalize these features to let feature values lie between interval [-1,1], please give a formula.
Asked
Active
Viewed 2.0k times
4
-
2This is essentially the same question as http://stats.stackexchange.com/questions/8285/normalizing-data-between-0-and-1 except your lower bound is -1, not 0. So: take any of the answers there, multiply by 2, and subtract 1. But first read the cautionary remarks! – whuber Apr 12 '11 at 17:30
-
1This is essentially the same question as http://stats.stackexchange.com/questions/1112/how-to-represent-an-unbounded-variable-as-number-between-0-and-1/1113#1113 except your lower bound is -1, not 0. So Please have a look at my answer there. Note, I am referring to another question then @whuber – Henrik Apr 12 '11 at 17:33
-
@Henrik Thanks for pointing that out. Because these are substantially the same questions, I have merged them. – whuber Apr 12 '11 at 17:35
1 Answers
5
Standard normalization is given as:
X_std = (X - X.min) / (X.max - X.min)
Now if you want to scale it between a min max range, this is what you can do,
X_scaled = X_std * (max - min) + min
In matlab(some variables are redundant but will help in understanding):
function [ Data_out ] = scaleData( Data, fmin, fmax)
[m, n] = size(Data); % m data points with n feature dimension
Data_out = zeros(m,n);
for i = 1 : n
X = Data(:,i);
Xmin = min(X); Xmax = max(X);
X_std = (X - Xmin) ./ (Xmax - Xmin);
X_scaled = X_std .* (fmax - fmin) + fmin;
Data_out(:,i) = X_scaled;
end
end

Parag
- 186
- 1
- 4