開始使用免費開始

簡單填補(Simple imputation)

正如你在上一個練習所看到的,直接刪除資料可能會讓你的資料集縮水太多。在面試情境下,這會導致你的機器學習模型產生偏差的結果。

更有彈性的做法是對遺漏值進行「填補」。在 Python 中有多種方式可行,但在本練習中,你會在 loan_data 上使用 sklearn.impute 模組中的 SimpleImputer() 函式。

接著你會使用 pandasnumpy,把填補後的資料集轉回成 DataFrame。

注意,現在在流程(pipeline)中新增了 2 個步驟,InstantiateFitMachine learning pipeline

本練習屬於課程

用 Python 練習機器學習面試題

檢視課程

動手互動練習

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

# Import imputer module
from sklearn.impute import SimpleImputer

# Subset numeric features: numeric_cols
numeric_cols = ____.____(include=[____.____])
編輯並執行程式碼