zscore归一化:
minmax
from sklearn import preprocessing
from sklearn.preprocessing import StandardScaler
import numpy as np# 数据
x = np.array([[1.,-1.,2.],[2.,0.,0.],[0.,1.,-1.]])
print('----------------minmaxscaler标准化-------------')
# 调用minmaxscaler标准化
min_max_scaler = preprocessing.MinMaxScaler()
x_minmax = min_max_scaler.fit_transform(x)
print(x_minmax)# 手写minmaxscaler标准化
def MinMaxScaler(data):return (data-data.min(axis = 0))/(data.max(axis=0)-data.min(axis=0))
print(MinMaxScaler(x))print('----------------zscore归一化-------------')
# 手写ZScoreScaler归一化
def ZScoreScaler(data):return (data-data.mean(axis = 0))/data.std(axis = 0)
print(ZScoreScaler(x))# 调库
zscaler = StandardScaler ()
x_zscore = zscaler.fit_transform(x)
print(x_zscore)