標準化
正規化能把欄位縮放到兩個界線之間,但如果其中一個欄位深受離群值影響,兩個已縮放的欄位就很難比較。常見的解法是「標準化」:不再設定嚴格的上下界,而是把資料以平均數為中心,並計算每個資料點距離平均數有多少個標準差。
本練習屬於課程
Feature Engineering for Machine Learning in Python
練習說明
- 從
sklearn的preprocessing模組匯入StandardScaler。 - 將
StandardScaler()具現化為SS_scaler。 - 在
so_numeric_df的Age欄位上擬合StandardScaler。 - 使用剛剛擬合好的 scaler 轉換同一個欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import StandardScaler
____
# Instantiate StandardScaler
SS_scaler = ____()
# Fit SS_scaler to the data
____.____(so_numeric_df[['Age']])
# Transform the data using the fitted scaler
so_numeric_df['Age_SS'] = ____.____(so_numeric_df[['Age']])
# Compare the origional and transformed column
print(so_numeric_df[['Age_SS', 'Age']].head())