DW金融风控-task01赛题理解

Task01 赛题理解

总数据量超过 120w,包含47列变量信息,其中15列为匿名变量。从80万条作为训练集,20 万条作为测试集A,20万条作为测试集B,同时会对employmentTitle、purpose、postCode和title等信息进行脱敏。

一、 预测指标 AUC

1. 混淆矩阵(Confuse Matrix)

TP、FN、FP、TN
 (1)若一个实例是正类,并且被预测为正类,即为真正类TP(True Positive) 
 (2)若一个实例是正类,但是被预测为负类,即为假负类FN(False Negative) 
 (3)若一个实例是负类,但是被预测为正类,即为假正类FP(False Positive) 
 (4)若一个实例是负类,并且被预测为负类,即为真负类TN(True Negative)

2. 准确率(Accuracy)

Accuracy=(TP+TN)/(TP+TN+FP+FN)

3. 精确率(Precision)

又称查准率,正确预测为正样本(TP)占预测为正样本(TP+FP)的百分比。

4. 召回率(Recall)

又称为查全率,正确预测为正样本(TP)占正样本(TP+FN)的百分比。

5. F1 Score

F1 Score=2/(1/Precision+1/Recall)

6. P-R曲线(Precision-Recall Curve)

横轴为Recall,纵轴为Precision

7. ROC(Receiver Operating Characteristic)

假正例率(FPR)定义为 X 轴,真正例率(TPR)定义为 Y 轴.

TPR:在所有实际为正例的样本中,被正确地判断为正例之比率.
FPR:在所有实际为负例的样本中,被错误地判断为正例之比率.

8. AUC(Area Under Curve)

被定义为 ROC曲线下与坐标轴围成的面积.
在0.5-1之间, AUC越接近1.0, 检测方法真实性越高.

9. KS(Kolmogorov-Smirnov)

K-S曲线将真正例率和假正例率都作为纵轴,横轴则由选定的阈值来充当.
KS = max(TPR - FPR)
KS值[0.3,0.5],模型具有较强的区分能力.

二、赛题流程在这里插入图片描述

三、代码示例

1. pandas数据读取

	import pandas as pd
	train = pd.read_csv('train.csv')
	testA = pd.read_csv('testA.csv')

2. 分类指标评价计算实例

a. 混淆矩阵

import numpy as np
from sklearn.metrics import confusion_matrix
y_pred = [0, 1, 0, 1]
y_true = [0, 1, 1, 0] 
print('混淆矩阵:\n',confusion_matrix(y_true, y_pred))
混淆矩阵: [[1 1] [1 1]]

b. accuracy

from sklearn.metrics import accuracy_score y_pred = [0, 1, 0, 1]
y_true = [0, 1, 1, 0] print('ACC:',accuracy_score(y_true, y_pred))
ACC: 0.5

c. Precision,Recall,F1-score

from sklearn import metrics
y_pred = [0, 1, 0, 1]
y_true = [0, 1, 1, 0] print('Precision',metrics.precision_score(y_true, y_pred)) print('Recall',metrics.recall_score(y_true, y_pred)) print('F1-score:',metrics.f1_score(y_true, y_pred))
Precision 0.5 
Recall 0.5 
F1-score: 0.5

d. P-R曲线

import matplotlib.pyplot as plt
from sklearn.metrics import precision_recall_curve
y_pred = [0, 1, 1, 0, 1, 1, 0, 1, 1, 1]
y_true = [0, 1, 1, 0, 1, 0, 1, 1, 0, 1]
precision, recall, thresholds = precision_recall_curve(y_true, y_pred) plt.plot(precision, recall)

e. ROC曲线

from sklearn.metrics import roc_curve
y_pred = [0, 1, 1, 0, 1, 1, 0, 1, 1, 1] y_true = [0, 1, 1, 0, 1, 0, 1, 1, 0, 1] FPR,TPR,thresholds=roc_curve(y_true, y_pred) plt.title('ROC')
plt.plot(FPR, TPR,'b') plt.plot([0,1],[0,1],'r--') plt.ylabel('TPR')
plt.xlabel('FPR')

在这里插入图片描述

f. AUC

import numpy as np
from sklearn.metrics import roc_auc_score
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8]) print('AUC socre:',roc_auc_score(y_true, y_scores))
AUC socre: 0.75

g. KS值

# 在实际操作时往往使用ROC曲线配合求出KS值 from sklearn.metrics import roc_curve
y_pred = [0, 1, 1, 0, 1, 1, 0, 1, 1, 1] y_true = [0, 1, 1, 0, 1, 0, 1, 1, 1, 1] FPR,TPR,thresholds=roc_curve(y_true, y_pred) KS=abs(FPR-TPR).max()
print('KS值:',KS)
KS值: 0.5238095238095237

四、评分卡

评分卡是一张拥有分数刻度会让相应阈值的表. 信用评分卡是用于用户信用的一张刻度表. 评分卡是金融风控中常用的一种对于用户信用进行刻画的手段.

五、补充

  1. id 为贷款清单分配的唯一信用证标识
  2. loanAmnt 贷款金额
    1. term贷款期限(year)
  3. interestRate 贷款利率
  4. installment 分期付款金额
  5. grade 贷款等级
  6. subGrade贷款等级之子级
  7. employmentTitle就业职称
  8. employmentLength就业年限(年)
  9. homeOwnership 借款人在登记时提供的房屋所有权状况
  10. annualIncome 年收入
  11. verificationStatus 验证状态
  12. issueDate 贷款发放的月份
  13. purpose 借款人在贷款申请时的贷款用途类别
  14. postCode 借款人在贷款申请中提供的邮政编码的前3位数字
  15. regionCode 地区编码
  16. dti 债务收入比
  17. delinquency_2years 借款人过去2年信用档案中逾期30天以上的违约事件数
  18. ficoRangeLow 借款人在贷款发放时的fico所属的下限范围
  19. ficoRangeHigh 借款人在贷款发放时的fico所属的上限范围
  20. openAcc 借款人信用档案中未结信用额度的数量
  21. pubRec 贬损公共记录的数量
  22. pubRecBankruptcies 公开记录清除的数量
  23. revolBal 信贷周转余额合计
  24. revolUtil 循环额度利用率,或借款人使用的相对于所有可用循环信贷的信贷金额
  25. totalAcc 借款人信用档案中当前的信用额度总数
  26. initialListStatus 贷款的初始列表状态
  27. applicationType 表明贷款是个人申请还是与两个共同借款人的联合申请
  28. earliesCreditLine 借款人最早报告的信用额度开立的月份
  29. title 借款人提供的贷款名称
  30. policyCode 公开可用的策略 =1 代码=2
  31. n系列匿名特征 匿名特征n0-n14,为一些贷款人行为计数特征的处理
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值