Skip to content

This project is a state-of-the-art Machine Learning API designed to assist financial institutions with credit risk assessment. It leverages advanced neural networks for: Credit Card Default Prediction: Assess the probability of a customer defaulting on their credit card payments. Credit Limit Recommendation: Estimate an optimal credit limit based

Notifications You must be signed in to change notification settings

austinLorenzMccoy/credit-default-prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 Credit Prediction Machine Learning API

πŸš€ Project Overview

This project is a state-of-the-art Machine Learning API designed to assist financial institutions with credit risk assessment. It leverages advanced neural networks for:

  • Credit Card Default Prediction: Assess the probability of a customer defaulting on their credit card payments.
  • Credit Limit Recommendation: Estimate an optimal credit limit based on customer financial behavior.

With a clean architecture and scalable design, this API bridges the gap between machine learning models and practical financial solutions.


πŸ”§ Tech Stack

Category Technology
Programming Language Python
Machine Learning TensorFlow/Keras, Scikit-learn
Data Manipulation Pandas, NumPy
API Framework FastAPI
Data Scaling StandardScaler, Random Oversampling

πŸ“Š Features

Default Prediction Model

  • Binary Classification: Predicts the likelihood of credit card default.
  • Probability Output: Provides interpretable percentage risk scores.
  • Class Balancing: Handles imbalanced datasets using Random Oversampling.

Credit Limit Prediction Model

  • Regression-based: Estimates appropriate credit limits for customers.
  • Regularization: Incorporates techniques to avoid overfitting.
  • Custom Feature Engineering: Tailored financial predictors for better performance.

πŸ› οΈ Core Capabilities

Machine Learning Highlights

  • Deep Neural Networks: Custom layers with dropout and regularization.
  • Feature Scaling: Scaled inputs ensure consistent model performance.
  • Model Evaluation: Metrics like Mean Squared Error and Classification Accuracy guide training.

API Development

  • FastAPI Framework: Efficient, asynchronous API handling.
  • Pydantic for Validation: Validates incoming request payloads.
  • Robust Error Handling: Ensures predictable and stable responses.

🚦 Getting Started

Prerequisites

Ensure you have the following installed:

  • Python 3.8+
  • pip (Python package manager)
  • Virtual environment (recommended)

Installation

  1. Clone the repository:
    git clone https://github.com/austinLorenzMccoy/credit-prediction-api  
    cd credit-prediction-api  
  2. Install dependencies:
    pip install -r requirements.txt  

Running the API

To start the API server locally:

python cli.py api  

πŸ“‘ API Endpoints

1️⃣ Default Prediction

  • URL: /api/v1/predict/default
  • Method: POST
  • Input: Simplified customer financial data
  • Output: Default risk as a percentage probability with risk factors

2️⃣ Credit Limit Prediction

  • URL: /api/v1/predict/credit-limit
  • Method: POST
  • Input: Simplified customer financial data
  • Output: Recommended credit limit with adjustment factors

3️⃣ Health Check

  • URL: /api/v1/health
  • Method: GET
  • Output: API health status and model status

πŸ” Example API Usage with curl

Check API Health

curl -X GET http://localhost:8000/api/v1/health

Response:

{"status":"healthy","model_status":{"predictor_ready":true}}

Predict Default Risk

curl -X POST http://localhost:8000/api/v1/predict/default \
  -H "Content-Type: application/json" \
  -d '{
    "credit_limit": 100000,
    "age": 25,
    "gender": 2,
    "education": 2,
    "marital_status": 1,
    "payment_status": 0,
    "bill_amount": 10000,
    "payment_amount": 2000
  }'

Response:

{"prediction":"Low Risk of Default (Probability: 15.00%)","probability":0.15,"is_high_risk":false,"risk_factors":["Low payment to bill ratio"]}

Predict Credit Limit

curl -X POST http://localhost:8000/api/v1/predict/credit-limit \
  -H "Content-Type: application/json" \
  -d '{
    "credit_limit": 100000,
    "age": 35,
    "gender": 2,
    "education": 1,
    "marital_status": 1,
    "payment_status": 0,
    "bill_amount": 10000,
    "payment_amount": 8000
  }'

Response:

{"predicted_credit_limit":150000.0,"adjustment_factor":1.5,"recommendation_factors":["Good payment history","High payment to bill ratio","Age factor positive","Education level positive"]}

πŸ“Š Input Parameters Explained

Parameter Description Values
credit_limit Current credit limit Numeric value
age Customer age Integer
gender Customer gender 1=male, 2=female
education Education level 1=graduate, 2=university, 3=high school, 4=others
marital_status Marital status 1=married, 2=single, 3=others
payment_status Last month's payment status 0=paid duly, 1=1 month delay, 2=2 months delay, etc.
bill_amount Last month's bill amount Numeric value
payment_amount Last month's payment amount Numeric value

πŸ“‘ API Endpoints

1️⃣ Default Prediction

  • URL: /predict/default
  • Method: POST
  • Input: Customer's financial features (list of floats)
  • Output: Default risk as a percentage probability

2️⃣ Credit Limit Prediction

  • URL: /predict/credit-limit
  • Method: POST
  • Input: Customer's age, payment history, and bill amount
  • Output: Recommended credit limit (numeric)

πŸ“ˆ Model Performance

Default Prediction Model

  • Accuracy: Validated on a balanced dataset with enhanced features.

Credit Limit Prediction Model

  • Metric: Mean Squared Error minimized through iterative fine-tuning.

πŸ“‚ Project Structure

credit-prediction-api/  
β”œβ”€β”€ app/  
β”‚   β”œβ”€β”€ app.py             # FastAPI application  
β”‚   β”œβ”€β”€ main.py            # Model training script  
β”‚   β”œβ”€β”€ models/            # Pre-trained models  
β”‚   β”œβ”€β”€ scalers/           # Saved scalers  
β”œβ”€β”€ data/  
β”‚   β”œβ”€β”€ raw/               # Original datasets  
β”œβ”€β”€ notebooks/             # Jupyter notebooks for EDA and model training  
β”œβ”€β”€ frontend/              # HTML, CSS, and JS files for the user interface  
β”œβ”€β”€ tests/                 # Unit tests for endpoints  
β”œβ”€β”€ requirements.txt       # Python dependencies  
β”œβ”€β”€ README.md              # Project documentation  
└── .env                   # Environment variables  

πŸ”’ Data Privacy

  • Models trained on anonymized data.
  • No sensitive information is stored or processed beyond the scope of prediction tasks.

🀝 Contributing

We welcome contributions! To get started:

  1. Fork this repository.
  2. Create a feature branch: git checkout -b feature-name.
  3. Commit your changes: git commit -m "Add new feature".
  4. Push the branch: git push origin feature-name.
  5. Open a pull request for review.

πŸ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.


πŸ‘₯ Contact

About

This project is a state-of-the-art Machine Learning API designed to assist financial institutions with credit risk assessment. It leverages advanced neural networks for: Credit Card Default Prediction: Assess the probability of a customer defaulting on their credit card payments. Credit Limit Recommendation: Estimate an optimal credit limit based

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published