项目目的:利用车贷金融数据建立评分卡,并尝试多次迭代观察不同行为对模型,以及建模中间过程产生哪些影响。

首先是标准化导入需要使用的工具

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use("ggplot")#风格设置
import seaborn as sns
sns.set_style("whitegrid")
%matplotlib inline
import warnings #忽略错误模块
warnings.filterwarnings("ignore")
plt.rcParams["font.sans-serif"]=["SimHei"] #指定默认字体

导入需要的数据

acc = pd.read_csv('accepts.csv')  #通过的客户
rej = pd.read_csv('rejects.csv')  #拒绝的客户
pd.set_option("display.max_columns",len(acc.columns))#解决全部显示的问题
acc.head()

汽车金融评分卡

 

 各变量含义介绍:       #中文含义

#中文含义
##application_id---申请者ID
##account_number---帐户号
##bad_ind---是否违约
##vehicle_year---汽车购买时间
##vehicle_make---汽车制造商
##bankruptcy_ind---曾经破产标识
##tot_derog---五年内信用不良事件数量(比如手机欠费消号)
##tot_tr---全部帐户数量
##age_oldest_tr---最久账号存续时间(月)
##tot_open_tr---在使用帐户数量
##tot_rev_tr---在使用可循环贷款帐户数量(比如信用卡)
##tot_rev_debt---在使用可循环贷款帐户余额(比如信用卡欠款)
##tot_rev_line---可循环贷款帐户限额(信用卡授权额度)
##rev_util---可循环贷款帐户使用比例(余额/限额)
##fico_score---FICO打分
##purch_price---汽车购买金额(元)
##msrp---建议售价
##down_pyt---分期付款的首次交款
##loan_term---贷款期限(月)
##loan_amt---贷款金额
##ltv---贷款金额/建议售价*100
##tot_income---月均收入(元)
##veh_mileage---行使历程(Mile)
##used_ind---是否使用
##weight---样本权重

汽车金融评分卡

 

 汽车金融评分卡

 

 数据清洗

1.缺失值处理

 数值数据处理

acc_Floatcolumns=[i for i in acc.columns if acc[i].dtype=="float"]
rej_Floatcolumns=[i for i in rej.columns if rej[i].dtype=="float"]

汽车金融评分卡

 

 汽车金融评分卡

 

 利用Imputer 模块进行缺失值填充

from sklearn.preprocessing import Imputer#只支持 均值,中位数,众数填补
inputer = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0)
inputer = inputer.fit(X)
X = inputer.transform(X)
主要参数说明:
missing_values:缺失值,可以为整数或NaN(缺失值numpy.nan用字符串‘NaN’表示),默认为NaN

strategy:替换策略,字符串,默认用均值‘mean’替换

①若为mean时,用特征列的均值替换

②若为median时,用特征列的中位数替换

③若为most_frequent时,用特征列的众数替换

axis:指定轴数,默认axis=0代表列,axis=1代表行

copy:设置为True代表不在原数据集上修改,设置为False时,就地修改,存在如下情况时,即使设置为False时,也不会就地修改

①X不是浮点值数组

②X是稀疏且missing_values=0

③axis=0且X为CRS矩阵

④axis=1且X为CSC矩阵

statistics_属性:axis设置为0时,每个特征的填充值数组,axis=1时,报没有该属性错误
Imputer 模块参数说明

相关文章:

  • 2021-11-18
  • 2021-05-12
  • 2021-09-25
  • 2021-10-08
  • 2021-05-29
  • 2021-11-22
  • 2021-04-30
  • 2021-07-29
猜你喜欢
  • 2021-04-20
  • 2021-07-03
  • 2021-07-30
  • 2022-01-18
  • 2021-04-30
  • 2021-05-05
  • 2022-01-19
相关资源
相似解决方案