A machine learning application that predicts whether a loan applicant will default on their loan. Built with FastAPI and Streamlit, containerized with Docker, and deployable to AWS ECS.
- Input: Loan application details (12 fields)
- Output: Prediction of "Default" or "No Default"
- Model: Support Vector Machine (SVM)
- Frontend: Streamlit
- API: FastAPI
- Deployment: Docker (local), AWS ECS Fargate (cloud)
loan_default_prediction/
├── app/
│ ├── __init__.py
│ ├── inference.py
│ ├── main.py
│ └── streamlit_app.py
├── data/
│ └── .gitkeep
├── notebooks/
│ └── sas-challenge.ipynb
├── requirements.txt
├── Dockerfile
├── .dockerignore
├── .gitignore
├── README.md
└── LICENSE
pip install -r requirements.txtuvicorn app.main:app --reload --host 0.0.0.0 --port 8000streamlit run app/streamlit_app.pydocker build -t loan-prediction-app .
docker run -d -p 8503:8503 --name test-streamlit loan-prediction-app
# Visit http://localhost:8503-
Build and Push Docker Image to ECR
docker tag loan-prediction-app:latest <your-account-id>.dkr.ecr.<region>.amazonaws.com/loan-prediction-app:latest docker push <your-account-id>.dkr.ecr.<region>.amazonaws.com/loan-prediction-app:latest
-
Deploy to ECS
- Use the provided
deploy-aws.shscript or follow the AWS Console steps. - Ensure your ECS service uses a public subnet and security group allows inbound TCP on port 8503.
- Use the provided
-
Access the App
- Find your ECS task's public IP.
- Visit:
http://<public-ip>:8503
curl http://localhost:8000/healthcurl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{ ... }'| Field | Example | Description |
|---|---|---|
| loan_amount | 20000 | Loan amount in dollars |
| mortgage_amount | 140000 | Mortgage amount in dollars |
| property_value | 200000 | Property value in dollars |
| loan_reason | "DebtCon" | "DebtCon" or "HomeImp" |
| occupation_length | 5 | Years in current job |
| derogatory_reports | 0 | Number of bad credit reports |
| late_payments | 0 | Number of late payments |
| oldest_credit_line | 120 | Age of oldest credit (months) |
| recent_credit | 1 | Recent credit inquiries |
| credit_number | 20 | Number of credit accounts |
| ratio | 35.5 | Debt-to-income ratio (%) |
| occupation | "ProfExe" | Job type (see options below) |
- Develop and test locally (with or without Docker).
- Build Docker image and verify locally.
- Push image to AWS ECR.
- Deploy to AWS ECS Fargate using the latest image.
- Configure security group for public access on port 8503.
- Access your app via the public IP and port 8503.
- This is a demonstration model; not for real loan decisions.
- Do not commit large data/model files to GitHub.
- All predictions are logged (without personal data).