比較密度圖
你先前做過的不同插補方式,可以用各自的密度圖來做圖形化比較。透過這些圖,你可以更容易分析並找出與原始資料集分佈最相近的那一個。同時,你也能看出某種插補方式可能帶來的偏誤。
在這個練習中,你要比較先前為 diabetes 建立的各個插補後 DataFrame 的密度圖。
diabetes_cc、diabetes_mean_imputed、diabetes_knn_imputed 與 diabetes_mice_imputed 這些 DataFrame 已為你載入可用,matplotlib.pyplot 也已以 plt 匯入。
本練習屬於課程
在 Python 中處理遺漏值
練習說明
- 為每個 DataFrame 的
'Skin_Fold'欄位繪製密度圖。 - 使用
labels清單設定圖例標籤。 - 將 x 軸標籤設為
'Skin Fold'。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot graphs of imputed DataFrames and the complete case
diabetes_cc['___'].___(___='___', c='red', linewidth=3)
diabetes_mean_imputed['___'].plot(___='___')
diabetes_knn_imputed['___'].plot(___='___')
diabetes_mice_imputed['___'].plot(___='___')
# Create labels for the four DataFrames
labels = ['Baseline (Complete Case)', 'Mean Imputation', 'KNN Imputation', 'MICE Imputation']
plt.legend(___)
# Set the x-label as Skin Fold
plt.xlabel('___')
plt.show()