GCP ML Lab 2 – Vertex AI: Predicting Loan Risk with AutoML

Vertex AI Loan Risk Prediction Workflow Vertex AI Loan Risk Prediction Workflow

Vertex AI Loan Risk Prediction Workflow

This guide explains how to create and deploy a machine learning model in Google Cloud’s Vertex AI to predict the risk of loan defaults.

Task 1: Prepare the Training Data

Create a Dataset

  1. Go to Vertex AI > Datasets in the Google Cloud Console.
  2. Click Create dataset, name it LoanRisk.
  3. Select Tabular and choose Regression/Classification.

Upload Data

  • Choose CSV from Cloud Storage.
  • Enter the file path: spls/cbl455/loan_risk.csv.

Generate Statistics (Optional)

Click Generate statistics to view summary metrics and visualizations for each column.

Task 2: Train the Model

Model Setup

  1. Click Train new model > Other.
  2. Select Classification as the objective.
  3. Name the model LoanRisk and set Default as the target column.

Feature Selection

Exclude non-relevant fields such as ClientID from the model training.

Training Configuration

  • Set training budget to 1 node hour.
  • Keep Early stopping enabled.

Task 3: Evaluate Model Performance

Precision/Recall Curve

Adjust the confidence threshold to analyze trade-offs between precision and recall.

Confusion Matrix

Displays how accurately the model classified repay and default instances.

Feature Importance

Visualizes the impact of each feature on the model’s predictions. Helps refine the model by identifying key predictors.

Task 4: Deploy the Model

Deployment Steps

  1. Click Deploy to Endpoint.
  2. Name the endpoint LoanRisk and select an appropriate machine type (e.g., e2-standard-8).
  3. Enable Feature attribution under Explainability options.
  4. Assign the training dataset and target column (Default).
  5. Click Deploy to create the endpoint.

Task 5: Get Predictions

Environment Setup

Set environment variables for input file, project number, and AutoML service endpoint in Cloud Shell.

Send Prediction Request

Use curl to send a POST request with a JSON payload containing fields like age, income, and loan. The response includes prediction scores for each class (repay or default).

Sample Output

The response shows confidence scores for each class and includes the model ID and display name.

This completes the end-to-end process of preparing data, training, evaluating, deploying, and making predictions with Vertex AI.

Leave a Reply

Your email address will not be published. Required fields are marked *