Pythonで学ぶクレジットリスクモデリング
Michael Crabtree
Data Scientist, Ford Motor Company
loan_statusの値がクラス01y_train['loan_status'].value_counts()
| loan_status | 学習データ数 | 全体に占める割合 |
|---|---|---|
| 0 | 13,798 | 78% |
| 1 | 3,877 | 22% |
xgboostの勾配ブースティング木はロス関数に対数損失を使用| 真のローン状態 | 予測確率 | 対数損失 |
|---|---|---|
| 1 | 0.1 | 2.3 |
| 0 | 0.9 | 2.3 |
| 人 | 貸付額 | 潜在利益 | 予測 | 実際 | 損失 |
|---|---|---|---|---|---|
| A | $1,000 | $10 | 延滞 | 延滞なし | -$10 |
| B | $1,000 | $10 | 延滞なし | 延滞 | -$1,000 |
| 方法 | 長所 | 短所 |
|---|---|---|
| データを追加収集 | 延滞件数が増える | 延滞の割合は変わらない可能性 |
| モデルにペナルティ | 延滞の再現率が向上 | 追加の調整と保守が必要 |
| サンプリングを変更 | 技術的調整が少ない | データ内の延滞が減る |
loan_statusに基づき2つの新セットを作成# Concat the training sets
X_y_train = pd.concat([X_train.reset_index(drop = True),
y_train.reset_index(drop = True)], axis = 1)
# Get the counts of defaults and non-defaults
count_nondefault, count_default = X_y_train['loan_status'].value_counts()
# Separate nondefaults and defaults
nondefaults = X_y_train[X_y_train['loan_status'] == 0]
defaults = X_y_train[X_y_train['loan_status'] == 1]
# Undersample the non-defaults using sample() in pandas
nondefaults_under = nondefaults.sample(count_default)
# Concat the undersampled non-defaults with the defaults
X_y_train_under = pd.concat([nondefaults_under.reset_index(drop = True),
defaults.reset_index(drop = True)], axis=0)
Pythonで学ぶクレジットリスクモデリング