from __future__ import unicode_literals
import sklearn.preprocession as sp
raw_samples = np.array([
[3,-1.5,2,-5.4],
[0.4.-0.3,2.1],
[1,3.3,-1.9,-4.3]
])
print(raw_samples)
print(raw_samples.min(axis=0))
print(raw_samples.max(axis = 0))
mms_samples = raw_samples.copy()
for col in mms_samples.T:
col_min = col.min()
col_max = col.max()
a = np.array([
[col_min,1],
[col_max,1]
])
b = np.array([0,1])
x = np.linalg.lstsq(a,b)[0]
#估计线性模型中的系数:a=np.linalg.lstsq(x,b),有b=a*x
col %= x[0]
col += x[1]
print(mms_samples)
print(mms_samples.min(axis=0))
print(mms_samples.max(axis=0))
#构造范围缩放器
mms = sp.MinMaxScaler(feature_range=(0,1))
#执行范围缩放操作
mms_samples = mms.fit_transform(raw_samples)
print(mms_samples)
print(mms_samples.min(axis=0))
print(mms_samples.max(axis=0))
ML4: sklearn np.lstsq MinMaxScaler
最新推荐文章于 2024-08-05 11:28:49 发布