Predicting how much loan will be approved

Badge source
Key findings: People with the highest credit score, and have a co-applicant, are more likely to receive a large loan amount.
Authors
Table of Contents
- Business problem - Data source - Methods - Tech Stack - Quick glance at the results - Lessons learned and recommendation - Limitation and what can be improved - Run Locally - Explore the notebook - Deployment on streamlit - App deployed on Streamlit - Repository structure - Contribution - License
Business problem
This app predicts how much of a loan will be granted to an applicant. The app uses different information about the applicant profile and predict how much will be approved. Usually the applicant with a higher credit score, a co-applicant will be granted a larger loan amount. It depends also on how much the applicant has requested.
Data source
Methods
- Exploratory data analysis
- Bivariate analysis
- Multivariate correlation
- S3 bucket model hosting
- Model deployment
Tech Stack
- Python (refer to requirement.txt and yml file in the assets folder for the packages used in this project)
- Streamlit (interface for the model)
- AWS S3 (model storage)
Quick glance at the results
Correlation between the features.

RMSE of random forest with the best hyperparameters.

We have an RMSE on a range between 0 and 400000
Top features of random forest with the best hyperparameters.

Least useful features of random forest with the best hyperparameters.

Top 3 models (with default parameters)
| Model with the best hyperparameter | RMSE (range between 0 and 400000) | |------------------- |------------------ | | Random Forest | 20791.86 | | Bagging | 20780.02 | | Gradient Boosting | 26974.42 |
- The final model used is: Random Forest
- Metrics used: RMSE
- Why choose random forest while bagging yield the best results?:
RMSE random forest

RMSE bagging

Lessons learned and recommendation
- Based on the analysis on this project, we found out that the loan amount that will be granted is determined mainly by the loan amount requested, credit score and a co-applicant. The least important features are expenses types and gender.
- Recommendation would be to focus more on the most predictive feature when looking at the applicant profile, and pay less attention on the least predictive features.
Limitation and what can be improved
- The dataset lack a metadata about the features. (What expenses types mean? What does property type 1, 2, 3, 4 mean?)
- Retrain the model without the least predictive features
- Hyperparameter tuning: I used RandomSearchCV to save time but could be improved by couple of % with GridSearchCV.
Run Locally
Initialize gitgit init
Clone the project
git clone https://github.com/semasuka/Loan-amount-prediction-regression.git
enter the project directory
cd Loan-amount-prediction-regression
Create a conda virtual environment and install all the packages from the environment.yml (recommended)
conda env create --prefix <env_name> --file assets/environment.yml
Activate the conda environment
conda activate <env_name>
List all the packages installed
conda list
Start the streamlit server locally
streamlit run loanamountapp.py
If you are having issue with streamlit, please follow this tutorial on how to set up streamlit
Explore the notebook
To explore the notebook file here
Deployment on streamlit
To deploy this project on streamlit share, follow these steps:
- first, make sure you upload your files on Github, including a requirements.txt file
- go to streamlit share
- login with Github, Google, etc.
- click on new app button
- select the Github repo name, branch, python file with the streamlit codes
- click advanced settings, select python version 3.9 and add the secret keys if your model is stored on AWS or GCP bucket
- then save and deploy!
App deployed on Streamlit

Video to gif tool
Repository structure
โโโ assets
โ โโโ bottom10.png <- A picture of the bottom 10 features
โ โโโ environment.yml <- list of all the dependencies with their versions(for conda environment)
โ โโโ gif_streamlit.gif <- gif file used in the README
โ โโโ heatmap.png <- heatmap image used in the README
โ โโโ loanamountbanner.png <- banner image used in the README
โ โโโ rmse.png <- Image of the best RMSE from the random forest used in the README
โ โโโ rmse_bagging.png <- Image of the bagging RMSE used in the README
โ โโโ rmserandforest.png <- Image of the random forest RMSE used in the README
โ โโโ top10.png <- A picture of the top 10 features
โ
โโโ datasets
โ โโโ test.csv <- the test data
โ โโโ train.csv <- the train data
โ
โ
โโโ .gitignore <- used to ignore certain folder and files that won't be commit to git.
โ
โ
โโโ LICENSE <- license file.
โ
โ
โโโ Loanamountprediction.ipynb <- main python notebook where all the analysis and modeling are done.
โ
โ
โโโ README.md <- this readme file.
โ
โ
โโโ loanamountapp.py <- file with the model and streamlit component for rendering the interface.
โ
โ
โโโ requirements.txt <- list of all the dependencies with their versions(used for Streamlit).
Contribution
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change or contribute.
License
MIT License
Copyright (c) 2022 Stern Semasuka
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Learn more about MIT license