A step-by-step machine learning project to assess loan default risk using borrower data
📘 Read full project write-up: Building an AI Lending Model – Step-by-Step Guide
This is a web application deployed on Google App Engine that provides real-time loan default risk assessment using a machine learning model deployed on Vertex AI. The application takes loan details as input and returns the probability of default along with risk assessment metrics.
- Real-time loan default risk prediction
- Web-based interface for loan officers
- Integration with Vertex AI for model inference
- Comprehensive input validation
- Detailed risk assessment results including:
- Default probability
- Risk level classification
- Confidence score
- Request tracking
- Google Cloud Platform account
- Python 3.9
- Google Cloud SDK
- A trained model deployed on Vertex AI
lendingapp/
├── main.py # Main application file
├── app.yaml # App Engine configuration
├── requirements.txt # Python dependencies
├── artifacts/
│ ├── numeric_features # List of numeric features
│ ├── selected_features # List of all features used by model
│ └── scaler.pkl # Fitted StandardScaler object
└── templates/
└── index.html # Frontend interface
- Update
app.yamlwith your project details:
env_variables:
PROJECT_ID: "your-project-id"
LOCATION: "us-central1"
ENDPOINT_ID: "your-endpoint-id"
GOOGLE_CLOUD_PROJECT: "your-project-id"- Ensure your Vertex AI model endpoint is deployed and accessible.
The application accepts the following inputs:
- Original Loan Amount ($): 10,000 - 2,000,000
- Credit Score: 300 - 850
- Original Loan-to-Value Ratio (%): 0 - 100
- Debt-to-Income Ratio (%): 0 - 65
- Original Interest Rate (%): 0 - 25
- State: Valid US state codes
- Clone the repository:
git clone [repository-url]
cd lendingapp- Install dependencies locally (for testing):
pip install -r requirements.txt- Deploy to App Engine:
gcloud app deploy app.yaml- View the deployed application:
gcloud app browseThe application provides:
- Default Probability: The model's predicted probability of loan default
- Risk Level: Classification as "High" (>50%) or "Low" (≤50%)
- Confidence: The model's confidence in its prediction
- Request ID: Unique identifier for tracking predictions
- Timestamp: When the prediction was made
The application includes:
- Input validation for all fields
- Proper error messages for invalid inputs
- Logging for debugging and monitoring
- Error tracking with request IDs
Monitor the application using Google Cloud Console:
- App Engine dashboard for application metrics
- Cloud Logging for detailed logs
- Vertex AI dashboard for model metrics