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.
Category | Technology |
---|---|
Programming Language | Python |
Machine Learning | TensorFlow/Keras, Scikit-learn |
Data Manipulation | Pandas, NumPy |
API Framework | FastAPI |
Data Scaling | StandardScaler, Random Oversampling |
- Binary Classification: Predicts the likelihood of credit card default.
- Probability Output: Provides interpretable percentage risk scores.
- Class Balancing: Handles imbalanced datasets using Random Oversampling.
- Regression-based: Estimates appropriate credit limits for customers.
- Regularization: Incorporates techniques to avoid overfitting.
- Custom Feature Engineering: Tailored financial predictors for better performance.
- 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.
- FastAPI Framework: Efficient, asynchronous API handling.
- Pydantic for Validation: Validates incoming request payloads.
- Robust Error Handling: Ensures predictable and stable responses.
Ensure you have the following installed:
- Python 3.8+
- pip (Python package manager)
- Virtual environment (recommended)
- Clone the repository:
git clone https://github.com/austinLorenzMccoy/credit-prediction-api cd credit-prediction-api
- Install dependencies:
pip install -r requirements.txt
To start the API server locally:
python cli.py api
- URL:
/api/v1/predict/default
- Method:
POST
- Input: Simplified customer financial data
- Output: Default risk as a percentage probability with risk factors
- URL:
/api/v1/predict/credit-limit
- Method:
POST
- Input: Simplified customer financial data
- Output: Recommended credit limit with adjustment factors
- URL:
/api/v1/health
- Method:
GET
- Output: API health status and model status
curl -X GET http://localhost:8000/api/v1/health
Response:
{"status":"healthy","model_status":{"predictor_ready":true}}
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"]}
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"]}
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 |
- URL:
/predict/default
- Method:
POST
- Input: Customer's financial features (list of floats)
- Output: Default risk as a percentage probability
- URL:
/predict/credit-limit
- Method:
POST
- Input: Customer's age, payment history, and bill amount
- Output: Recommended credit limit (numeric)
- Accuracy: Validated on a balanced dataset with enhanced features.
- Metric: Mean Squared Error minimized through iterative fine-tuning.
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
- Models trained on anonymized data.
- No sensitive information is stored or processed beyond the scope of prediction tasks.
We welcome contributions! To get started:
- Fork this repository.
- Create a feature branch:
git checkout -b feature-name
. - Commit your changes:
git commit -m "Add new feature"
. - Push the branch:
git push origin feature-name
. - Open a pull request for review.
This project is licensed under the MIT License. See the LICENSE file for details.
- GitHub: @austinLorenzMccoy
- Email: chibuezeaugustine23@gmail.com