This project predicts whether a credit card client will default on payment next month, using a machine learning model trained on the "Default of Credit Card Clients" dataset. The model is served as an API using FastAPI and deployed with Uvicorn, while MongoDB Cloud is used for storing client data and prediction results.
- Dataset: Default of Credit Card Clients
- ML Model: Random Forest Classifier (for binary classification)
- API Framework: FastAPI
- Server: Uvicorn (ASGI server)
- Database: MongoDB Cloud (for prediction and request storage)
payment-delay-prediction/ ├── db/ │ ├── config.py # database configration │ ├── database.py # MongoDB connection & storage logic │ ├── dataset/ │ └── default.csv # Dataset file (optional) | ├── main.py # FastAPI entry point ├── model.py # Model training & loading logic ├── schemas.py # Pydantic schemas for request/response ├── requirements.txt # Python dependencies └── README.md # Project description
- Train and save a Random Forest model for payment default prediction
- Predict default status via REST API
- Log predictions and input data to MongoDB Cloud
- Simple and fast deployment with Uvicorn
- Target: default.payment.next.month (1 = default, 0 = not)
- Features: 23 financial and demographic variables
- Preprocessing: Handled internally before model training
Predict default status of a credit card client.
Sample Request:
{
"LIMIT_BAL": 20000,
"SEX": 2,
"EDUCATION": 2,
"MARRIAGE": 1,
"AGE": 24,
"PAY_0": 2,
"PAY_2": 2,
"PAY_3": -1,
"PAY_4": -1,
"PAY_5": -2,
"PAY_6": -2,
"BILL_AMT1": 3913,
"BILL_AMT2": 3102,
"BILL_AMT3": 689,
"BILL_AMT4": 0,
"BILL_AMT5": 0,
"BILL_AMT6": 0,
"PAY_AMT1": 0,
"PAY_AMT2": 689,
"PAY_AMT3": 0,
"PAY_AMT4": 0,
"PAY_AMT5": 0,
"PAY_AMT6": 0
}
Sample Response:
{
name: "jamie"
balance: 20000
gender : male
age : 34
"default": "no",
"summary": "On the predicted data the user may be not a defaulter"
}
git clone https://github.com/mohsinraza2999/payment-delay-prediction.git cd payment-delay-prediction
pip install -r requirements.txt
python app/model.py
uvicorn app.main:app --reload
- Create a MongoDB Atlas account.
- Set up a new cluster and create a database + collection.
- Obtain your connection string (Mongo URI).
- Add it to your environment or use a
.envfile:
MONGO_URI=mongodb+srv://<username>:<password>@cluster0.mongodb.net/dbname
- Add model versioning
- Implement user authentication
- Add logging and monitoring
- Develop a front-end dashboard
This project is licensed under the MIT License.
Mohsin Raza
Open to contributions, feedback, and improvements!