In [1]:
import numpy as np
In [2]:
np.random.seed(10)
x = [np.random.randint(10,25) for i in range(10)]
print x
In [3]:
def min_max(x):
return [round((xx-min(x))/(1.0*(max(x)-min(x))),2) for xx in x]
In [4]:
print x
print min_max(x)
In [ ]:
In [5]:
from sklearn.preprocessing import MinMaxScaler
import numpy as np
np.random.seed(10)
x = np.matrix([np.random.randint(10,25)*1.0 for i in range(10)])
print x
In [9]:
minmax = MinMaxScaler(feature_range=(0.0,1.0))
x = x.T
x_t = minmax.fit_transform(x)
print x_t
In [10]:
# 加载库
import numpy as np
from sklearn.preprocessing import scale
In [11]:
np.random.seed(10)
x = [np.random.randint(10,25)*1.0 for i in range(10)]
In [12]:
x_centered = scale(x,with_mean=True,with_std=False)
x_standard = scale(x,with_mean=True,with_std=True)
print x
print x_centered
print x_standard
print 'Origin x mean = %0.2f,Centered mean = %0.2f,Std dev of standard x = %0.2f' %(np.mean(x),np.mean(x_centered),np.mean(x_standard))