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.
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.
- 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
Interactive API documentation generated by FastAPI.
Example prediction using the /predict endpoint.
Application deployed on an AWS EC2 instance.
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.
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
- Python
- Scikit-learn
- Pandas
- NumPy
- FastAPI
- Uvicorn
- Pydantic
- Docker
- Docker Hub
- AWS EC2
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
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 |
GET /
Returns a welcome message.
POST /predict
{
"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"
}{
"credit_risk": "Low Risk",
"confidence": 0.932
}Clone the repository.
git clone https://github.com/devsutharsystems/credit-risk-classification-deployment-engine.git
cd credit-risk-classification-deployment-engineInstall dependencies.
pip install -r requirements.txtStart the FastAPI server.
uvicorn main:app --reloadOpen
http://127.0.0.1:8000/docs
Build the Docker image.
docker build -t credit-risk-api .Run the container.
docker run -p 8000:8000 credit-risk-apiThe application is deployed on an AWS EC2 instance using Docker.
Swagger Documentation
http://13.60.78.56:8001/docs
- Hyperparameter tuning
- Feature importance visualization
- Model explainability using SHAP
- CI/CD with GitHub Actions
- Docker Compose
- Kubernetes deployment
- Cloud monitoring and logging
Dev Suthar
- GitHub: https://github.com/devsutharsystems
- LinkedIn: https://linkedin.com/in/i-dev-suthar