在Python中,進(jìn)行數(shù)據(jù)預(yù)處理的歸一化可以使用sklearn庫(kù)中的MinMaxScaler類(lèi)。以下是使用MinMaxScaler進(jìn)行歸一化的步驟:
import numpy as np
from sklearn.preprocessing import MinMaxScaler
data = np.array([[10, 20, 30, 40, 50],
[15, 25, 35, 45, 55],
[20, 30, 40, 50, 60],
[25, 35, 45, 55, 65],
[30, 40, 50, 60, 70],
[35, 45, 55, 65, 75],
[40, 50, 60, 70, 80],
[45, 55, 65, 75, 85],
[50, 60, 70, 80, 90],
[55, 65, 75, 85, 95]])
scaler = MinMaxScaler(feature_range=(0, 1))
normalized_data = scaler.fit_transform(data)
print(normalized_data)
執(zhí)行以上代碼后,將得到歸一化后的數(shù)據(jù)集。請(qǐng)注意,歸一化后的數(shù)據(jù)范圍將在[0, 1]之間。