When someone secures a loan there are 3 factors about the loan: 1. Purpose – why the person needs the loan 2. Months of Loan Duration – how long the loan is for 3. Amount – the amount of $ the person wants to be loaned.
With this there are several factors that are considered when giving a
loan to a person: 1. Checking Balance – the range of $
the person has in their checking account
2. Credit History – on a scale from critical to perfect
how good is their credit history 3. Savings Balance -
the range of $ the person has in their savings account
4. Age – how old is the person 5. Job
– what type of job do they have (skilled,unskilled, management,
unemployment)
When a person is given a loan, the previous factors are considered.The final say that a person is given a loan or not (Default) is decided when looking at the factors. When the loan office looks at the persons’ responses, they are then given a loan, but it is not clear to the everyday person which factor is the most influential in this. As there are a lot of factors that are considered we want to see which factors are more influential in getting a loan than others.
The code chuck will load all the data from the loans data set that was found in Brightspace. We will start by just loadin the data.
# Loading the credit data
credit <- read.csv("credit.csv")
#Skimming and displaying first 10 rows of data set
skimr::skim(credit)
| Name | credit |
| Number of rows | 1000 |
| Number of columns | 17 |
| _______________________ | |
| Column type frequency: | |
| character | 10 |
| numeric | 7 |
| ________________________ | |
| Group variables | None |
Variable type: character
| skim_variable | n_missing | complete_rate | min | max | empty | n_unique | whitespace |
|---|---|---|---|---|---|---|---|
| checking_balance | 0 | 1 | 6 | 10 | 0 | 4 | 0 |
| credit_history | 0 | 1 | 4 | 9 | 0 | 5 | 0 |
| purpose | 0 | 1 | 3 | 20 | 0 | 6 | 0 |
| savings_balance | 0 | 1 | 7 | 13 | 0 | 5 | 0 |
| employment_duration | 0 | 1 | 8 | 11 | 0 | 5 | 0 |
| other_credit | 0 | 1 | 4 | 5 | 0 | 3 | 0 |
| housing | 0 | 1 | 3 | 5 | 0 | 3 | 0 |
| job | 0 | 1 | 7 | 10 | 0 | 4 | 0 |
| phone | 0 | 1 | 2 | 3 | 0 | 2 | 0 |
| default | 0 | 1 | 2 | 3 | 0 | 2 | 0 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| months_loan_duration | 0 | 1 | 20.90 | 12.06 | 4 | 12.0 | 18.0 | 24.00 | 72 | ▇▇▂▁▁ |
| amount | 0 | 1 | 3271.26 | 2822.74 | 250 | 1365.5 | 2319.5 | 3972.25 | 18424 | ▇▂▁▁▁ |
| percent_of_income | 0 | 1 | 2.97 | 1.12 | 1 | 2.0 | 3.0 | 4.00 | 4 | ▂▃▁▂▇ |
| years_at_residence | 0 | 1 | 2.85 | 1.10 | 1 | 2.0 | 3.0 | 4.00 | 4 | ▂▆▁▃▇ |
| age | 0 | 1 | 35.55 | 11.38 | 19 | 27.0 | 33.0 | 42.00 | 75 | ▇▆▃▁▁ |
| existing_loans_count | 0 | 1 | 1.41 | 0.58 | 1 | 1.0 | 1.0 | 2.00 | 4 | ▇▅▁▁▁ |
| dependents | 0 | 1 | 1.16 | 0.36 | 1 | 1.0 | 1.0 | 1.00 | 2 | ▇▁▁▁▂ |
head(credit, 10)
## checking_balance months_loan_duration credit_history purpose
## 1 < 0 DM 6 critical furniture/appliances
## 2 1 - 200 DM 48 good furniture/appliances
## 3 unknown 12 critical education
## 4 < 0 DM 42 good furniture/appliances
## 5 < 0 DM 24 poor car
## 6 unknown 36 good education
## 7 unknown 24 good furniture/appliances
## 8 1 - 200 DM 36 good car
## 9 unknown 12 good furniture/appliances
## 10 1 - 200 DM 30 critical car
## amount savings_balance employment_duration percent_of_income
## 1 1169 unknown > 7 years 4
## 2 5951 < 100 DM 1 - 4 years 2
## 3 2096 < 100 DM 4 - 7 years 2
## 4 7882 < 100 DM 4 - 7 years 2
## 5 4870 < 100 DM 1 - 4 years 3
## 6 9055 unknown 1 - 4 years 2
## 7 2835 500 - 1000 DM > 7 years 3
## 8 6948 < 100 DM 1 - 4 years 2
## 9 3059 > 1000 DM 4 - 7 years 2
## 10 5234 < 100 DM unemployed 4
## years_at_residence age other_credit housing existing_loans_count job
## 1 4 67 none own 2 skilled
## 2 2 22 none own 1 skilled
## 3 3 49 none own 1 unskilled
## 4 4 45 none other 1 skilled
## 5 4 53 none other 2 skilled
## 6 4 35 none other 1 unskilled
## 7 4 53 none own 1 skilled
## 8 2 35 none rent 1 management
## 9 4 61 none own 1 unskilled
## 10 2 28 none own 2 management
## dependents phone default
## 1 1 yes no
## 2 1 no yes
## 3 2 no no
## 4 2 no no
## 5 2 no yes
## 6 2 yes no
## 7 1 no no
## 8 1 yes no
## 9 1 no no
## 10 1 no yes
The code chunk will clean the data. In the balances for checking_balance and savings_balance there was unknowns, so this takes these values out. It also puts a sequential order to savings_balance, credit_history, and job.
## checking_balance credit_history savings_balance job age default
## 1 1 - 200 DM good < 100 DM skilled 22 yes
## 2 < 0 DM good < 100 DM skilled 45 no
## 3 < 0 DM poor < 100 DM skilled 53 yes
## 4 1 - 200 DM good < 100 DM management 35 no
## 5 1 - 200 DM critical < 100 DM management 28 yes
## 6 1 - 200 DM good < 100 DM skilled 25 yes
## 7 < 0 DM good < 100 DM skilled 24 yes
## 8 1 - 200 DM good < 100 DM skilled 22 no
## 9 < 0 DM critical < 100 DM unskilled 60 yes
## 10 < 0 DM good < 100 DM skilled 28 no
## amount balance
## 1 5951 1 - 200 DM:< 100 DM
## 2 7882 < 0 DM:< 100 DM
## 3 4870 < 0 DM:< 100 DM
## 4 6948 1 - 200 DM:< 100 DM
## 5 5234 1 - 200 DM:< 100 DM
## 6 1295 1 - 200 DM:< 100 DM
## 7 4308 < 0 DM:< 100 DM
## 8 1567 1 - 200 DM:< 100 DM
## 9 1199 < 0 DM:< 100 DM
## 10 1403 < 0 DM:< 100 DM
The main goal we want to try to answer is “What components are the main points to worry about regarding eligibility of a loan.”
We are going to first take a look into a comparison between the various factors and the default of the loan to see if there were any conclusions that could be made. First we looked into comparing credit history and savings balance.
In looking at this graph, it is inconclusive about whether or not credit
history can predict a persons acceptance of a loan. There are definitely
more perfect credit people that are accepted, but given that the plot
seems very random and a majority of people have DM’s under $100 it is
hard to tell.
Next we looked at comparing credit history to amount loaned out to
see if this was another factor incorporated to see if a loan would be
accepted
In looking at this graph, it is inconclusive about whether or not credit
history can predict a persons acceptance of a loan. There are definitely
more perfect credit people that are accepted, but given that the plot
seems very random and a majority of people have lower amounts which
makes it hard to tell.
Similarly, we want to create a comparison to look at job and age to see if there is a comparison between the factors of age and job and whether that affects someones ability to get a loan.
In looking at the graphs, there was definitely a correlation between
being unemployed and being accepted for a loan. It is also interesting
that the only people that were accepted for a loan were unemployed,
besides one outlier, was younger people. For an unskilled worker it
seems that if you are younger you are more likely to be unskilled as the
average is about 34 for those accepted and 38 for those who were
denied.
As we noticed that the older folks in the unskilled and unemployed job classifications were not being accepted for loans, we wanted to see if the amount they were asking for had sway on the acceptance of their loan.
In looking at these graphs, there does not seem to be a skew that would
allow for the prior concoeved trend.
We decided the next best course of action, would be to create a classification tree to see what criteria the code things is most important the whether or not a person is accepted to get their loan.
## CP nsplit rel.error xerror xstd
## 1 0.121212121 0 1.00000000 1.0000000 0.04912530
## 2 0.077922078 1 0.87878788 0.9480519 0.04880858
## 3 0.014430014 2 0.80086580 0.8138528 0.04747937
## 4 0.010822511 7 0.71861472 0.8571429 0.04799079
## 5 0.008658009 12 0.66233766 0.8311688 0.04769363
## 6 0.006926407 15 0.63636364 0.8441558 0.04784581
## 7 0.006493506 21 0.59307359 0.8484848 0.04789494
## 8 0.005194805 23 0.58008658 0.8484848 0.04789494
## 9 0.004329004 28 0.55411255 0.9393939 0.04874528
## 10 0.003246753 67 0.38095238 0.9437229 0.04877731
## 11 0.002886003 75 0.35497835 0.9610390 0.04889786
## 12 0.002164502 91 0.30303030 0.9696970 0.04895363
## 13 0.001731602 192 0.05627706 1.0216450 0.04922569
## 14 0.001443001 199 0.04329004 1.0389610 0.04929274
## 15 0.000000000 208 0.03030303 1.0389610 0.04929274
## 16 -1.000000000 213 0.03030303 1.0389610 0.04929274
This first tree looks like it was able to break down the classifications well, but it is too complex. We want to be able to simplify or prun our tree. In order to do this we need to first look at the X-val relative error to see the best course of action of pruning.
## CP nsplit rel.error xerror xstd
## 1 0.121212121 0 1.00000000 1.0000000 0.04912530
## 2 0.077922078 1 0.87878788 0.9480519 0.04880858
## 3 0.014430014 2 0.80086580 0.8138528 0.04747937
## 4 0.010822511 7 0.71861472 0.8571429 0.04799079
## 5 0.008658009 12 0.66233766 0.8311688 0.04769363
## 6 0.006926407 15 0.63636364 0.8441558 0.04784581
## 7 0.006493506 21 0.59307359 0.8484848 0.04789494
## 8 0.005194805 23 0.58008658 0.8484848 0.04789494
## 9 0.004329004 28 0.55411255 0.9393939 0.04874528
## 10 0.003246753 67 0.38095238 0.9437229 0.04877731
## 11 0.002886003 75 0.35497835 0.9610390 0.04889786
## 12 0.002164502 91 0.30303030 0.9696970 0.04895363
## 13 0.001731602 192 0.05627706 1.0216450 0.04922569
## 14 0.001443001 199 0.04329004 1.0389610 0.04929274
## 15 0.000000000 208 0.03030303 1.0389610 0.04929274
## 16 -1.000000000 213 0.03030303 1.0389610 0.04929274
## exrror cutoff cp prune value
## 0.86133218 0.01443001
Using our X-error cut off and prune value, we are now going to prune
our tree.
## Warning: extra=1 is not supported by rpart.rules (although useable for plots)
## default
## 0.38 when credit_history is critical or poor or good & amount < 8016
## 0.71 when credit_history is very good or perfect
## 0.82 when credit_history is critical or poor or good & amount >= 8016
In the end according to our pruned tree it seemed that credit history was important first and that if some that has very good or perfect credit history they are going to be accepted. After that, if they do not have perfect or very good credit history, the amount asked comes into play. If the amount asked for is less than 8,016 then they do not get accepted, if it is greater than or equal to 8,016 then you do.
In looking at the final pruned tree and the prior graphs it seemed that the credit_history is one of the most important factors in being accepted for a loan. If someone has very good or perfect credit then they are more likely to be accepted. The second factor also in the pruned tree had to do with the amount. This is interesting because one would think that a person would be less likely to accepted if they are asking for a lot any have bad credit, but the pruned tree hinted towards the opposite. No other factors really shows any causation towards being important in our data. The only factor that saw some causation was looking into unemployed workers and how those over about 30 were not accepted.
We do recognize that there are limitations to this data set. First, we were given this data set and did not know the context of it, so we were limited to the physical numbers and data that we had. We were also limited to only the data within the data set and could not get any other additional data that was not already in it. With this, the checking and savings account balances were only given in the range of debt memorandum or the amount of increase other than due to withdrawal, cashed check, or use of card. This meant that the balances were not true account balances, so it was harder to use this data and truly know the amount of disposable income that the people applying for loans. We believe this data only came from one loan office as there is only 1,000 entries. There is also no evidence to prove how this data was collected, so we again are limited to the physical data and the assumption that it is just one office. This means there is a limitation for the use of this data set. This data set can only be used for this office and their practices as this is only data from 1 office and not a sample from all over the world.
For recommendations, we would look into other data sets or data from multiple offices. Our findings are only truly limited to this specific data set as it has not been repeated multiple times or from multiple different loan offices. We would want to specifically pay attention to the amount as this was important in the conclusion of our findings. This one set from this one office, can really only be used for their use. We would also recommend additional data to be collected such as disposable income. We would also recommend that when data from other loan offices are added that they are labeled where they came from to make sure that that specific office does not have some underlying bias or differing practices that could be an outlier in the data set.