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.
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
$$
And in case you want to bring a variable back to its original value you can do it because these are linear transformations and thus invertible. For example:
$$
x = (x''' - a)\frac{(\max{x} - \min{x})}{b-a} + \min{x}
$$
An example in Python:
import numpy as np
x = np.array([1, 3, 4, 5, -1, -7])
# goal : range [0, 1]
x1 = (x - min(x)) / ( max(x) - min(x) )
print(x1)
>>> [0.66666667 0.83333333 0.91666667 1. 0.5 0.]

