欠損したクレジットデータの置換
まず、欠損データを確認しましょう。loan_status に欠損がある場合、貸倒かどうかが分からないため、デフォルト確率の予測にそのデータは使えません。person_emp_length の欠損はそれほど致命的ではありませんが、学習時のエラーにつながります。
そこで、person_emp_length 列の欠損データを確認し、欠損値は中央値で置き換えてください。
データセット cr_loan はワークスペースに読み込まれています。
この演習はコースの一部です
Pythonで学ぶクレジットリスクモデリング
演習の手順
.isnull()を使って、欠損データを含む列名の配列を出力します。person_emp_lengthに欠損があるデータの先頭5行を出力します。.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.____()