數(shù)據(jù)分析
接上篇
針對(duì) 數(shù)據(jù)集的各個(gè)方面進(jìn)行簡單數(shù)據(jù)分析收班。
主要有
- 貸款基本情況
- 用戶畫像
- 平臺(tái)業(yè)務(wù)分析
數(shù)據(jù)分析主要方面
先說結(jié)論:
- 貸款基本情況:
- 貸款品質(zhì)中以好賬為主,占比高達(dá)92.46%,壞賬占比不到8%,情況樂觀怠肋;
- Lendding Club 平臺(tái)在2011到2015期間飛速發(fā)展,壞賬數(shù)量在2015年明顯下降淹朋,說明平臺(tái)開始重視對(duì)風(fēng)險(xiǎn)的控制笙各;
- 用戶畫像1:
- 用戶主要分布在加州,因?yàn)長ending Club總部在加州瑞你,對(duì)本地業(yè)務(wù)開拓比較深酪惭;其次是紐約州和德克薩斯州;
- 用戶職業(yè)主要都是老師者甲、管理者春感;
- 大部分用戶工作了10+年以上,其余用戶工作年限非常均勻虏缸,從1到9年的都有鲫懒,數(shù)量相差不多;
- 極大部分用戶年收入都大于20000美元,其中高于60000的用戶占比大于50%刽辙;
- 用戶畫像2:
- 大部分用戶貸款是為了債務(wù)整合(借新債還舊債)窥岩、還信用卡;
- 50% 以上用戶房子還在按揭宰缤,40%用戶還在租房颂翼,不到10%的用戶擁有自己的房子;
- 絕大部分用戶的 貶損公共設(shè)施的記錄次數(shù)小于三次
- 平臺(tái)業(yè)務(wù)分析
- 人均貸款數(shù)額逐年增加慨灭,2009年不到10000美元朦乏,在2015年達(dá)到16000美元。貸款總額逐年飆升氧骤,從2012年不到10億呻疹,到2015年接近60億进鸠。
- 信用等級(jí)越高结榄,貸款利率越低; 信用等級(jí)越高捅厂,好賬率越低
- 大部分貸款用戶的DTI低于35%费薄,這部分用戶還款壓力較小,一小部分客戶DIT達(dá)到40%冯遂,還款壓力大档冬,存在壞賬風(fēng)險(xiǎn)
1.貸款質(zhì)量情況
loanData.loan_status.value_counts()
# Current 558269
# Fully Paid 197119
# Charged Off 41288
# Late (31-120 days) 10683
# In Grace Period 5778
# Late (16-30 days) 2155
# Does not meet the credit policy. Status:Fully Paid 1862
# Default 1131
# Does not meet the credit policy. Status:Charged Off 697
# Issued 40
將逾期15天以上的貸款視為壞賬瞧柔,簡化貸款質(zhì)量
good_loan = [
'Current', 'Fully Paid',
'Does not meet the credit policy. Status:Fully Paid', 'Issued '
]
def loan_condition(status):
if status in good_loan:
return 'good_loan'
else:
return 'bad_loan'
loanData['loan_condition'] = loanData.loan_status.apply(loan_condition)
貸款質(zhì)量和貸款總額情況
#時(shí)間轉(zhuǎn)換為年
loanData['issue_d'] = pd.to_datetime(loanData.issue_d)
loanData['issue_year'] = loanData.issue_d.dt.year
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 6))
#貸款品質(zhì)情況
loanData.loan_condition.value_counts().plot.pie(
autopct='%1.2f%%', ax=ax1, fontsize=12, startangle=70)
ax1.set_title('GOOD OR BAD')
ax1.set_ylabel("% of Loan Condition")
ax1.legend()
#正負(fù)樣本數(shù)量差距懸殊语稠,對(duì)于后面建模而言是個(gè)很大問題
#發(fā)放貸款數(shù)量按照年度分布情況
sns.barplot(
x='issue_year',
y='loan_amnt',
data=loanData,
hue='loan_condition',
estimator=lambda x: len(x) / len(loanData) * 100,
ax=ax2)
ax2.set_title('Loan Amount by Year ')
ax2.set_ylabel('%')
ax2.set_xlabel('Issue Year')
ax2.legend()
貸款質(zhì)量和貸款總額百分比
可以看出纺荧,壞賬僅有不到8%,但是實(shí)際上的金額也是比較驚人的。
2011年后宙暇,貸款總額每年都在飆升
貸款人數(shù)量
f1, (ax3, ax4) = plt.subplots(1, 2, figsize=(16, 6))
day_dist = loanData.groupby(['issue_d']).size()
day_dist.plot(ax=ax3)
ax3.set_title('Amount of Borrowers by Day')
ax3.set_ylabel('Amount of borrowers')
ax3.set_xlabel('Time')
year_dist = loanData.groupby(['issue_year']).size()
year_dist.plot(kind='bar', ax=ax4)
ax4.set_title('Amount of Borrowers by Year')
ax4.set_ylabel('Amount of borrowers')
ax4.set_xlabel('Time')
#
貸款人數(shù)逐年飆升
可以看出2012年后Lending Club飛速發(fā)展,客戶飛速增加议泵,雖然有波動(dòng)占贫,但總體再增加
2.客戶畫像1
1-1地域分布
loanData.addr_state.value_counts()[:20].plot(kind='bar', figsize=(8, 4))
人數(shù)相差不大
2-1職業(yè)分布前20
#客戶畫像1-2:職業(yè)分布前20
loanData.emp_title.value_counts()[:20].plot(kind='bar', figsize=(8, 4))
職業(yè)分布
各行各業(yè)的人都有,居然是老師最多先口,管理者次之型奥。
1-3:工作年限分布
#客戶畫像1-3:工作年限分布
loanData.emp_length.value_counts().plot(kind='bar')
工作年限分布
工作年限越長越容易貸款嗎,看來是了
1-4: 用戶年收入(美元)分布
這里將年收入大致分為三個(gè)區(qū)間
20000以下的視為低年收入碉京,20000-60000視為中等厢汹,高于60000的就是高收入人群
#客戶畫像1-4: 用戶年收入收入分布
def inc_strata(income):
if income <= 20000:
return 'low'
elif income > 2000 and income <= 60000:
return 'mid'
else:
return 'hign'
loanData['inc_strata'] = loanData.annual_inc.apply(inc_strata)
loanData.inc_strata.value_counts().plot(kind='bar')
年收入分布
大部分客戶年收入都在20000以上
#貸款質(zhì)量與年收入的關(guān)系
sns.countplot(x='inc_strata', data=loanData, hue='loan_condition')
貸款質(zhì)量與年收入的關(guān)系
中等人群壞賬數(shù)量最多
2-1 貸款目的分布
#客戶畫像2-1 貸款目的分布
loanData.purpose.value_counts().plot(kind='barh')
貸款目的
可以看出人們貸款主要是為了債務(wù)整合和信用卡償還,債務(wù)整合就是借信用卡還其他信用卡谐宙,和信用卡償還貌似沒區(qū)別
2-2 住房類型分布
#客戶畫像2-2 住房類型分布
loanData.home_ownership.value_counts().plot.pie(
autopct='%.3f%%', figsize=(5, 5))
住房類型
一半客戶按揭烫葬,四成客戶租房。有房子的不足10%
2-3 貶損公共記錄的次數(shù)
#客戶畫像2-3 貶損公共記錄的次數(shù)
loanData.pub_rec.value_counts()[:3].plot(kind='bar')
貶損公共記錄的次數(shù)
看來有不良記錄的人很難申請(qǐng)貸款
業(yè)務(wù)分析
1-1 貸款量明細(xì):每年人均貸款總額凡蜻,年均貸款總金額
#業(yè)務(wù)分析1-1 貸款量明細(xì):每年人均貸款總額搭综,年均貸款總金額
f1, (ax4, ax5) = plt.subplots(1, 2, figsize=(16, 6))
loanData.groupby(['issue_year'])['loan_amnt'].mean().plot(kind='bar', ax=ax4)
ax4.set_xlabel('Year')
ax4.set_ylabel('Loan Amount per Capita')
loanData.groupby(['issue_year'])['loan_amnt'].sum().plot(kind='bar', ax=ax5)
ax5.set_xlabel('Year')
ax5.set_ylabel('Total Loan Amount')
貸款量明細(xì)
LC在2012-2015飛速發(fā)展,能發(fā)的錢越來越多
1-2平均貸款利率與信用等級(jí)關(guān)系划栓、貸款情況與信用等級(jí)的關(guān)系
#業(yè)務(wù)分析1-2
f2, (ax6, ax7) = plt.subplots(1, 2, figsize=(20, 6))
groupby_grade = loanData.groupby(['grade'])
groupby_grade['int_rate'].mean().plot(kind='bar', ax=ax6)
ax6.set_title('Interest Rate vs Grade')
ax6.set_ylabel('Interest Rate')
ax6.set_xlabel('Grade')
#
sns.countplot(x='grade', data=loanData, hue='loan_condition', ax=ax7)
ax7.set_title('Amount of Borrower vs Grade')
ax7.set_ylabel('Amount of Borrower')
信用等級(jí)關(guān)系很大
信用等級(jí)越低兑巾,貸款利率越高
1-3 DTI分布情況
DTI:每月還款占月收入的比例
#業(yè)務(wù)分析1-3 DTI分布情況
#DTI 每月還款占月收入的比例
f3, ax8 = plt.subplots(1, 1, figsize=(8, 4))
loanData.dti.plot(kind='hist', bins=100, ax=ax8)
ax8.set_xlim(left=0, right=50)
DIT分布
大部分的貸款客戶的DTI在35%以下,說明還款壓力不是很大
一小部分客戶DIT達(dá)到45%忠荞,存在風(fēng)險(xiǎn)
后續(xù)特征工程中將以35%為分界 分為兩類
在右側(cè)看不見的地方還存在極小一部分蒋歌,,基本屬于風(fēng)險(xiǎn)很大的貸款
1-4 貸款期限分布
#業(yè)務(wù)分析1-4 貸款期限分布
sns.countplot(x='term', data=loanData)
貸款期限
LC平臺(tái)以短期貸款為主委煤,但長期貸款比例也不低