金融评分卡模型

数据分析:汽车金融评分卡模型

目录

在这里插入图片描述

一、项目目的

1,背景
评分卡被广泛用于互联网金融企业和保险银行机构来解决目前信用风控问题,根据已有的数据,提供用户违约/预期等行为的概率指标预测。
其中申请评分卡,可以将风险控制在贷前的状态,也就是减少客户违约而造成经济损失的风险,是风险控制的重要一个环节,故建立准确的申请评分卡能够有效降低金融机构的财产损失风险。

2,目标
借助贷款违约数据,建立汽车金融(贷款违约)分类模型与客户申请评分卡,判断客户违约的可能性;
当有一个新的客户申请时,参考评分卡可以生成直接评分,判断用户是否较安全,并结合模型表现可以大致预估其违约概率,为是否放贷提供决策建议。

3,内容
根据汽车金融贷款违约数据,按照各类客户(同意贷款客户/拒绝贷款客户)的各维度特征与是否违约情况数据信息,结合LR、LRCV算法建立分类模型,利用ROC曲线、KS曲线评估模型分类效果。

二、数据处理

2.1 导入模块

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.neighbors import KNeighborsClassifier
from fancyimpute import KNN
from PyWoE import woe
from sklearn.model_selection import train_test_split
import itertools
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LogisticRegressionCV
from sklearn.metrics import confusion_matrix,recall_score,classification_report
from sklearn.metrics import confusion_matrix,recall_score,classification_report
from sklearn.metrics import roc_curve, auc
warnings.filterwarnings('ignore')
from pylab import mpl
plt.rcParams['font.sans-serif']='Microsoft YaHei'
plt.rcParams['figure.dpi']=100
from matplotlib import rcParams
rcParams['axes.unicode_minus']=False
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('max_colwidth',100)

2.2 导入数据
总数据包括了被接受的客户相关信息,以及被拒绝的客户相关信息

accepts = pd.read_csv(r'C:\accepts.csv')
rejects= pd.read_csv(r'C:\rejects.csv')

数据大致信息

accepts.info()  
Data columns (total 25 columns):		#总共25个特征,部分存在缺失值
application_id    5845 non	null int64	#申请者ID
account_number    5845 non	null int64	#帐户号
bad_ind           5845 non	null int64	#是否违约
vehicle_year      5844 non	null float64#汽车购买时间
vehicle_make      5546 non	null object	#汽车制造商
bankruptcy_ind    5628 non	null object	#曾经破产标识
tot_derog         5632 non	null float64#五年内信用不良事件数量(比如手机欠费消号)
tot_tr            5632 non	null float64#全部帐户数量
age_oldest_tr     5629 non	null float64#最久账号存续时间(月)
tot_open_tr       4426 non	null float64#在使用帐户数量
tot_rev_tr        5207 non	null float64#在使用可循环贷款帐户数量(比如信用卡)
tot_rev_debt      5367 non	null float64#在使用可循环贷款帐户余额(比如信用卡欠款)
tot_rev_line      5367 non	null float64#可循环贷款帐户限额(信用卡授权额度)
rev_util          5845 non	null int64	#可循环贷款帐户使用比例(余额/限额)
fico_score        5531 non	null float64#FICO打分
purch_price       5845 non	null float64#汽车购买金额(元)
msrp              5844 non	null float64#建议售价
down_pyt          5845 non	null float64#分期付款的首次交款
loan_term         5845 non	null int64	#贷款期限(月)
loan_amt          5845 non	null float64#贷款金额
ltv               5844 non	null float64#贷款金额/建议售价*100
tot_income        5840 non	null float64#月均收入(元)
veh_mileage       5844 non	null float64#行驶里程(Mile)
used_ind          5845 non	null int64	#是否使用
weight            5845 non	null float64#样本权重
dtypes: float64(17), int64(6), object(2)		

查看拒绝用户大致信息,拒绝用户有22个特征,缺少bad_ind是否违约, account_number账户号, weight样本权重这三个特征,这里违约情况已经给出,不需要定义违约

rejects.info()	

2.3 数据可视化

#各个变量的缺失值比例,都小于30%
num_of_null=accepts.isnull().sum()/accepts.shape[0]).sort_values(ascending=False)
num_of_null.plot(kind='bar')

在这里插入图片描述

#accepts中好坏客户的比重,大约为4:1
num_1=accepts.bad_ind.sum()
num_0=accepts.bad_ind.count()-num_1
ratio_1=num_1/(num_1+num_0)
ratio_0=1-ratio_1
plt.subplot(121)
sns.barplot(x=['good','bad'],y=[num_0,num_1])
plt.text(0,num_0+50,num_0,ha='center',va='baseline',fontsize=10)
plt.text(1,num_1+50,num_1,ha='center',va='baseline',fontsize=10)
plt.subplot(122)
plt.pie([num_0,num_1],labels=['good','bad'],autopct='%2.1f%%',startangle=90,explode=[0,0.1],textprops={
   'fontsize':10})
plt.axis('equal')
plt.suptitle('好坏客户的比重')

在这里插入图片描述
2.4 拒绝推断
客户总体包含两类人群(接受客户、拒绝客户),对所有客户进行分析,以防止选择偏差,故推断拒绝用户的特征。
这里使用KNN方式进行拒绝推断,和比例分配的方式

2.4.1KNN拒绝推断

#由于KNN的性质,取出accepts中的部分连续变量作为特征变量,预测目标变量bad_ind,这里使用相关系数进行筛选,选出相关系数较大的
corr=accepts.corr()
#sns.heatmap(corr)
#plt.title('correlation')
corr.bad_ind.abs().sort_values(ascending=False).head(10)
bad_ind          1.000000
weight           1.000000
fico_score       0.328627
tot_rev_line     0.193812
age_oldest_tr    0.178258
tot_derog        0.160237
ltv              0.152730
tot_tr           0.119947
rev_util         0.112972
veh_mileage      0.064927
#排除bad_ind, weight后,其他变量中,tot_tr, age_oldest_tr, tot_rev_line之间存在较强的线性相关性,故最后选择了"tot_derog","age_oldest_tr","rev_util","fico_score","ltv"作为分析变量

def KNN_RI(accepts,rejects,n_neighbors=5, weights='distance'):#用KNN进行拒绝推断,设定KNN参数
    accepts_x = accepts[["tot_derog","age_oldest_tr","rev_util","fico_score","ltv"]]#选择连续变量作为特征变量
    accepts_y = accepts['bad_ind']
    rejects_x = rejects[["tot_derog","age_oldest_tr","rev_util","fico_score","ltv"]]
    #缺失值处理
    accepts_x.fillna(accepts_x.mean(),inplace=True
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值