只縮放資料集的部分欄位
在前面的影片中,你對整個資料集使用過 QuantileTransformer。在這個練習中,你要練習只縮放資料集的部分欄位。這麼做的原因是這些股票資料集包含以數值編碼的類別特徵(day_of_week、day、month),如果對整個資料集使用 QuantileTransformer,這些欄位會被不正確地縮放。
此轉換器已從 sklearn 匯入,並提供含有額外特徵的 apple 股票資料集。
本練習屬於課程
Python 中的異常偵測
練習說明
- 建立一個清單,包含
apple的 5 個數值欄位名稱。 - 初始化一個可將特徵轉換為常態分佈的
QuantileTransformer。 - 同步縮放並儲存
to_scale中的 5 個欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a list of columns
to_scale = [____]
# Initialize a QuantileTransformer
qt = ____
# Scale and store simultaneously
apple.loc[____] = ____