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.
 A: 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.]

A: I tested on randomly generated data, and 
\begin{equation}
    X_{out} = (b-a)\frac{X_{in} - \min{X_{in}}}{\max{X_{in}} - \min{X_{in}}} + a
\end{equation}
does not preserve the shape of the distribution. Would really like to see the proper derivation of this using functions of random variables.
The approach that did preserve the shape for me was using:
\begin{equation}
    X_{out} = \frac{X_{in} - \mu_{in}}{\sigma_{in}} \cdot \sigma_{out} + \mu_{out}
\end{equation}
where
\begin{equation}
    \sigma_{out} = \frac{b-a}{6}
\end{equation}
(I admit that using 6 is a bit dirty) and
\begin{equation}
    \mu_{out} = \frac{b+a}{2}
\end{equation}
and
$a$ and $b$ is the desired range; so as per original question would be $a=-1$ and $b=1$.
I arrived at the result from this reasoning
\begin{equation}
    Z_{out} = Z_{in}
\end{equation}
\begin{equation}
    \frac{X_{out} - \mu_{out}}{\sigma_{out}} = \frac{X_{in} - \mu_{in}}{\sigma_{in}}
\end{equation}
