開始使用免費開始

填補遺漏資料

你發現 Rental Listing Inquiries 資料集中的「price」與「building_id」欄位有遺漏值。因此,在把資料送進模型之前,你需要先填補這些值。

數值型特徵「price」將以非遺漏價格的平均值來編碼。

把類別型特徵「buildingid」以最常見的類別來填補並不好,因為那會表示所有缺少「buildingid」的公寓都位在最熱門的大樓。更好的做法是用一個新的類別來填補。

競賽資料的 DataFrame rental_listings 已替你讀入。

本練習屬於課程

用 Python 拿下 Kaggle 競賽

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import SimpleImputer
from sklearn.impute import SimpleImputer

# Create mean imputer
mean_imputer = ____(strategy='____')

# Price imputation
rental_listings[['price']] = mean_imputer.____(____[[____]])
編輯並執行程式碼