# How to normalize data between -1 and 1?

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.

• 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 – mtreg Oct 26 '15 at 1:19
• You can find reference at Wikipedia as follows: en.wikipedia.org/wiki/Normalization_(statistics) – salem Feb 26 '18 at 5:38
• 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 – Giuseppe Canale Mar 8 '18 at 16:46
• @covfefe if you are still around you might want to accept one of the answers – Simone Nov 4 '18 at 9:06

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

• This is an old answer but can you please provide citations? – hamid Oct 19 '17 at 2:31
• 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. – 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).