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 的梯度提升树使用对数损失(log-loss)| 实际状态 | 预测概率 | 对数损失 |
|---|---|---|
| 1 | 0.1 | 2.3 |
| 0 | 0.9 | 2.3 |
| 人员 | 贷款额 | 潜在利润 | 预测状态 | 实际状态 | 损失 |
|---|---|---|---|---|---|
| A | $1,000 | $10 | 违约 | 非违约 | -$10 |
| B | $1,000 | $10 | 非违约 | 违约 | -$1,000 |
| 方法 | 优点 | 缺点 |
|---|---|---|
| 收集更多数据 | 提高违约数量 | 违约占比可能不变 |
| 对模型加惩罚 | 提升违约召回率 | 需要更多调参与维护 |
| 不同方式采样 | 技术改动最少 | 数据中违约更少 |
loan_status 创建两个新集合# 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 信用风险建模