##3.2检察LoanStatus的详细内容PastDue <- c("Past Due (>120 days)","Past Due (1-15 days)","Past Due (16-30 days)", "Past Due (31-60 days)","Past Due (61-90 days)","Past Due (91-120 days)")##标签為Past Due的同一归类為PastDuenewloandata$LoanStatus[newloandata$LoanStatus %in% PastDue] <- "PastDue"##cancelled归类到current中newloandata$LoanStatus[newl兒童生日禮物,oandata$LoanStatus=="Cancelled"]<-"Current"##defaulted归类為chargedoffnewloandata$LoanStatus[newloandata$LoanStatus=="Defaulted"]<-"Chargedoff"##FinalPaymentInProgress归类為completednewloandata$LoanStatus[newloandata$LoanStatus=="FinalPaymentInProgress"]<-"Completed"##检察数据table(newloandata$LoanStatus)
###画圖看是不是可用中位数弥补缺失值library(ggplot2)library(ggthemes)ggplot(newloandata,aes(x=CreditScore,))+ geom_density(fill="pink",alpha=0.4)+ geom_vline(aes(xintercept=median(CreditScore,na.rm = T)),colour="red",linetype="dashed",lwd=1)+ theme_few()+ggtitle("The density of CreditScore")
ggplot(newloandata,aes(x=InquiriesLast6Months,))+ geom_density(fill="skyblue",alpha=0.4)+ geom_vline(aes(xintercept=median(InquiriesLast6Months,na.rm = T)),colour="red",linetype="dashed",lwd=1)+ theme_few()+ggtitle("The density of InquiriesLast6Months")
ggplot(newloandata,aes(x=DelinquenciesLast7Years,))+ geom_density(fill="blue",alpha=0.4)+ geom_vline(aes(xintercept=median(DelinquenciesLast7Years,na.rm = T)),colour="red",linetype="dashed",lwd=1)+ theme_few()+ggtitle("The density of DelinquenciesLast7Years")
ggplot(newloandata,aes(x=BankcardUtilization,))+ geom_density(fill="grey",alpha=0.4)+ geom_vline(aes(xintercept=median(BankcardUtilization,na.rm = T)),colour="red",linetype="dashed",lwd=1)+ theme_few()+ggtitle("The density of BankcardUtilization")
library(ggplot2)###1.受雇佣状况延续時候與貸款状况的瓜葛?newloandata$EmploymentStatusDuration <- as.integer(newloandata$EmploymentStatusDuration)ggplot(data = newloandata, aes(x = EmploymentStatusDuration, color = LoanStatus)) + geom_line(aes(label = ..count..), stat = 'bin') + labs(title = "The LoanStatus By EmploymentStatusDuration", x = "EmploymentStatusDuration", y = "Count", fill = "LoanStatus")
###2.告貸人是不是有衡宇和貸款状况的瓜葛?mosaicplot(table(newloandata$IsBorrowerHomeowner,newloandata$LoanStatus),main="The Loanstatus By IsBorrowerHomeowner", color = c('pink','skyblue'))
###3.消费信誉分與貸款状况的瓜葛?options(digits=1)newloandata$CreditScore <- newloandata$CreditScoreclass(newloandata$CreditScore)ggplot(data = newloandata, aes(x = CreditScore, color = LoanStatus)) + geom_line(aes(label = ..count..), stat = 'bin') + labs(title = "The LoanStatus By CreditScore", x = "CreditScore", y = "Count", fill = "LoanStatus")
ggplot(data = newloandata[newloandata$InquiriesLast6Months < 20,], aes(x = InquiriesLast6Months, color = LoanStatus)) + geom_line(aes(label = ..count..), stat = 'bin') + labs(title = "The LoanStatus By InquiriesLast6Months", x = "InquiriesLast6Months", y = "Count", fill = "LoanStatus")
###5.信誉品级與貸款状况的瓜葛?par(mfrow=c(2,1))###斟酌2009年7月1日以前的信誉品级對貸款状况的影响:CreditGrademosaicplot(table(loandata_before$CreditGrade,loandata_before$LoanStatus),main="The Loanstatus By CreditGrade", color = c('pink','skyblue'))###斟酌2009年7月1日以後的信誉品级對貸款状况的影响:ProsperRating.Alphamosaicplot(table(loandata_after$ProsperRating.Alpha,loandata_after$LoanStatus),main="The Loanstatus By ProsperRating.Alpha", color = c('pink','skyblue'))
ggplot(data = newloandata,aes(x = DelinquenciesLast7Years, color = LoanStatus)) + geom_line(aes(label = ..count..), stat = 'bin') + labs(title = "The LoanStatus By DelinquenciesLast7Years", x = "DelinquenciesLast7Years", y = "Count", fill = "LoanStatus")
###10.债務收入比例與貸款状况的瓜葛?ggplot(data = newloandata[newloandata$DebtToIncomeRatio < 1,], aes(x = DebtToIncomeRatio, color = LoanStatus)) + geom_line(aes(label = ..count..), stat = 'bin') + labs(title = "The LoanStatus By DebtToIncomeRatio", x = "DebtToIncomeRatio", y = "Count", fill = "LoanStatus")
债務比越低,還款率越高,也就是说貸款人自己的债務不高的环境下,具有還款能力越高。
4.11 告貸标利率與貸款状况的瓜葛?
###11.告貸标利率與貸款状况的瓜葛?ggplot(data = newloandata, aes(x = BorrowerRate, color = LoanStatus)) + geom_line(aes(label = ..count..), stat = 'bin') + labs(title = "The LoanStatus By BorrowerRate", x = "BorrowerRate", y = "Count", fill = "LoanStatus")