Explore Loan Data in R - Loan Grade and Interest Rate
Premium
There is no set path to how one would go about analyzing a data set. Typically, a data scientist would spend quite some time exploring and observing the data to understand it well.
Let’s look at some of the attributes in our dataset and see their relationship with the default rate. For each loan, we have two basic attributes, namely, grade and the interest rate. In LendingClub, loan grade, or credit grade, is the letter (A-G or AA-HR) that is assigned to a borrower and corresponds with the interest rate that is charged for the loan.
These rates are set based on the originator’s underwriting assessment for the individual borrower. The higher the expected risk of default, the higher the interest rate is set in order to offset this risk. The assessment of the credit grade decision includes FICO, loan term (a shorter term is considered better), proprietary models, and the loan amount requested by the borrower.
We also have the interest rate being charged for each loan.
Default Rate for Each Loan Grade
Let’s create a plot where we will plot the default rate for each grade.
The following command will give us the number of defaults for each grade.
1> g1 = loandata %>%filter(loan_status =="Default")%>% group_by(grade)%>% summarise(default_count = n())2> g1
3# A tibble: 7 x 24 grade default_count
5<chr><int>61 A 97572 B 348783 C 553494 D 3697105 E 2704116 F 1260127 G 37913>14
We can now calculate the default rate in each grade as follows:
1> g2 = loandata %>% group_by(grade)%>% summarise(count = n())2> g3 <- g2 %>% left_join(g1)%>% mutate(default_rate =100*default_count/count)%>% select(grade,count,default_count,default_rate)3Joining, by ="grade"4> g3
5# A tibble: 7 x 46 grade count default_count default_rate
7<chr><int><int><dbl>81 A 99569759.7992 B 16649348720.9103 C 16815553432.9114 D 8480369743.6125 E 5261270451.4136 F 2109126059.7147 G 59937963.315>16