密度プロットを比較する
これまでに行ったさまざまな代入法は、密度プロットで可視的に比較できます。これらのプロットから、元のデータセットと分布が最も似ているデータセットを簡単に分析して見つけることができます。また、代入によってどのような偏りが生じるかも確認できます。
この演習では、先ほど作成した diabetes の Imputed 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()