Skip to content

devsutharsystems/credit-risk-classification-deployment-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏦 Credit Risk Classification And Deployment Engine

A Machine Learning-powered REST API that assesses the credit risk of loan applicants by predicting loan approval outcomes from demographic and financial information.

The project was developed using Python, Scikit-learn, and FastAPI, containerized with Docker, and deployed on AWS EC2.


πŸ“– Overview

Credit risk assessment is a critical process in the banking and financial industry. Financial institutions evaluate multiple applicant attributes before approving credit or loans. This project automates that decision by training and comparing multiple machine learning models and deploying the best-performing model through a production-ready REST API.

Users can submit applicant information through the API and receive an instant credit risk classification.


✨ Features

  • Trained and compared multiple machine learning algorithms
  • Automated preprocessing pipeline
  • REST API built with FastAPI
  • Interactive Swagger UI documentation
  • Dockerized application
  • Deployed on AWS EC2
  • Production-ready inference pipeline
  • Clean and modular project structure

πŸ“Έ Project Screenshots

Swagger UI

Interactive API documentation generated by FastAPI.

image

Credit Risk Prediction Example

Example prediction using the /predict endpoint.

image

AWS EC2 Deployment

Application deployed on an AWS EC2 instance.

image

πŸ“Š Model Performance

The following machine learning algorithms were evaluated.

Model Accuracy
Random Forest 78.57%
Gaussian Naive Bayes 83.12%
Decision Tree 72.08%
K-Nearest Neighbors 81.17%
Support Vector Classifier 83.12%

The deployed Credit Risk Classification API uses the Gaussian Naive Bayes classifier, which achieved the highest validation accuracy during model evaluation.

Model Comparison

image

🧠 Machine Learning Pipeline

Dataset
    β”‚
    β–Ό
Data Cleaning
    β”‚
    β–Ό
Categorical Encoding
    β”‚
    β–Ό
Feature Scaling
    β”‚
    β–Ό
Train/Test Split
    β”‚
    β–Ό
Model Training
(Random Forest, Naive Bayes,
Decision Tree, KNN, SVC)
    β”‚
    β–Ό
Best Model Selection
    β”‚
    β–Ό
Model Serialization (.pkl)
    β”‚
    β–Ό
FastAPI
    β”‚
    β–Ό
Docker
    β”‚
    β–Ό
AWS EC2 Deployment

πŸ›  Tech Stack

Programming Language

  • Python

Machine Learning

  • Scikit-learn
  • Pandas
  • NumPy

API Development

  • FastAPI
  • Uvicorn
  • Pydantic

Deployment

  • Docker
  • Docker Hub
  • AWS EC2

πŸ“‚ Project Structure

credit-risk-classification-deployment-engine/
β”‚
β”œβ”€β”€ main.py
β”œβ”€β”€ train.py
β”œβ”€β”€ preprocessing_utils.py
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
β”‚
β”œβ”€β”€ model.pkl
β”œβ”€β”€ scaler.pkl
β”œβ”€β”€ encoders.pkl
β”œβ”€β”€ label_encoder_y.pkl
β”‚
β”œβ”€β”€ model_comparison.png
β”‚
└── screenshots/
    β”œβ”€β”€ swagger-ui.png
    β”œβ”€β”€ prediction-example.png
    β”œβ”€β”€ docker-ps.png
    └── aws-ec2.png

πŸ“‹ Input Features

The model evaluates the following applicant attributes to classify credit risk.

Feature Description
Gender Applicant Gender
Married Marital Status
Dependents Number of Dependents
Education Education Level
Self Employed Employment Status
Applicant Income Monthly Applicant Income
Coapplicant Income Monthly Co-applicant Income
Loan Amount Requested Loan Amount
Loan Amount Term Loan Repayment Term
Credit History Credit Score Availability
Property Area Urban / Semiurban / Rural

πŸš€ API Endpoints

Home

GET /

Returns a welcome message.


Predict Credit Risk

POST /predict

Example Request

{
    "gender": "Male",
    "married": "Yes",
    "dependents": 1,
    "education": "Graduate",
    "self_employed": "No",
    "applicant_income": 5000,
    "coapplicant_income": 2000,
    "loan_amount": 150,
    "loan_amount_term": 360,
    "credit_history": 1,
    "property_area": "Urban"
}

Example Response

{
    "credit_risk": "Low Risk",
    "confidence": 0.932
}

βš™οΈ Installation

Clone the repository.

git clone https://github.com/devsutharsystems/credit-risk-classification-deployment-engine.git
cd credit-risk-classification-deployment-engine

Install dependencies.

pip install -r requirements.txt

Start the FastAPI server.

uvicorn main:app --reload

Open

http://127.0.0.1:8000/docs

🐳 Docker

Build the Docker image.

docker build -t credit-risk-api .

Run the container.

docker run -p 8000:8000 credit-risk-api

☁️ AWS Deployment

The application is deployed on an AWS EC2 instance using Docker.

Swagger Documentation

http://13.60.78.56:8001/docs

πŸ“ˆ Future Improvements

  • Hyperparameter tuning
  • Feature importance visualization
  • Model explainability using SHAP
  • CI/CD with GitHub Actions
  • Docker Compose
  • Kubernetes deployment
  • Cloud monitoring and logging

πŸ‘¨β€πŸ’» Author

Dev Suthar

About

Loan approval prediction using machine learning with data preprocessing, exploratory data analysis, model comparison, and performance evaluation.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors