Dataset
本文的目的是探索银行信用卡批准系统的预测性能
- 本文的数据集credit.csv提供了关于用户信用卡信息,总共两个属性:
paid:是否偿还了信用卡
model_score:银行批准其办理信用卡的概率(通过银行的预测系统计算出来的)
import matplotlib.pyplot as plt
import pandas
credit = pandas.read_csv("credit.csv")
print(credit.head(10))
plt.scatter(credit["model_score"], credit["paid"])
plt.show()
'''
paid model_score
0 1 0.787062
1 1 0.959871
2 1 0.881820
3 1 0.918720
4 1 0.776411
5 1 0.541068
6 1 1.000000
7 1 0.882755
8 1 0.705474
9 1 0.818945
'''
Predictive Power
观察上面的数据,第二列是模型预测的结果。为了确定一个是否批准一个用户办理信用卡,我们可以设置一个阈值(discrimination threshold)。比如,我们将其设置为0.6,那么大于0.6的我们就对其接受,其他的就拒绝。
- 下面代码将阈值设置为0.5,然后将model_score中大于0.5的表示允许办理行用卡,那么与实际是否换卡的信息paid进行比较即可得到模型的精确度:
# Will we approve the credit card based on the probability of paying?
pred = credit["model_score"] > 0.5
# boolean型数据与0,1值可以进行比较
accuracy = sum(pred == credit["paid"]) / len(pred)
print(accuracy)
'''
accuracy :0.86830015313935682
'''
Sensitivity, Specificity, And Fall-Out
银行想要多盈利,那么必然要尽可能多的放贷,同时也要考虑风险,那么他们会倾向于拒绝有很高的违约概率的客户,但是会允许有适当的违约概率的用户。因此预测的精确度并不是一个很好的度量准则。
下面是二分类中很重要的几个度量值:
Sensitivity or True Postive Rate(灵敏度或真阳性率TPR):可以放贷的用户中,真正对其放贷的比例(越高越好,带来更多利润)