python实现(0,1)的归⼀化数据需要进⾏归⼀化,整理了以下三种版本
(1)按列进⾏归⼀化
#(1)
import pandas as pd
import numpy as np
from sklearn.preprocessing import MinMaxScaler
weight_unbn = np.loadtxt('D:\\')
scaler = MinMaxScaler( )
scaler.fit(weight_unbn)
scaler.data_max_
weight_ansform(weight_unbn)
np.savetxt('D:\\', weight_bn)
weight_bn_pd = pd.DataFrame(weight_bn)
weight__csv('D:\\weight_bn.csv')
# print(weight_bn_pd.head())
(2)按列进⾏归⼀化
import numpy as np
weight的搭配def noramlization(data):
minVals = data.min(0)
maxVals = data.max(0)
ranges = maxVals - minVals
normData = np.zeros(np.shape(data))
m = data.shape[0]
normData = data - np.tile(minVals, (m, 1))
normData = normData/np.tile(ranges, (m, 1))
return normData, ranges, minVals
weight_unbn = np.loadtxt('D:\\')
weight_unbn = np.array(weight_unbn)
weight_bn, _, _, = noramlization(weight_unbn)
#print(weight_bn[:3,:])
(3)按列进⾏归⼀化
from sklearn import preprocessing
import numpy as np
weight_unbn = np.loadtxt('D:\\Data\\biclustering_data\\')
min_max_scaler = preprocessing.MinMaxScaler()
weight_bn = min_max_scaler.fit_transform(weight_unbn)
#print(weight_bn[:3,:])
(4)全局进⾏归⼀化
import numpy as np
def noramlization(data):
minVals = data.min()
maxVals = data.max()
ranges = maxVals - minVals
normData = np.zeros(np.shape(data))
m = data.shape[0]
normData = data - np.tile(minVals, (m, 1))
normData = normData/np.tile(ranges, (m, 1))
return normData, ranges, minVals, maxVals
weight_unbn = np.array([[ 0, 1, 5, 3, 4],
[ 5, 5.5, 6, 8, 9],
[10, 11, 12, 13, 14]])
weight_unbn = np.array(weight_unbn)
weight_bn, ranges, minVals, maxVals,= noramlization(weight_unbn)
print(weight_bn, ranges, minVals, maxVals)
from sklearn import preprocessing
import numpy as np
genome_derived_features_con = pd.read_csv('D:/Data/features/genome_derived_features_con.csv', index_col=0)
min_max_scaler = preprocessing.MinMaxScaler()
genome_derived_features_con = np.array(genome_derived_features_con)
genome_derived_features_con_reshape = genome_derived_shape([-1, 1])
genome_derived_features_con_row_norm_reshape = min_max_scaler.fit_transform(genome_derived_features_con_reshape)
#print(weight_bn[:3,:])
genome_derived_features_con_row_norm = genome_derived_features_con_row_shape(genome_derived_features_con.shape) genome_derived_features_con_row_norm = pd.DataFrame(genome_derived_features_con_row_norm)
genome_derived_features_con__csv('D:/Data/features/genome_derived_features_con_row_norm_1.csv')
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论