One-Hot 編碼
標籤編碼的問題在於它隱含假設類別之間存在排序關係。因此,讓我們把特徵「RoofStyle」與「CentralAir」改用 one-hot 編碼。你在工作環境中已經有 House Prices Kaggle 比賽的 train 與 test DataFrame。
請記住,如果你處理的是二元特徵(僅有 2 個類別的類別型特徵),建議只使用標籤編碼。
你的目標是判斷上述哪些特徵不是二元特徵,並且只對這個特徵套用 one-hot 編碼。
本練習屬於課程
用 Python 拿下 Kaggle 競賽
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Concatenate train and test together
houses = pd.concat([train, test])
# Look at feature distributions
print(houses['RoofStyle'].____, '\n')
print(houses['CentralAir'].____)