-
Notifications
You must be signed in to change notification settings - Fork 1
/
prosperLoanData.Rmd
730 lines (566 loc) · 27.3 KB
/
prosperLoanData.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
---
output:
pdf_document: default
html_document: default
---
"Prosper Loan Data Exploration"
Saeid Rostami
========================================================
```{r echo=FALSE, message=FALSE, warning=FALSE, packages}
library(ggplot2)
library(dplyr)
library(gridExtra)
library(lubridate)
```
```{r echo=FALSE, Load_the_Data}
# Load the Data
prosper_data <- read.csv("prosperLoanData.csv")
```
# Summary of Data
```{r echo=FALSE}
nrow(prosper_data)
ncol(prosper_data)
```
Prosper which was founded in 2005 is a peer-to-peer lending platform that people can invest in each other. Prosper connects people who need money with those who have money to invest. Prosper loan data contain 113,937 rows with 81 columns.
```{r echo=FALSE}
names(prosper_data)
```
# Creating new dataframe based on prosper data
```{r echo=FALSE}
df <- prosper_data[, c("DelinquenciesLast7Years", "PublicRecordsLast10Years")]
today <- Sys.Date()
df$DaysWithCreditLine <- as.numeric(
floor(
difftime(today,
as.Date(prosper_data$FirstRecordedCreditLine,
"%Y-%m-%d %H:%M:%S")
)
)
)
df$InquiriesLast6Months <- prosper_data$InquiriesLast6Months
# Rate, Terms, Score and Listing creation date
df$BorrowerRate <- prosper_data$BorrowerRate
df$Term <- factor(prosper_data$Term)
df$ProsperRating <- factor(prosper_data$ProsperRating..Alpha., levels = c("AA", "A", "B", "C", "D", "E", "HR"))
df$ListingCreationDate <- prosper_data$ListingCreationDate
# Amount, employment status and listing category
df$LoanOriginalAmount <- prosper_data$LoanOriginalAmount
df$ListingCategory <- factor(prosper_data$ListingCategory..numeric.,
labels=c("Not available", "Debt consolidation",
"Home improvement", "Business",
"Personal loan", "Student use",
"Auto", "Other", "Baby & Adoption Loans",
"Boat", "Cosmetic Procedures",
"Engagement Ring Financing",
"Green Loans", "Household Expenses",
"Large Purchases", "Medical/Dental",
"Motorcycle", "RV", "Taxes",
"Vacation", "Wedding Loans"))
df$EmploymentStatus <- prosper_data$EmploymentStatus
df$AnnualIncome <- prosper_data$StatedMonthlyIncome * 12
df$RevolvingCreditBalance <- prosper_data$RevolvingCreditBalance
str(df)
summary(df)
```
# Univariate Plots Section
## Loan original amount
```{r echo=FALSE, warning=FALSE, Univariate_Plots}
ggplot(data = df) +
geom_histogram(aes(x = LoanOriginalAmount),binwidth=700) +
scale_x_continuous(
limits = c(0, quantile(df$LoanOriginalAmount, 0.99, na.rm = TRUE)),
breaks = seq(0, quantile(df$LoanOriginalAmount, 0.99, na.rm = TRUE), 1000)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
From the figure above we can see the amont of money that people borrow and as we can see people tend to borrow in whole numbers.
```{r echo= FALSE, warning= FALSE}
summary(df$LoanOriginalAmount)
```
The minimum money that people borrowed is 1000 as opposed to maximum, which is 35000. the median and mean are 6500 and 8337 respectively.
## Loan category
```{r echo= FALSE, warning= FALSE}
ggplot(data = df) +
geom_bar(aes(x = ListingCategory)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
Sounds like most people borrow to cover their debts.
## Employment status
```{r echo=FALSE, warning=FALSE}
ggplot( data = df) +
geom_bar(aes(x = EmploymentStatus)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
As we can see most of the borrowers are employed.
## Income status
```{r echo=FALSE, warning=FALSE}
ggplot( data = df) +
geom_histogram(aes(x = AnnualIncome),binwidth = 2000) +
scale_x_continuous(
limits = c(0, quantile(df$AnnualIncome, 0.99, na.rm = TRUE)),
breaks = seq(0, quantile(df$AnnualIncome, 0.99, na.rm = TRUE), 10000)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
```{r echo=FALSE, warning= FALSE}
summary(df$AnnualIncome)
```
The majority of income are between 20000 and 90000 annually. The median is 56000 and the mean is 67296.
## Payment history
```{r echo= FALSE, warning=FALSE}
plot1 <- ggplot(data = df) +
geom_histogram(aes(x = DelinquenciesLast7Years),binwidth = 1) +
scale_x_continuous(
limits = c(0, quantile(df$DelinquenciesLast7Years, 0.99, na.rm = TRUE)),
breaks = seq(0, quantile(df$DelinquenciesLast7Years, 0.99, na.rm = TRUE), 5)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))+
coord_cartesian(ylim = c(0,4000))
plot2 <- ggplot( data = df) +
geom_histogram(aes(x = PublicRecordsLast10Years),binwidth = 1) +
scale_x_continuous(
limits = c(0, quantile(df$PublicRecordsLast10Years, 0.99, na.rm = TRUE)),
breaks = seq(0, quantile(df$PublicRecordsLast10Years, 0.99, na.rm = TRUE), 1)) +
coord_cartesian(ylim = c(0,25000),xlim = c(0,5))
grid.arrange(plot1, plot2, nrow = 2)
```
```{r echo=FALSE, warning=FALSE}
summary(df$DelinquenciesLast7Years)
```
```{r echo=FALSE, warning=FALSE}
summary(df$PublicRecordsLast10Years)
```
It is obvious that most of the borrower have zero or one deliquencies in the last 7 years. Similarly they have zero or one public records in the last 10 years.
## Revolving Credit Balance
```{r echo=FALSE, warning=FALSE}
ggplot( data = df) +
geom_histogram(aes(x = RevolvingCreditBalance),binwidth = 7000) +
scale_x_continuous(
limits = c(0, quantile(df$RevolvingCreditBalance, 0.99, na.rm = TRUE)),
breaks = seq(0, quantile(df$RevolvingCreditBalance, 0.99, na.rm = TRUE), 10000)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
```{r echo=FALSE, warning=FALSE}
summary(df$RevolvingCreditBalance)
```
Revolving Credit Balance is the total outstanding balance that the borrower owes on his/her credit accounts. The median and mean are 8549 and 17600 respectively and the most common amount is 0.
## Length of credit history
```{r echo=FALSE, warning=FALSE}
plot1 <- ggplot(data = df) +
geom_histogram(aes(x = DaysWithCreditLine), binwidth = 100)
plot2 <- ggplot(data = df) +
geom_histogram(aes(x = DaysWithCreditLine / 365),binwidth = 5, label="Years with credit line")
grid.arrange(plot1, plot2)
```
here is a credit line stors the credit story of 60 years.
## Rating
```{r echo=FALSE, warning=FALSE}
ggplot(data = df) +
geom_bar(aes(x = ProsperRating))
```
The most common rating is C follows by B. A and D are at the next steps (excluding the NA).
## Loan length
```{r echo=FALSE, warning=FALSE}
ggplot(data = df) +
geom_bar(aes(x = Term))
```
Most loans have 36 months terms
## Borrower Rating
```{r echo=FALSE, warning=FALSE}
ggplot(data = df, binwidth = 1) +
geom_histogram(aes(x = BorrowerRate * 100))
```
```{r echo=FALSE, warning=FALSE}
summary(df$BorrowerRate)
```
The median and mean for the borrower rate are 18.4% and 19.28% respectively, and The maximum borrower rate is 0.4975 or 49.75%.
## Years borrowing
```{r echo=FALSE, warning=FALSE}
df$ListingCreationYear <- year(prosper_data$ListingCreationDate)
df$ListingCreationYear <- as.factor(df$ListingCreationYear )
ggplot( data = df) +
geom_bar(aes(x = ListingCreationYear)) +
ggtitle("Loan Origination by Year") +
xlab("Loan Creation Year")
```
2013 is the year that people borrowed money more than any other years and 2009 is the minimum borrowing year. There can be many resons behind that like economic crises or elections.
## Employment Duration of the borrowers
```{r echo=FALSE, warning=FALSE}
df$EmploymentStatusDuration = prosper_data$EmploymentStatusDuration
ggplot(data = df) +
geom_histogram(aes(x = EmploymentStatusDuration/12), binwidth=2) +
ggtitle("Employment Duration of the borrowers") +
xlab("Employment duration (years)") +
theme(text = element_text(size=12))
```
With the increase of the length of employment there is a decreas in the number of people who borrow loans.
## Top 10 borrower states
```{r echo=FALSE, warning= FALSE}
groupByBorrowerState <- group_by(prosper_data, BorrowerState)
borrowersByState <- summarise(groupByBorrowerState, count = n())
borrowersByState <- borrowersByState[order(-borrowersByState$count),]
states <- unique((head(borrowersByState, 11))$BorrowerState)
top10States <- subset(prosper_data, (BorrowerState %in% states))
ggplot( data = subset(top10States, BorrowerState != '')) +
geom_bar(aes(x = BorrowerState)) +
ggtitle("TOP 10 States") +
theme(text = element_text(size=10)) +
xlab("Borrower State")
```
As we can see California is the state that people were more likely to loan and Florida, Illinois, New York and Texas are at the next steps.
# Univariate Analysis
### What is the structure of your dataset?
For the purpose of this project I am using the Prosper data set, which contains all Prosper loans created until March 11th, 2014. There are discrete and continuous variables in this dataset.Each variable is a column and each row is an observation.
### What is/are the main feature(s) of interest in your dataset?
- DelinquenciesLast7Years
- PublicRecordsLast10Years
- DebtToIncomeRatio
- RevolvingCreditBalance
- DaysWithCreditLine
- LoanOriginalAmount
- ListingCategory
- EmploymentStatus
- AnnualIncome
- BorrowerRate
- Term
- ProsperRating
- Listing Creation Date
### What other features in the dataset do you think will help support your \
investigation into your feature(s) of interest?
Other variables that help me in my investigation are Employment Duration,
Debt To Income Ratio, Prosper Rating and Occupation.
### Did you create any new variables from existing variables in the dataset?
I created following new variables during the analysis: ListingCretionYear and Days with credit line.
### Of the features you investigated, were there any unusual distributions? \
Did you perform any operations on the data to tidy, adjust, or change the form \
of the data? If so, why did you do this?
I set ListingCreationYear variable as a factor so when I plotted it would look discrete. I've alose taked care of ranked variables order in top 10 loan states.
# Bivariate Plots Section
## Relationship between Prosper Rating and BorrowerAPR
```{r echo=FALSE, warning=FALSE}
df$BorrowerAPR = prosper_data$BorrowerAPR
rating <- c("HR", "E", "D", "C", "B", "A", "AA")
ggplot(aes(x = ProsperRating, y = BorrowerAPR * 100),
data = subset(df, !is.na(BorrowerAPR))) +
geom_boxplot(lwd = 0.75) +
scale_x_discrete(limits = rating)
```
As we can see biger APRs have higher risk.
## The relationship between Loan Original Amount and Number of
Investors
```{r echo=FALSE,warning=FALSE}
df$Investors = prosper_data$Investors
ggplot( data = df) +
geom_point(aes(x = LoanOriginalAmount, y = Investors),alpha = 1/20) +
ggtitle("Loan Original Amount vs Number of Investors") +
xlab("Loan Original Amount")
```
As we can see larger loans have more investors.
## Borrowed loan amount vary trought the years
```{r echo=FALSE, warning=FALSE}
ggplot(data=df) +
geom_boxplot(aes(x=as.character(ListingCreationYear), y=LoanOriginalAmount)) +
ggtitle("Listing Creation Year vs Loan Original Amount") +
xlab("Listing Creation Year") +
ylab("Loan Original Amount")
```
Mean loans amounts wen up slowly from 2005 to 2007, then it decreased at 2008 and went down to his minimum value at 2009. After that it recovered and increased and peaked at 2013 and 2014.
## Relationship between loan amount and terms.
```{r echo=FALSE, warning=FALSE}
ggplot(data = df) +
geom_boxplot(aes(x = as.character(Term), y = LoanOriginalAmount)) +
ggtitle("Term vs Loan Original Amount") +
xlab("Term") +
ylab("Loan Original Amount")
```
```{r echo=FALSE, warning=FALSE}
by(df$LoanOriginalAmount, df$Term, summary)
```
The loan amonts are getting larger with longer terms. As we can see from the Table median and mean are increasing by longer terms.
## Relationships between loan amount and the IncomeRange
```{r echo=FALSE, warning=FALSE}
df$IncomeRange = prosper_data$IncomeRange
ggplot(aes(x = IncomeRange, y = LoanOriginalAmount), data=df) +
geom_boxplot() +
ggtitle("Income Range vs Loan Amount") +
xlab("Income Range") +
theme(text = element_text(size=12),
axis.text.x = element_text(angle=90, vjust=1)) +
ylab("Loan Original Amount")
```
It is obvious from the box pots that larger loans on average are related to larger incomes.
## Relationship between monthly debt and current credit lines
```{r echo=FALSE, warning=FALSE}
df$MonthlyDebt <- prosper_data$DebtToIncomeRatio * prosper_data$StatedMonthlyIncome
df$CurrentCreditLines <- prosper_data$CurrentCreditLines
ggplot(aes(x = CurrentCreditLines, y = MonthlyDebt),
data = subset(df, MonthlyDebt != 171000)) +
geom_jitter(alpha = 1/10, shape = 20) +
geom_smooth(method = 'lm') +
xlim(0,60) +
ylim(0,8000) +
ggtitle("Monthly Debt vs Current Credit Lines") +
xlab("Monthly Debt") +
ylab("Current Credit Lines")
```
As we can see the amonth of debt is growing by increasing the number of credit lines.
## Relationship between LoanOriginalAmount with ListingCategory.
```{r echo=FALSE, warning=FALSE}
ggplot( data = df) +
geom_boxplot(aes(x = ListingCategory, y = LoanOriginalAmount)) +
scale_y_continuous(limits = c(0, quantile(df$LoanOriginalAmount, 0.99, na.rm = TRUE))) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
If we look at the mean values we can see that the mean of Baby & Adoption and Dept Consolidation are the highest as opposed to Student and Vacation that are the minimums.
## Employment status and loan amount
```{r echo=FALSE, warning=FALSE}
ggplot(aes(x = EmploymentStatus, y = LoanOriginalAmount), data = df) +
geom_boxplot() +
scale_y_continuous(limits = c(0, quantile(df$LoanOriginalAmount, 0.99, na.rm = TRUE))) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
As we can see Employed people requested more loans. Interestingly, Not employed people wanted more loan than part-time employed people.
## Relationship of borrower rate and other variables.
```{r echo=FALSE, warning=FALSE}
df$BankcardUtilization <- prosper_data$BankcardUtilization
plot1 <- ggplot(aes(x = BankcardUtilization, y = BorrowerRate), data = df) +
geom_point(alpha = 0.005) +
stat_smooth(method = "lm")
plot2 <- ggplot(aes(x = RevolvingCreditBalance, y = BorrowerRate), data = df) +
geom_point(alpha = 0.005) +
stat_smooth(method = "lm")
plot3 <- ggplot(aes(x = DelinquenciesLast7Years, y = BorrowerRate), data = df) +
geom_point(alpha = 0.005) +
stat_smooth(method = "lm")
plot4 <- ggplot(aes(x = PublicRecordsLast10Years, y = BorrowerRate), data = df) +
geom_point(alpha = 0.005) +
stat_smooth(method = "lm")
plot5 <- ggplot(aes(x = DaysWithCreditLine, y = BorrowerRate), data = df) +
geom_point(alpha = 0.005) +
stat_smooth(method = "lm")
plot6 <- ggplot(aes(x = InquiriesLast6Months, y = BorrowerRate), data = df) +
geom_point(alpha = 0.005) +
stat_smooth(method = "lm")
grid.arrange(plot1, plot2, plot3, plot4, plot5, plot6, nrow = 3, ncol = 2)
```
As BankcardUtilization, DeliquenciesLast7Years, PublicRecordsLast10Years and InquiriesLast6Months increaseswith the borrower rate,as opposed to RevolvingCreditBalance, whcih decreased. DaysWithCreditLine has no significant change with BorrowerRate.
## Correlation between BorrowerRate with BankcardUtilization:
```{r echo=FALSE, message=FALSE, warning=FALSE}
cor(df$BorrowerRate, df$BankcardUtilization, use = "complete.obs")
```
## Correlation between BorrowerRate with RevolvingCreditBalance:
```{r echo=FALSE, message=FALSE, warning=FALSE}
cor(df$BorrowerRate, df$RevolvingCreditBalance, use = "complete.obs")
```
## Correlation between BorrowerRate with DelinquenciesLast7Years:
```{r echo=FALSE, message=FALSE, warning=FALSE}
cor(df$BorrowerRate, df$DelinquenciesLast7Years, use = "complete.obs")
```
## Correlation between BorrowerRate with PublicRecordsLast10Years:
```{r echo=FALSE, message=FALSE, warning=FALSE}
cor(df$BorrowerRate, df$PublicRecordsLast10Years, use = "complete.obs")
```
## Correlation between BorrowerRate with DaysWithCreditLine:
```{r echo=FALSE, message=FALSE, warning=FALSE}
cor(df$BorrowerRate, df$DaysWithCreditLine, use = "complete.obs")
```
## Correlation between BorrowerRate with InquiriesLast6Months:
```{r echo=FALSE, message=FALSE, warning=FALSE}
cor(df$BorrowerRate, df$InquiriesLast6Months, use = "complete.obs")
```
None of that variebles has strong relatipnship with each other. The strongest relationship is between BorrowerRate with BankcardUtilization with 0.25.
## Relation of Term and AnnualIncome
```{r echo=FALSE, warning=FALSE}
ggplot(aes(x = Term, y = AnnualIncome), data = df) +
geom_boxplot() +
scale_y_continuous(
limits = c(0, quantile(df$AnnualIncome, 0.99, na.rm = TRUE)))
```
```{r echo=FALSE, warning=FALSE}
summary(subset(df, Term == 12)$AnnualIncome)
summary(subset(df, Term == 36)$AnnualIncome)
summary(subset(df, Term == 60)$AnnualIncome)
```
The median and mean for 12 months term are the highest between term of 12,36 and 60.
## Relation betwen Term and DeptToIncomeRatito
```{r echo=FALSE, warning=FALSE}
df$DebtToIncomeRatio = prosper_data$DebtToIncomeRatio
ggplot(aes(y = DebtToIncomeRatio, x = Term), data = df) +
geom_boxplot() +
scale_y_continuous(
limits = c(0, quantile(df$DebtToIncomeRatio, 0.99, na.rm = TRUE)))
```
```{r echo=FALSE, warning=FALSE}
summary(subset(df, Term == 12)$DebtToIncomeRatio)
summary(subset(df, Term == 36)$DebtToIncomeRatio)
summary(subset(df, Term == 60)$DebtToIncomeRatio)
```
As we can see the median of the DebtToIncomeRatio increases as the terms goes up.
## ProsperRating against BorrowerRate
```{r echo=FALSE, warning=FALSE}
ggplot(aes(x = ProsperRating, y = BorrowerRate), data = df) +
geom_boxplot()
```
As we can see The better rating belongs to lower borrower rate.
## Relationship of term and borrower rate
```{r echo=FALSE, warning=FALSE}
ggplot(aes(x = Term, y = BorrowerRate), data = df) +
geom_boxplot() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
```
The median of 60 month term is the highest one, while the 12 month has the minimum one.
# Bivariate Analysis
> **Tip**: As before, summarize what you found in your bivariate explorations
here. Use the questions below to guide your discussion.
### Talk about some of the relationships you observed in this part of the \
investigation. How did the feature(s) of interest vary with other features in \
the dataset?
The number of investors is increasing with higher prosper score, loan amount is bigger, borrowers have less existing prosper loans, estimated loss is lower. The mean loan amount vary trough years. The minimum mean in 2009 and
the maximum one is in 2013 and 2014. We also can see for instance the borrower rate increases as debt to income ratio increases. Moreover, we can see that with bigger amonth of loan the term is also longer.
### Did you observe any interesting relationships between the other features \
(not the main feature(s) of interest)?
I noticed that employed people are more likely to loan than others. Also debt to income ratio for rating AA is the lowest one.
### What was the strongest relationship you found?
The strongest relationship that I found was between BorrowerRate with BankcardUtilization with value of 0.255482.
# Multivariate Plots Section
## Borrower Rate vs Income Range vs Is Borrower Homeowner
```{r echo=FALSE, warning=FALSE}
df$IsBorrowerHomeowner <- prosper_data$IsBorrowerHomeowner
ggplot(aes(x = as.factor(IncomeRange), y = BorrowerRate),
data = subset(df,
IncomeRange != 'Not employed' &
IncomeRange != 'Not displayed'&
IncomeRange != '$0')) +
geom_boxplot(aes(fill = IsBorrowerHomeowner)) +
ggtitle("Income Range vs Borrower Rate (by Home Owner)") +
guides(fill = guide_legend(title = "Is Borrower Homeowner")) +
xlab("Income Range") +
ylab("Borrower Rate") +
theme(text = element_text(size=12),
axis.text.x = element_text(angle=90, vjust=1))
```
As we can see borrowers with higher income, which are home owners have lower borrower rates.
## Relationship between Delinquencies and Employment Status
```{r echo=FALSE, warning=FALSE}
df$AmountDelinquent <- prosper_data$AmountDelinquent
ggplot(aes(x = DelinquenciesLast7Years, y = AmountDelinquent),
data = filter(df, AmountDelinquent > 0 &
EmploymentStatus != "Other" )) +
geom_point() +
xlim(0, quantile(df$DelinquenciesLast7Years, 0.99, na.rm = T)) +
ylim(0, quantile(df$AmountDelinquent, 0.99, na.rm = T)) +
facet_wrap(~EmploymentStatus)+
ggtitle('Relationship between Delinquencies and Employment Status')
```
From the above we can see relationship between the amount borrowers were delinquent and the number of delinquencies they've had over the last 7 years then separated that by employment status. Is obvious that Employed and Full time are the maximum.
## Relationshiop between Debt to Income
```{r echo=FALSE, warning=FALSE}
ggplot(aes(x=DebtToIncomeRatio), data=subset(df,DebtToIncomeRatio<=1)) +
geom_density(aes(color = IncomeRange,
fill = IncomeRange),
alpha = 0.5) +
xlim(0, quantile(df$DebtToIncomeRatio, 0.95, na.rm = T)) +
ggtitle('Borrowers APR to Income Range') +
facet_wrap(~IncomeRange, ncol=2,
scales = "free")
```
## Relationship between a lender yield on the loan and the number of investors with risk rating
```{r echo=FALSE, warning=FALSE}
df$TermInMonth <- as.factor(df$Term)
df$LenderYield <- prosper_data$LenderYield
rating <- c("HR", "E", "D", "C", "B", "A", "AA")
ggplot(data = subset(df,ProsperRating %in% rating),
aes(x = LenderYield,
y = Investors,
colour =as.integer(ProsperRating), group = ProsperRating
)) +
geom_jitter(alpha = 0.5,
position = 'jitter') +
facet_wrap(~TermInMonth, ncol = 3) +
scale_color_gradient2(name = 'Prosper Rating',
breaks = seq(1, 7, 1),
labels = rating,
limits = c(1, 7)) +
xlab("Lender yield") +
ylab("Number of Investor") +
ggtitle("Lender yield by Term and Categories")+
theme(legend.position = "right",
legend.direction = "vertical",
legend.key.size = unit(1, "cm"))
```
This plot shows the relationship between a lender yield on the loan and the number of investors with the duration of the loan and the prosper rating.
## Relationship between dept to income ratio and borrowerAPR with prosper rating
```{r echo=FALSE, warning=FALSE}
df$BorrowerAPR <- prosper_data$BorrowerAPR
ggplot(aes(x = DebtToIncomeRatio, y = BorrowerAPR,
color =as.integer(ProsperRating), group = ProsperRating),
data = subset(df, !is.na(BorrowerAPR) & ProsperRating %in% rating)) +
geom_jitter() +
xlim(0, quantile(df$DebtToIncomeRatio, 0.995, na.rm = T)) +
theme(legend.position = "right",
legend.direction = "vertical",
legend.key.size = unit(1, "cm"))
```
Above plot describes the risk category based on to the particular loan.It displays the progression from a safe area, green color, to a risky area, red color,.
# Multivariate Analysis
### Talk about some of the relationships you observed in this part of the \
investigation. Were there features that strengthened each other in terms of \
looking at your feature(s) of interest?
Monthly income had positive and late payments has negative correlation with Rating. The number of investors is increasing when the prosper score is getting beter and loan amount is getting bigger too. Also we can see that higher loan amounts have longer term.
### Were there any interesting or surprising interactions between features?
I've observed that employed people are more likely to borrow money.
### OPTIONAL: Did you create any models with your dataset? Discuss the \
strengths and limitations of your model.
No I did not.
------
# Final Plots and Summary
### Plot One
```{r echo=FALSE, warning=FALSE}
ggplot(data = df) +
geom_bar(aes(x = ListingCategory), fill = 'orange', color = I("#506E86")) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
xlab("Listing of Differenr Catagories")+
ylab("Number of Loan")+
ggtitle("Number of loans for different catagories")
```
### Description One
As we can see largest number of the loans belongs to debt consolidation, about 60000 loans, while home improvement, business and other are at the next steps (Not Available is not considered). I choose this plot because I wanted to know in which areas people use prosper loan.
### Plot Two
```{r echo=FALSE, warning=FALSE}
ggplot(aes(x = DebtToIncomeRatio, y = BorrowerAPR,
color =as.integer(ProsperRating), group = ProsperRating),
data = subset(df, !is.na(BorrowerAPR) & ProsperRating %in% rating)) +
geom_jitter() +
geom_point(size = 1.1) +
xlim(0, quantile(df$DebtToIncomeRatio, 0.995, na.rm = T)) +
scale_color_gradient2(high = "#FA4659", midpoint = 4, mid = "#FBB448",
low = "#2EB872",
breaks = seq(1, 7, 1),
labels = rev(rating),
limits = c(1, 7),
name = 'Category of Risk') +
theme(legend.position = "right",
legend.direction = "vertical",
legend.key.size = unit(1, "cm"))+
ggtitle('Borrower APR and Debt To Income Ratio')
```
### Description Two
This scatter plot shows us the relationship between Dept to Income Ratio and BorrowerAPR and the colors illustrate the risky areas for the particular loan. The green color is the most safest zone and the red color is the most risky one. I also deleted outliers from this plot(0.05%). We can see that APR is going up with the increase of rating risk. Also we can see that majority of people have debt-to-income ratios below 1.
### Plot Three
```{r echo=FALSE, warning=FALSE}
ggplot(aes(x = ProsperRating, y = BorrowerAPR * 100,
fill = I("#cd1045"), color = I("#a26c40")),
data = subset(df, !is.na(BorrowerAPR))) +
geom_boxplot(lwd = 0.75, outlier.colour = I("#FBB448"), outlier.shape = 1) +
scale_x_discrete(limits = rating) +
ggtitle('Borrower APR and ProsperRating') +
ylab("Borrower APR")
```
### Description Three
The boxplots above show the relationship between borrower's Prosper rating and their assigned Annual Percentage Rate. As we can see lower APR has less risk thtan higher one. Moreover, we can see that the variation in APR goes down in safer zones.
# Reflection
Well I selected this project maninly because I did not know anything about loan, peosper loan, peer to peer lending business etc. and I wanted to learn something new. I spent a lot of time to learn about prosper loan and also spent even more time to understand each variable in the dataset. Also I was a little struggling with ggplot syntax and I checked Stackoverflow and Google alot during this project. :)
Following are some of the interesting features which I observed during the exploratory analysis:
- Most of borrowers Income ranges from 25,000 - 74,999.
- Most loans are taken for debt consolidation.
- There are 3 loan terms 12, 36 and 60 months and the most popular one is 36 month.
- Borrower who home owner usually receive bigger loan than others.
- The Borrower rate of Interest and Lender Yield is low for higher Credit Grades and high for lower Credit Grades.
- Employed person are more likley to take loan thatn others.