資料縮放-標準化欄位
已知 wine 資料集中的 Ash、Alcalinity of ash 與 Magnesium 欄位使用的量尺不同,讓我們將它們標準化,以方便用於線性模型。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 匯入
StandardScaler類別。 - 建立一個
StandardScaler()並將其存到變數scaler。 - 從
wineDataFrame 建立只包含Ash、Alcalinity of ash、Magnesium欄位的子集,指定給wine_subset。 - 對
wine_subset進行標準化器的擬合與轉換(fit 與 transform)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import StandardScaler
from sklearn.preprocessing import ____
# Create the scaler
scaler = ____
# Subset the DataFrame you want to scale
____ = wine[[____]]
# Apply the scaler to wine_subset
wine_subset_scaled = scaler.____(____)