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

Join Sign in

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

1 hour 30 minutes 5 Credits


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.

What you'll learn

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.

  2. Click Continue.

It takes a few moments to provision and connect to the environment. 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 YOUR_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


ACTIVE: * 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_ID>

Example output:

[core] project = qwiklabs-gcp-44776a13dea667a6 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 New Notebook.

  3. In the Customize instance menu, select TensorFlow Enterprise and choose the version of TensorFlow Enterprise 2.3 (with LTS) > Without GPUs.

  4. In the New notebook instance dialog, for Region, select us-central1, for Zone, select a zone within the selected region, 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.

Finish your quest

This self-paced lab is part of the Build and Deploy Machine Learning Solutions on Vertex AI quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest and get immediate completion credit. Refer to the Google Cloud Skills Boost catalog for all available quests.

Take your next lab

Continue the Build and Deploy Machine Learning Solutions on Vertex AI quest with the next lab, Vertex Pipelines: Qwik Start.

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 September 22, 2022

Lab Last Tested September 22, 2022

Copyright 2022 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.