Consumer Behavior in Having Term of Deposit
Deposit is one of the bank product that people usually like to have, and one of its type is Term of Deposit. This type of investment is offered by bank and financial institution, when someone decided to buy this product, they will deposit a specific amount of money with bank for period of time. During this period, the deposited amount earn a fix interest rate, which is usually higher than the interest rate offered on regular saving account.
Things that Banks or Financial Institutions should know before they offer their product is whether the consumer will buy their product or not. Better understanding about their costumer behavior will help them to get more people buying their product.
This analysis is aiming to get better understanding about behavior or state of the costumer when they want or not to buy term of deposit in Bank. The data I used in this analysis was obtained from Portuguese banking institution. The data contain 21 columns and 41188 rows.
Import Library and Data Reading
library(dplyr)
library(ggplot2)
library(ggplot2)
library(plotly)
library(gridExtra)
library(tidyr)
library(tibble)
library(rsconnect)
library(DT)bank <- read.csv("data_input/bank-additional-full.csv", sep = ";", stringsAsFactors = T)
datatable(bank, options = list(scrollX = T))Column Description
- age (numeric)
- job : type of job (categorical:‘admin.’, ‘blue-collar’, ‘entrepreneur’, ‘housemaid’, ‘management’, ‘retired’, self-‘employed’, ‘services’, ‘student’, ‘technician’, ‘unemployed’, ‘unknown’)
- marital : marital status (categorical: ‘divorced’,‘married’,‘single’,‘unknown’; note: ‘divorced’ means divorced or widowed)
- education : (categorical: ‘basic.4y’, ‘basic.6y’, ‘basic.9y’, ‘high.school’, ‘illiterate’, ‘professional.course’, ‘university.degree’, ‘unknown’)
- default : has credit in default? (categorical: ‘no, yes, ’unknown’)
- housing : has housing loan? (categorical: ‘no’, ‘yes’, ‘unknown’)
- loan : has personal loan? (categorical: ‘no’, ‘yes’, ‘unknown’)
Related with the Last Contact of the Current Campaign:
- contact : contact communication type (categorical: ‘cellular’, ‘telephone’)
- month : last contact month of year (categorical: ‘jan’, ‘feb’, ‘mar’, …, ‘nov’, ‘dec’)
- day_of_week : last contact day of the week (categorical: ‘mon’, ‘tue’, ‘wed’, ‘thu’, ‘fri’)
- duration : last contact duration, in seconds (numeric). Important note: this attribute highly affects the output target (e.g., if duration=0 then y=‘no’). Yet, the duration is not known before a call is performed. Also, after the end of the call y is obviously known. Thus, this input should only be included for benchmark purposes and should be discarded if the intention is to have a realistic predictive model.
Other Attributes:
- campaign : number of contacts performed during this campaign and for this client (numeric, includes last contact)
- pdays : number of days that passed by after the client was last contacted from a previous campaign (numeric; 999 means client was not previously contacted)
- previous : number of contacts performed before this campaign and for this client (numeric)
- poutcome : outcome of the previous marketing campaign (categorical: ‘failure’, ‘nonexistent’, ‘success’)
Social and Economic Context Attributes:
- emp.var.rate : employment variation rate - quarterly indicator (numeric)
- cons.price.idx : consumer price index - monthly indicator (numeric)
- cons.conf.idx : consumer confidence index - monthly indicator (numeric)
- euribor3m : euribor 3 month rate - daily indicator (numeric)
- nr.employed : number of employees - quarterly indicator (numeric)
Output Variable (desired target):
- 21 - y - has the client subscribed a term deposit? (binary: ‘yes’,‘no’)
Data Coertion
glimpse(bank)#> Rows: 41,188
#> Columns: 21
#> $ age <int> 56, 57, 37, 40, 56, 45, 59, 41, 24, 25, 41, 25, 29, 57,…
#> $ job <fct> housemaid, services, services, admin., services, servic…
#> $ marital <fct> married, married, married, married, married, married, m…
#> $ education <fct> basic.4y, high.school, high.school, basic.6y, high.scho…
#> $ default <fct> no, unknown, no, no, no, unknown, no, unknown, no, no, …
#> $ housing <fct> no, no, yes, no, no, no, no, no, yes, yes, no, yes, no,…
#> $ loan <fct> no, no, no, no, yes, no, no, no, no, no, no, no, yes, n…
#> $ contact <fct> telephone, telephone, telephone, telephone, telephone, …
#> $ month <fct> may, may, may, may, may, may, may, may, may, may, may, …
#> $ day_of_week <fct> mon, mon, mon, mon, mon, mon, mon, mon, mon, mon, mon, …
#> $ duration <int> 261, 149, 226, 151, 307, 198, 139, 217, 380, 50, 55, 22…
#> $ campaign <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
#> $ pdays <int> 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, …
#> $ previous <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ poutcome <fct> nonexistent, nonexistent, nonexistent, nonexistent, non…
#> $ emp.var.rate <dbl> 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, …
#> $ cons.price.idx <dbl> 93.994, 93.994, 93.994, 93.994, 93.994, 93.994, 93.994,…
#> $ cons.conf.idx <dbl> -36.4, -36.4, -36.4, -36.4, -36.4, -36.4, -36.4, -36.4,…
#> $ euribor3m <dbl> 4.857, 4.857, 4.857, 4.857, 4.857, 4.857, 4.857, 4.857,…
#> $ nr.employed <dbl> 5191, 5191, 5191, 5191, 5191, 5191, 5191, 5191, 5191, 5…
#> $ y <fct> no, no, no, no, no, no, no, no, no, no, no, no, no, no,…
All data already in their appropriate data type
Data Preprocessing
Checking for Missing Value
colSums(is.na(bank))#> age job marital education default
#> 0 0 0 0 0
#> housing loan contact month day_of_week
#> 0 0 0 0 0
#> duration campaign pdays previous poutcome
#> 0 0 0 0 0
#> emp.var.rate cons.price.idx cons.conf.idx euribor3m nr.employed
#> 0 0 0 0 0
#> y
#> 0
All columns already have no mising values
Checking for Outliers
summary(bank)#> age job marital
#> Min. :17.00 admin. :10422 divorced: 4612
#> 1st Qu.:32.00 blue-collar: 9254 married :24928
#> Median :38.00 technician : 6743 single :11568
#> Mean :40.02 services : 3969 unknown : 80
#> 3rd Qu.:47.00 management : 2924
#> Max. :98.00 retired : 1720
#> (Other) : 6156
#> education default housing loan
#> university.degree :12168 no :32588 no :18622 no :33950
#> high.school : 9515 unknown: 8597 unknown: 990 unknown: 990
#> basic.9y : 6045 yes : 3 yes :21576 yes : 6248
#> professional.course: 5243
#> basic.4y : 4176
#> basic.6y : 2292
#> (Other) : 1749
#> contact month day_of_week duration
#> cellular :26144 may :13769 fri:7827 Min. : 0.0
#> telephone:15044 jul : 7174 mon:8514 1st Qu.: 102.0
#> aug : 6178 thu:8623 Median : 180.0
#> jun : 5318 tue:8090 Mean : 258.3
#> nov : 4101 wed:8134 3rd Qu.: 319.0
#> apr : 2632 Max. :4918.0
#> (Other): 2016
#> campaign pdays previous poutcome
#> Min. : 1.000 Min. : 0.0 Min. :0.000 failure : 4252
#> 1st Qu.: 1.000 1st Qu.:999.0 1st Qu.:0.000 nonexistent:35563
#> Median : 2.000 Median :999.0 Median :0.000 success : 1373
#> Mean : 2.568 Mean :962.5 Mean :0.173
#> 3rd Qu.: 3.000 3rd Qu.:999.0 3rd Qu.:0.000
#> Max. :56.000 Max. :999.0 Max. :7.000
#>
#> emp.var.rate cons.price.idx cons.conf.idx euribor3m
#> Min. :-3.40000 Min. :92.20 Min. :-50.8 Min. :0.634
#> 1st Qu.:-1.80000 1st Qu.:93.08 1st Qu.:-42.7 1st Qu.:1.344
#> Median : 1.10000 Median :93.75 Median :-41.8 Median :4.857
#> Mean : 0.08189 Mean :93.58 Mean :-40.5 Mean :3.621
#> 3rd Qu.: 1.40000 3rd Qu.:93.99 3rd Qu.:-36.4 3rd Qu.:4.961
#> Max. : 1.40000 Max. :94.77 Max. :-26.9 Max. :5.045
#>
#> nr.employed y
#> Min. :4964 no :36548
#> 1st Qu.:5099 yes: 4640
#> Median :5191
#> Mean :5167
#> 3rd Qu.:5228
#> Max. :5228
#>
From summary above I can get some insights:
- From all campaigns that banks do, most people don’t want to have terms of deposit.
- Most costumer of this bank working as admin.
- More than 50% of bank costumer has no credit default.
- But mostly they have housing loan and personal loan.
- Most communication between bank and costumer is done using cellular phone.
- More than 50% of campaign result is unknown (poutocme column)
Also, from summary above I can say there’s some value that has probability at as an outliers. But considering all value is important, so I’ll not remove it
Feature Engineering
To better interpretation, Ill make new column contain age range of costumer. I grouped the values with a range of 10 years.
age.range <- function(x){
if (x <= 10 & x >= 1 ){
y <- "1 - 10"
}
else if (x >= 11 & x <= 20){
y <- "11 - 20 years"
}
else if (x >= 21 & x <= 30){
y <- "21 - 30 years"
}
else if (x >= 31 & x <= 40){
y <- "31 - 40 years"
}
else if (x >= 41 & x <= 50){
y <- "41 - 50 years"
}
else if (x >= 51 & x <= 60){
y <- "51 - 60 years"
}
else if (x >= 61 & x <= 70){
y <- "61 - 70 years"
}
else if (x >= 71 & x <= 80){
y <- "71 - 80 years"
}
else if (x >= 81 & x <= 90){
y <- "81 - 90 years"
}
else{
y <- "91 - 100 years"
}
return(y)
}
bank$age_range <- as.factor(sapply(bank$age, FUN = age.range))Analysis
Group of People that do Subscribe in Term of Deposit
subscribe <- bank %>%
mutate(day_of_week = factor(day_of_week, levels = c("mon", "tue", "wed", "thu", "fri"))) %>%
filter(y == "yes")People’s Age of Range that Subscribe in Term of Deposit
table(subscribe$age_range)#>
#> 11 - 20 years 21 - 30 years 31 - 40 years 41 - 50 years 51 - 60 years
#> 57 1067 1597 837 668
#> 61 - 70 years 71 - 80 years 81 - 90 years 91 - 100 years
#> 212 143 54 5
prop.table(table(subscribe$age_range))#>
#> 11 - 20 years 21 - 30 years 31 - 40 years 41 - 50 years 51 - 60 years
#> 0.012284483 0.229956897 0.344181034 0.180387931 0.143965517
#> 61 - 70 years 71 - 80 years 81 - 90 years 91 - 100 years
#> 0.045689655 0.030818966 0.011637931 0.001077586
ggplot(data = subscribe, mapping = aes(x = age_range)) +
geom_bar()+
labs(title = "Age's Range that Subscribe in Term of Deposit") +
theme_minimal()From bar plot above, we know that age range of 31-40 years subscribe the most of term deposit. For further campaign event, bank can focus in this age group for better result.
Job of People That Subscribe in Term of Deposit
I am eliminating unknown value in job column because we only want to know which people’s job that has term of deposit in bank
job_subscribe <- subscribe %>%
filter(job != "unknown") %>%
droplevels()table(job_subscribe$job)#>
#> admin. blue-collar entrepreneur housemaid management
#> 1352 638 124 106 328
#> retired self-employed services student technician
#> 434 149 323 275 730
#> unemployed
#> 144
prop.table(table(job_subscribe$job))#>
#> admin. blue-collar entrepreneur housemaid management
#> 0.29372149 0.13860526 0.02693895 0.02302846 0.07125788
#> retired self-employed services student technician
#> 0.09428633 0.03237019 0.07017163 0.05974365 0.15859222
#> unemployed
#> 0.03128395
ggplot(data = job_subscribe, mapping = aes(x = job)) +
geom_bar()+
labs(title = "People's Job that Subscribe in Term of Deposit") +
theme_minimal()From the result we can say, people who work as an Admin most likely to have Term of Deposit In bank. Surprisingly it’s number even bigger than management or entrepreneur where these two group of people sometimes need to save more of their money in the bank to get more profit form bank’s interest rate.
Do Level of Education Influence People’s Interest to Have Deposit in Bank?
Educational column contain 7 type of educational level, they are: basic 4y, basic 6y, basic 9y, high school, illiterate, professional course and university degree. Sicne theres unknow value in Educational column, I’ll dispose unknown value form this column to know wich educational level of person that has deposit the most in bank.
bank_edu <- subscribe %>%
filter(education != "unknown") %>%
droplevels()table(bank_edu$education)#>
#> basic.4y basic.6y basic.9y high.school
#> 428 188 473 1031
#> illiterate professional.course university.degree
#> 4 595 1670
prop.table(table(bank_edu$education))#>
#> basic.4y basic.6y basic.9y high.school
#> 0.0975165186 0.0428343586 0.1077694236 0.2349054454
#> illiterate professional.course university.degree
#> 0.0009113693 0.1355661882 0.3804966963
Peoples that has university degree has higher frequency that loaning money from bank. Meanwhile, illiterate is group of people that have least loan to the bank
ggplot(data = bank_edu, mapping = aes(x = education)) +
geom_bar()+
labs(title = "People's Educational Level that Subscribe in Term of Deposit") +
theme_minimal()From plot above we know that people who has university degree has the most deposit in bank. Maybe this because people who has higher educational degree know more about money knowledge than other people with different educational level. This goes along with illiterate that has least number of people who have deposit in bank. Another reasons why higher educational degree has more people who deposit their money in Bank is higher educational level will come along with higher possibility to get better job and better salary.
Another Gorup of People that has Deposit in Bank (Credit Default, Housing Loan, Personal Loan)
default_bank <- subscribe %>%
filter(default != "unknown") %>%
droplevels()housing_bank <- subscribe %>%
filter(housing != "unknown") %>%
droplevels()loan_bank <- subscribe %>%
filter(loan != "unknown") %>%
droplevels()plot1 <- ggplot(data = default_bank, mapping = aes(x = default)) +
geom_bar() +
labs(title = "Did Someone Who has Credit Default have Deposit in Bank?") +
theme_minimal()
plot2 <- ggplot(data = housing_bank, mapping = aes(x = housing)) +
geom_bar() +
labs(title = "Group of People Who Have Bank Deposit Who has Housing Loan or Not") +
theme_minimal()
plot3 <- ggplot(data = loan_bank, mapping = aes(x = loan)) +
geom_bar() +
labs(title = "People's Educational Level that Subscribe in Term of Deposit") +
theme_minimal()
grid.arrange(plot1, plot2, plot3)default_table <- table(default_bank$default)
housing_table <- table(housing_bank$housing)
loan_table <- table(loan_bank$loan)
df1 <- as.data.frame(housing_table) %>%
spread(Var1, Freq) %>%
rownames_to_column(var = "Var") %>%
rename(people_group = Var)
df1$people_group <- paste0("housing", df1$people_group)
df2 <- as.data.frame(loan_table) %>%
spread(Var1, Freq) %>%
rownames_to_column(var = "Var") %>%
rename(people_group = Var)
df2$people_group <- paste0("loan", df2$people_group)
df3 <- as.data.frame(default_table) %>%
spread(Var1, Freq) %>%
rownames_to_column(var = "Var") %>%
rename(people_group = Var)
df3$people_group <- paste0("default", df3$people_group)
df3$yes <- 0
df <- rbind(df1, df2, df3)
df$people_group[df$people_group == "housing1"] <- "housing"
df$people_group[df$people_group == "loan1"] <- "loan"
df$people_group[df$people_group == "default1"] <- "default"
df#> people_group no yes
#> 1 housing 2026 2507
#> 2 loan 3850 683
#> 3 default 4197 0
From our analysis above, we can say that more people who have housing loan have deposit in bank rather than people who don’t. Its counter intuitive if we look at group of people who have personal loan and credit default, By logic people who don’t have personal loan or credit default will be much easier for them to set aside money to saving.
Relationship Between Group of People
From analysis before we can know distribution of people who has deposit in bank. I’ll combine some columns to see more specific about distribution of peoples group that subscribe into term of deposit. I’ll only use the higher frequency from each group to see the result
Educational Level and Job
edu_job <- subscribe %>%
select(education, job) %>%
filter(education == "university.degree")
ggplot(data = edu_job, mapping = aes(x = job)) +
geom_bar() +
labs(title = "Group of Working People that has University Degre") +
theme_minimal()From plot above, we still have admin as the highest group of people that has term of deposit in bank with university degree background, followed by technician and management. What about age range of people around 31-40 years old?
People’s Job with University Degree Around 31 - 40 Years Old
bank_age <- subscribe %>%
filter(age_range == "31 - 40 years",
education == "university.degree")
ggplot(data = bank_age, mapping = aes(x = job)) +
geom_bar() +
labs(title = "Group of Working People that has University Degre Around 31 - 40 Years Old") +
theme_minimal()Still, we have same result as before, where admin is the higher group of people that subscribe in term of deposit with university degree aroud 31 - 40 years old.
Bank Effort in Contacting their Costumer
In order to get consumer to subscribe in term of deposit, bank always contacting their costumer to explain and persuade them to have a deposit in their bank. So I’ll try to analyze if contact duration or day passed since the last time bank contacting their costumer has effect in better result.
Frequency of Last Month Since Costumer Contacted
table(subscribe$month)#>
#> apr aug dec jul jun mar may nov oct sep
#> 539 655 89 649 559 276 886 416 315 256
Fix Month order
month_bank <- subscribe %>%
mutate(month = factor(month, levels = c("mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec")))ggplot(data = month_bank, mapping = aes(x = month)) +
geom_bar() +
labs(title = "Last Month Since Costumer Contacted") +
theme_minimal()Our data was collected between May 2008 until November 2010, since there’s no obvious date provided, we assume all activity happened in a year.
From plot above, we know when consumer last contacted in May, July and August has highest number who subscribe in term of deposit, so I will focus in this three months.
Day of Week
Is there specific days when bank contact their consumer that effect the result consumer do subscribe in term of deposit?
day_month <- month_bank %>%
select(month, day_of_week) %>%
filter(month %in% c("may", "jul", "aug")) %>%
group_by(month, day_of_week) %>%
count() %>%
ungroup() %>%
arrange(month, desc(n)) %>%
mutate(total = n)Specific day in May
may_month <- day_month %>%
filter(month == "may")ggplot(data = may_month, mapping = aes(x = day_of_week, y = total)) +
geom_bar(stat = "identity") +
labs(title = "Specific Day in May") +
theme_minimal()Specific day in July
jul_month <- day_month %>%
filter(month == "jul")ggplot(data = jul_month, mapping = aes(x = day_of_week, y = total)) +
geom_bar(stat = "identity") +
labs(title = "Specific Day in July") +
theme_minimal()Specific day in August
aug_month <- day_month %>%
filter(month == "aug")ggplot(data = aug_month, mapping = aes(x = day_of_week, y = total)) +
geom_bar(stat = "identity") +
labs(title = "Specific Day in August") +
theme_minimal()From three plot above, I can say there’s no specific day when the last day people getting contacted by bank and do subscribe in term of deposit. Each day has same probability to give sam result for bank.
Duration of Contact
In order to know whether duration while bank contacting their consumer will affecting the result people do subscribe in term of deposit, I’ll focusing the analysis in three top months each day
may_duration <- subscribe %>%
filter(month == "may",
duration != 0) %>%
select(month, day_of_week, duration)
jul_duration <- subscribe %>%
filter(month == "jul",
duration != 0) %>%
select(month, day_of_week, duration)
aug_duration <- subscribe %>%
filter(month == "aug",
duration != 0) %>%
select(month, day_of_week, duration)ggplot(may_duration, aes(day_of_week, duration)) +
geom_jitter(aes(col = may_duration$duration)) +
geom_boxplot(alpha = 0.5) +
labs(title = "Call Duration Each Day in May", x= "Week Days", y= "Duration")ggplot(jul_duration, aes(day_of_week, duration)) +
geom_jitter(aes(col = jul_duration$duration)) +
geom_boxplot(alpha = 0.5) +
labs(title = "Call Duration Each Day in July", x= "Week Days", y= "Duration")ggplot(aug_duration, aes(day_of_week, duration)) +
geom_jitter(aes(col = aug_duration$duration)) +
geom_boxplot(alpha = 0.5) +
labs(title = "Call Duration Each Day in Aug", x= "Week Days", y= "Duration")From all three plot above, my conclusion is bank didn’t have to do long duration while contacting their consumer. From 3 top months, all calls duration are beneath 1000 second (around 17 minutes), only few calls performed above that. So for further communication between bank and consumer, it’s better to do it beneath 1000 second
Final Conclusion
My final conclusion from above analysis is:
To get more consumers who subscribe in terms of deposit, the bank can focus on group of people around 31-40 years old. Because in this age range, people start to plan their finances for various needs, so having a deposit is one of the best options for them.
Consumer who has university degree tend to have deposit in Bank, maybe they have more knowledge about money literation.
Consumer who works as an admin is a higher job where people have a term of deposit in the bank.
There’s no specific day where consumer get contacted by bank and do subscribe in term of deposit
Most call duration where consumers finally do subscribe perform under 1000 seconds (around 17 minutes)