取代遺漏的信用資料
現在,你需要檢查是否有遺漏值。如果 loan_status 裡有遺漏值,你就無法用這些資料來預測違約機率,因為你不會知道該筆貸款是否違約。person_emp_length 的遺漏值影響雖然沒那麼大,但仍可能造成訓練時出錯。
因此,請檢查 person_emp_length 欄位中的遺漏值,並把所有遺漏值以該欄位的中位數取代。
資料集 cr_loan 已載入到工作區。
本練習屬於課程
以 Python 進行信用風險建模
練習說明
- 使用
.isnull()印出包含遺漏值的欄位名稱陣列。 - 印出在
person_emp_length有遺漏值的前五列資料。 - 使用
.fillna()以所有就業年資的中位數取代該欄位中的遺漏值。 - 繪製
person_emp_length欄位的長條圖以檢查其分佈。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Print a null value column array
print(____.columns[____.____().any()])
# Print the top five rows with nulls for employment length
print(____[____[____].____()].head())
# Impute the null values with the median value for all employment lengths
____[____].____((cr_loan['person_emp_length'].____()), inplace=True)
# Create a histogram of employment length
n, bins, patches = plt.____(____[____], bins='auto', color='blue')
plt.xlabel("Person Employment Length")
plt.____()