Deploy a BigQuery ML Customer Churn Classifier to Vertex AI for Online Predictions

Sign in Join
Test and share your knowledge with our community!
Get access to over 700 hands-on labs, skill badges, and courses

Deploy a BigQuery ML Customer Churn Classifier to Vertex AI for Online Predictions

Lab 1 hour 30 minutes universal_currency_alt 5 Credits show_chart Intermediate
info This lab may incorporate AI tools to support your learning.
Test and share your knowledge with our community!
Get access to over 700 hands-on labs, skill badges, and courses


Google Cloud self-paced labs logo


In this lab, you will train, tune, evaluate, explain, and generate batch and online predictions with a BigQuery ML XGBoost model. You will use a Google Analytics 4 dataset from a real mobile application, Flood it! (Android app, iOS app), to determine the likelihood of users returning to the application. You will generate batch predictions with your BigQuery ML model as well as export and deploy it to Vertex AI for online predictions using the Vertex Python SDK.

BigQuery ML lets you train and do batch inference with machine learning models in BigQuery using standard SQL queries faster by eliminating the need to move data with fewer lines of code.

Vertex AI is Google Cloud's complimentary next generation, unified platform for machine learning development. By developing and deploying BigQuery ML machine learning solutions on Vertex AI, you can leverage a scalable online prediction service and MLOps tools for model retraining and monitoring to significantly enhance your development productivity, the ability to scale your workflow and decision making with your data, and accelerate time to value.

BigQuery ML Vertex AI Lab Architecture diagram Note: BQML is now BigQuery ML.

This lab is inspired by and extends Churn prediction for game developers using Google Analytics 4 (GA4) and BigQuery ML. Read the blog post and accompanying tutorial for additional depth on this use case and BigQuery ML.

In this lab, you will go one step further and focus on how Vertex AI extends BigQuery ML's capabilities through online prediction so you can incorporate both customer churn predictions into decision making UIs such as Looker dashboards but also online predictions directly into customer applications to power targeted interventions such as targeted incentives.


In this lab, you learn how to:

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.


ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project


[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Enable Google Cloud services

  • In Cloud Shell, use gcloud commands to enable the services used in the lab:
gcloud services enable \ \ \ \ \ \ \ \

Task 2. Deploy Vertex Notebook instance

  1. Click on the Navigation Menu (Navigation menu icon) > Vertex AI > Workbench.

  2. On the Notebook instances page, navigate to the User-Managed Notebooks tab and click Create New.

  3. In the Customize new instance menu, select Environment and choose the version of TensorFlow Enterprise 2.11.

  4. In the New instance dialog, for Region, select , for Zone, select , leave all other fields with their default options, and click Create.

After a few minutes, the Vertex AI console will display your instance name, followed by Open Jupyterlab.

  1. Click Open JupyterLab.

Your notebook is now set up.

Click Check my progress to verify the objective. Create a Vertex AI Notebook

Task 3. Clone the lab repository

Next you'll clone the training-data-analyst notebook in your JupyterLab instance.

  1. In JupyterLab, click the Terminal icon to open a new terminal.
Note: If prompted, click Cancel for Build Recommended.
  1. To clone the training-data-analyst Github repository, type in the following command, and press Enter:
cd git clone
  1. To confirm that you have cloned the repository, double-click the training-data-analyst directory and confirm that you can see its contents.

Click Check my progress to verify the objective. Clone the lab repository

Navigate to lab notebook

  1. In your notebook, navigate to training-data-analyst > quests > vertex-ai > vertex-bqml, and open lab_exercise.ipynb.

  2. Continue the lab in the notebook, and run each cell by clicking the Run (run button icon) icon at the top of the screen. Alternatively, you can execute the code in a cell with SHIFT + ENTER.

Read the narrative and make sure you understand what's happening in each cell. As you progress through the lab notebook, return back to these instructions to complete the graded exercises.

Task 4. Create a BigQuery dataset

Click Check my progress to verify the objective. Create a BigQuery dataset

Task 5. Create a BigQuery ML XGBoost churn propensity model

Click Check my progress to verify the objective. Create a BigQuery ML XGBoost churn propensity model

Task 6. Evaluate your BigQuery ML model

Click Check my progress to verify the objective. Evaluate your BigQuery ML model

Task 7. Batch predict user churn with your BigQuery ML model

Click Check my progress to verify the objective. Batch predict user churn with your BigQuery ML model


In this lab you trained, tuned, explained, and deployed a BigQuery ML user churn model to Vertex AI to generate high business impact batch and online churn predictions to target customers likely to churn with interventions such as in-game rewards and reminder notifications.

Next steps / Learn more

Read more about Vertex AI in the Vertex AI Documentation.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated April 17, 2024

Lab Last Tested April 17, 2024

Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.