4
$\begingroup$

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.

$\endgroup$
3
  • 2
    $\begingroup$ This is essentially the same question as stats.stackexchange.com/questions/8285/… 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! $\endgroup$
    – whuber
    Commented Apr 12, 2011 at 17:30
  • 1
    $\begingroup$ This is essentially the same question as stats.stackexchange.com/questions/1112/… 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 $\endgroup$
    – Henrik
    Commented Apr 12, 2011 at 17:33
  • $\begingroup$ @Henrik Thanks for pointing that out. Because these are substantially the same questions, I have merged them. $\endgroup$
    – whuber
    Commented Apr 12, 2011 at 17:35

1 Answer 1

5
$\begingroup$

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
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.