選出相關特徵
在這個練習中,你要找出 volunteer 資料集中的冗餘欄位,並對資料集進行特徵選擇,回傳僅包含相關特徵的 DataFrame。
例如,在主控台中探索 volunteer 資料集時,你會看到 3 個與地點相關的特徵:locality、region 和 postalcode。它們包含相關資訊,因此只保留其中一個特徵是合理的做法。
花點時間在主控台檢視 volunteer 的各個特徵,試著辨識出哪些是冗餘特徵。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 建立一個冗餘欄位名稱的清單,並將它存入變數
to_drop:- 在所有與地點相關的特徵中,只保留
postalcode。 - 經過特徵工程處理的特徵也屬於冗餘。
- 在所有與地點相關的特徵中,只保留
- 從資料集中刪除
to_drop清單中的欄位。 - 列印
volunteer_subset的.head(),查看被選出的欄位。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a list of redundant column names to drop
to_drop = ["____", "____", "____", "____", "____"]
# Drop those columns from the dataset
volunteer_subset = ____.____(____, ____)
# Print out the head of volunteer_subset
print(____)