lend_club 全球最大的P2P平臺2007~2012年貸款數據百度云下載。
此文章基于R語言做簡單分析。
rm(list=ls()) #清除變量
gc() #釋放內存
- step1
考慮到后續分析
將數據導入sqlserver,用到SSIS
如圖
**此處有坑
- step2
連接sqlserver,并將數據讀入R。
library(RODBC)
con<-odbcConnect("LI") # LI 是本地數據庫,con~connect 是本地連接RODBC Connection 2
Details:case=nochangeDSN=LIUID=Trusted_Connection=YesAPP=RStudioWSID=LIYI-PClend_club1<-sqlQuery(con,"SELECT sum([Amount Requested]) as sumamount,[Application Date] as date_1,[year],substring(convert(varchar(12),[Application Date],111),6,5) as month_dayFROM [liyi_test].[dbo].[lend_club]group by [year],substring(convert(varchar(12),[Application Date],111),6,5),[Application Date]order by [year],[month_day]") head(lend_club1)
sumamount date_1 year month_day
1 2000 2007-05-26 2007 05/26
2 47400 2007-05-27 2007 05/27
3 23900 2007-05-28 2007 05/28
4 121050 2007-05-29 2007 05/29
5 87500 2007-05-30 2007 05/30
6 46500 2007-05-31 2007 05/31
library(ggplot2)qplot(date_1,sumamount,data=lend_club1,geom="line") # 每天貸款金額的時序圖
p<-qplot(month_day,sumamount,data=lend_club1)
p+facet_wrap(~year) #2007-2012 期間每日的貸款金額
library(tidyr)
library(dplyr)
lend_club2<-separate(lend_club1,date_1,c("y","m","d"),sep="-")
head(lend_club2)sumamount y m d year month_day
1 2000 2007 05 26 2007 05/26
2 47400 2007 05 27 2007 05/27
3 23900 2007 05 28 2007 05/28
4 121050 2007 05 29 2007 05/29
5 87500 2007 05 30 2007 05/30
6 46500 2007 05 31 2007 05/31 lend_club3<-unite(lend_club2,"y_m",y,m,sep="-",remove = F)
head(lend_club3)sumamount y_m y m d year month_day
1 2000 2007-05 2007 05 26 2007 05/26
2 47400 2007-05 2007 05 27 2007 05/27
3 23900 2007-05 2007 05 28 2007 05/28
4 121050 2007-05 2007 05 29 2007 05/29
5 87500 2007-05 2007 05 30 2007 05/30
6 46500 2007-05 2007 05 31 2007 05/31qplot(m,sumamount,data=lend_club3,geom=c("boxplot")+facet_wrap(~year) #2007~2012年每月貸款金額的箱線圖
lend_club4<- lend_club3%>%group_by(m,y)%>%summarise(total_m=sum(sumamount))lend_club4
head(lend_club4)
Source: local data frame [6 x 3]
Groups: m [2]m y total_m(chr) (chr) (dbl)
1 01 2008 32256329
2 01 2009 28523635
3 01 2010 63082946
4 01 2011 171186425
5 01 2012 297667575
6 02 2008 20596688 折線圖 分面
p<-qplot(m,total_m,data=lend_club4)+geom_smooth(aes(group=y,colour=y),method = "lm")
折線圖 分面
p<-qplot(m,total_m,data=lend_club4)+geom_smooth(aes(group=y,colour=y))
p+facet_wrap(~y)
lend<-read.csv("C:\\Users\\liyi\\Desktop\\lend_club.csv")
lend1<-read.csv("C:\\Users\\liyi\\Desktop\\lend_club.csv",header = F)
lend1<-lend1[-1,]
head(lend1)
lend1<-lend1[,c(1,3,9)]
myvar<-c("amount","year","employment")
names(lend1)<-myvar
head(lend1)
str(lend1)
lend1$amountnew<-as.numeric(as.character(lend1$amount))library(sqldf)lend2<-sqldf('select sum(V1),V3,V9from lend1group by V3,V9')
q<-qplot(employment,amountnew,data = lend1,geom=c("boxplot"),colour=lend1$employment)+facet_wrap(~year)
q<- q+theme(axis.text.x=element_text(angle=90,hjust=1,colour="black"),legend.position='none')
q<- q+scale_y_continuous(limits = c(0, 100000))
q
轉載于:https://www.cnblogs.com/li-volleyball/p/5722049.html
總結
以上是生活随笔為你收集整理的R可视化lend_club 全球最大的P2P平台数据75W条的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。