In [6]:
# Min Max Scaler

In [1]:
import numpy as np
from sklearn import preprocessing

In [2]:
x = np.array([[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]])
x


Out[2]:
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.],
       [ 7.,  8.,  9.]])

In [3]:
minmax = preprocessing.MinMaxScaler(feature_range=(0,1))
minmax.fit(x).transform(x)


Out[3]:
array([[ 0. ,  0. ,  0. ],
       [ 0.5,  0.5,  0.5],
       [ 1. ,  1. ,  1. ]])

In [8]:
# standard scaler
standard = preprocessing.StandardScaler().fit(x)
standard.transform(x)


Out[8]:
array([[-1.22474487, -1.22474487, -1.22474487],
       [ 0.        ,  0.        ,  0.        ],
       [ 1.22474487,  1.22474487,  1.22474487]])

In [9]:
x


Out[9]:
array([[ 1.,  2.,  3.],
       [ 4.,  5.,  6.],
       [ 7.,  8.,  9.]])

In [10]:
# (x-x_mean)/x_std
x_std_0 = (1-4)/np.std(x[:, 0])
x_std_0


Out[10]:
-1.2247448713915892

In [ ]: