26
$\begingroup$

I have seen the min-max normalization formula but that normalizes values between 0 and 1. How would I normalize my data between -1 and 1? I have both negative and positive values in my data matrix.

$\endgroup$
  • 1
    $\begingroup$ If you're working in R, see this thread for a few options. In particular, a comment on the accepted answer has this function where you set the 'newMax' to 1 and 'newMin' to -1 and run the function on your data $\endgroup$ – mtreg Oct 26 '15 at 1:19
  • $\begingroup$ You can find reference at Wikipedia as follows: en.wikipedia.org/wiki/Normalization_(statistics) $\endgroup$ – salem Feb 26 '18 at 5:38
  • $\begingroup$ Javascript example, taken from here. function convertRange( value, r1, r2 ) { return ( value - r1[ 0 ] ) * ( r2[ 1 ] - r2[ 0 ] ) / ( r1[ 1 ] - r1[ 0 ] ) + r2[ 0 ]; } convertRange( 328.17, [ 300.77, 559.22 ], [ 1, 10 ] ); >>> 1.9541497388276272 $\endgroup$ – Giuseppe Canale Mar 8 '18 at 16:46
  • $\begingroup$ @covfefe if you are still around you might want to accept one of the answers $\endgroup$ – Simone Nov 4 '18 at 9:06
81
$\begingroup$

With: $$ x' = \frac{x - \min{x}}{\max{x} - \min{x}} $$ you normalize your feature $x$ in $[0,1]$.

To normalize in $[-1,1]$ you can use:

$$ x'' = 2\frac{x - \min{x}}{\max{x} - \min{x}} - 1 $$

In general, you can always get a new variable $x'''$ in $[a,b]$:

$$ x''' = (b-a)\frac{x - \min{x}}{\max{x} - \min{x}} + a $$

$\endgroup$
  • $\begingroup$ This is an old answer but can you please provide citations? $\endgroup$ – hamid Oct 19 '17 at 2:31
  • 12
    $\begingroup$ Honestly I don't have citations for this. It is just a linear transformation of a random variable. Have a look at the effect of linear transformations on the support of a random variable. $\endgroup$ – Simone Oct 19 '17 at 4:40

protected by gung Feb 21 at 19:55

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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