Normalization(正規化)
就像影片中提到的,正規化會把整個欄位線性縮放到 0 到 1 之間;0 對應該欄位的最小值,1 對應最大值。
在使用 scikit-learn(Python 中最常用的機器學習函式庫)時,你可以用 MinMaxScaler 來做正規化。
(之所以叫這個名稱,是因為它會把數值縮放到最小值與最大值之間。)
本練習屬於課程
Feature Engineering for Machine Learning in Python
練習說明
- 從
sklearn的preprocessing模組匯入MinMaxScaler。 - 以
MinMaxScaler()建立實例並命名為MM_scaler。 - 在
so_numeric_df的Age欄位上擬合MinMaxScaler。 - 使用剛剛擬合好的 scaler 轉換同一個欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import MinMaxScaler
____
# Instantiate MinMaxScaler
MM_scaler = ____()
# Fit MM_scaler to the data
____.____(so_numeric_df[['Age']])
# Transform the data using the fitted scaler
so_numeric_df['Age_MM'] = ____.____(so_numeric_df[['Age']])
# Compare the origional and transformed column
print(so_numeric_df[['Age_MM', 'Age']].head())