1 Data

The “Bank Personal Loan Modelling” dataset comprises a comprehensive numerical table aimed at assisting banks in tailoring loan offerings to individual clients. It encompasses key demographic and financial indicators, including age, experience, income, and ZIP code, among others. By leveraging this dataset, banks can analyze client profiles with precision, identifying optimal loan products tailored to specific financial circumstances and risk profiles. With insights gleaned from this dataset, financial institutions can enhance their decision-making processes, ensuring that clients receive personalized loan recommendations that align with their unique needs and financial capabilities. Source: https://www.kaggle.com/datasets/samira1992/bank-loan-intermediate-dataset

data = read.csv("https://hedibert.org/wp-content/uploads/2024/05/Bank_Personal_Loan_Modelling.csv",header=TRUE)

n = nrow(data)

attach(data)

par(mfrow=c(1,2))
hist(Income,xlab="Income",prob=TRUE,main="")
abline(v=quantile(Income,0.25),lwd=2,col=2)
abline(v=quantile(Income,0.5),lwd=2,col=2)
abline(v=quantile(Income,0.75),lwd=2,col=2)
plot(Income,Personal.Loan+rnorm(n,0,0.02),xlab="Income",ylab="Loan?",axes=FALSE)
axis(1);box();axis(2,at=c(0,1),lab=c("No (0)","Yes (1)"))

mean(Personal.Loan)
## [1] 0.096
mean(Personal.Loan[Education==1])
## [1] 0.04437023
mean(Personal.Loan[Education==2])
## [1] 0.129722
mean(Personal.Loan[Education==3])
## [1] 0.1365756
Educ = rep(1,n)
Educ[Education==1]=0
LS0tCnRpdGxlOiAiQmF5ZXNpYW4gTG9naXN0aWMgUmVncmVzc2lvbiIKc3VidGl0bGU6ICJMb2FuLCBpbmNvbWUgYW5kIGVkdWNhdGlvbiIKYXV0aG9yOiAiSGVkaWJlcnQgRnJlaXRhcyBMb3BlcyIKZGF0ZTogIjEwLzI0LzIwMjQiCm91dHB1dDoKICBodG1sX2RvY3VtZW50OgogICAgdG9jOiB0cnVlCiAgICBudW1iZXJfc2VjdGlvbnM6IHRydWUKICAgIHRvY19kZXB0aDogMgogICAgdG9jX2Zsb2F0OiAKICAgICAgY29sbGFwc2VkOiBmYWxzZQogICAgICBzbW9vdGhfc2Nyb2xsOiBmYWxzZQogICAgY29kZ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