Configure your notebook environment

Check my progress

/ 10

Create a connection to Google Cloud Serverless for Apache Spark

Check my progress

/ 10

Load data and explore with Gemini

Check my progress

/ 10

Perform feature engineering

Check my progress

/ 10

Train a logistic regression model

Check my progress

/ 10

Conduct model evaluation

Check my progress

/ 10

Write predictions to BigQuery

Check my progress

/ 10

Save the model to Cloud Storage

Check my progress

/ 10

Create an inference server

Check my progress

/ 10

Configure an agent

Check my progress

/ 10

This lab may incorporate AI tools to support your learning.
This content is not yet optimized for mobile devices.
For the best experience, please visit us on a desktop computer using a link sent by email.

GSP1374

Google Cloud self-paced labs

Overview

Scenario: A hypothetical eCommerce clothing retailer named TheLook stores data on customers, products, orders, logistics, web events, and digital marketing campaigns in BigQuery. The company wants to leverage the team's existing SQL and PySpark expertise to analyze this data using Apache Spark and make predictions about users' future purchases. To avoid manual infrastructure provisioning or tuning for Spark, TheLook seeks an auto-scaling solution that allows them to focus on workloads rather than cluster management. Additionally, they want to minimize the effort required to integrate Spark and BigQuery while staying within the BigQuery Studio environment.

In this lab, you implement a workflow to predict whether a user will make a purchase by building a Logistic Regression Classifier using PySpark and leveraging BigQuery Studio's native notebook integration and AI-features for exploring the data. Then, you deploy this model to an inference server and create an agent to query the model using natural language.

What you'll learn

In this lab, you learn how to perform the following tasks:

  • Use BigQuery Studio notebooks to run a data science workflow.
  • Create a connection to Apache Spark using Managed Service for Apache Spark serverless and powered by Spark Connect.
  • Load data from BigQuery by using the built-in integration between Apache Spark and BigQuery.
  • Explore the data using Gemini-assisted code generation.
  • Perform feature engineering using Apache Spark's data processing framework.
  • Train and evaluate a classification model by using Apache Spark's native machine learning library, MLlib.
  • Deploy an inference server for the classification model using Flask and Cloud Run.
  • Deploy an agent to query the inference server using natural language with Gemini Enterprise Agent Platform's Agent Runtime and the Agent Development Kit (ADK).

Prerequisites

Before starting this lab, you should be familiar with:

  • Basic SQL and Python programming.
  • Running Python code in a Jupyter notebook.
  • A baseline understanding of distributed computing.

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 are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials 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 (recommended) or private browser window to run this lab. This prevents 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: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the right is the Lab setup and access panel with the following:

    • The Open Google Cloud console button
    • The temporary credentials (username and password) that you must use for this lab
    • Other information, if needed, to step through this lab

    Note that the lab timer is located near the top of the page, showing the remaining time.

  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab setup and access panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab setup and access panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field. Navigation menu icon and Search field

Task 1. Access the notebook in BigQuery

In this task, you open the notebook for this lab in BigQuery and connect to a runtime.

  1. In the Google Cloud console, in the Navigation menu (Navigation Menu icon), click BigQuery.

    If a Welcome to BigQuery in the Cloud Console card opens, click Done to dismiss it.

  2. Above the BigQuery Studio pane, next to the SQL query button (+), click the dropdown arrow for Create new.

  3. In the Create new dropdown menu, hover the cursor over Notebook, and select Upload.

Dropdown arrow button

  1. For Upload from, select the URL radio button, and paste the following URL into the URL field:
https://github.com/CloudVLab/lab-assets/blob/main/labs/gsp1374/spark_data_science.ipynb

Wait for the notebook name to auto-populate to spark_data_science.

  1. For Region, select .

  2. Click Upload.

The notebook automatically opens. In the event that it does not open automatically, you can perform the following step to open the notebook.

  1. To open the notebook, in the Explorer pane, click the dropdown arrow named . Then, click the Notebooks, and click the notebook spark_data_science.
Note: To optimize on-screen space, you can collapse the BigQuery navigation menu by clicking the Toggle BigQuery navigation menu button (bottom left of the BigQuery navigation menu) and do the same for the table of contents by clicking the Collapse left pane button (top right of the table of contents).

Connect to a runtime

  1. On the top right of the notebook menu bar, click Connect to connect to a new runtime.

  2. In the pop-up, click Open if prompted and authorize Colab Enterprise to use your lab account, .

Note: This step takes a few minutes to complete. When the runtime is established, at the top of the notebook pane, you should see a green checkmark and new dropdown arrow next to the options for RAM and Disk.

If after five minutes you do not see the green checkmark, you can refresh the notebook page.

Active runtime

Note: Now that you've completed the first task, your notebook is ready for use. From here on, you complete the remaining tasks within the notebook environment. The notebook contains all the code and detailed, cell-by-cell explanations for the entire workflow.

Follow along on this lab page for brief summaries and progress checkpoints to help you track your progress.
  1. On the notebook page, scroll to the Task 2. Configure your notebook environment section to begin your workflow.

Task 2. Configure your notebook environment

In this task, you configure your notebook environment with the necessary tools and items to complete the lab—including configuring Private Google Access, creating a Cloud Storage bucket, and creating a BigQuery dataset.

In the notebook, you are prompted to add the Project ID and Region.

  • For this lab environment, use for the project ID and for the region.
Note: After completing each task in the notebook, return to this page to click the relevant progress checkpoint (that corresponds to the notebook task) to verify your progress.

Click Check my progress to verify the objective. Configure your notebook environment

Task 3. Create a connection to Managed Service for Apache Spark serverless

In this task, you use the serverless Spark Connect client to run interactive Spark jobs.

Note: The first time you run the cell to create the Spark session, you may encounter a service account error. Wait 1 minute and try again.

You may be asked to authenticate. Click the link in the output to do so, and then wait 2 minutes for permissions to propagate before running the cell again. You may need to run the cell multiple times for it to execute successfully, as more time may be needed for the permissions to propagate.

Wait until you see the output message Managed Service for Spark Session was successfully created before proceeding to the next task.

Click Check my progress to verify the objective. Create a connection to Google Cloud Serverless for Apache Spark

Task 4. Load data and explore with Gemini

In this task, you run through the first important step in any data science project: preparing your data. You start by loading data into an Apache Spark dataframe from BigQuery. Then, you use Gemini to generate PySpark code to explore the data.

The dataset is a synthetic dataset of customer information and purchase history, which is available as a BigQuery Public Dataset called thelook_ecommerce.

Test your understanding

After you explore the data in the notebook, answer the following multiple-choice question to reinforce your understanding.

Click Check my progress to verify the objective. Load data and explore with Gemini

Task 5. Perform feature engineering

In this task, you perform feature engineering on the data. Specifically, you select the appropriate columns, transform the data into more suitable data types, and identify a label column.

Click Check my progress to verify the objective. Perform feature engineering

Task 6. Train a logistic regression model

In this task, you use MLlib to train a logistic regression model. First, you use a VectorAssembler to convert the data into a vector format, and then StandardScaler scales the features column for better performance. Next, you create a reference to a LogisticRegression model and define hyperparameters. Last, you combine these steps into a Pipeline object, train the model using the fit() function and transform the data using the transform() function.

Click Check my progress to verify the objective. Train a logistic regression model

Task 7. Conduct model evaluation

In this task, you evaluate your newly transformed dataset and generate the evaluation metric area under curve (AUC). Then, you use Gemini to generate PySpark code to visualize your model output.

Click Check my progress to verify the objective. Conduct model evaluation

Task 8. Write predictions to BigQuery

In this task, you use Gemini to generate code to write your predictions to a new table in your BigQuery dataset.

Click Check my progress to verify the objective. Write predictions to BigQuery

Task 9. Save the model to Cloud Storage

In this task, you use MLlib's native functionality to save your model to Cloud Storage, so that the inference server can load the model from a bucket.

Click Check my progress to verify the objective. Save the model to Cloud Storage

Task 10. Create an inference server

Cloud Run is a flexible tool to run serverless web apps. It uses Docker containers to provide users with maximum customizability.

In this task, you use a Dockerfile that is configured to run a Flask app powering PySpark. This container runs on Cloud Run to perform inference on input data.

For reference, the original source code can be found on GitHub.

Click Check my progress to verify the objective. Create an inference server

Task 11. Configure an agent

Agent Runtime is a part of Gemini Enterprise Agent Platform, a set of services that enable developers to deploy, manage, and scale AI agents in production. It has many tools including evaluating agents, session contexts, and code execution. It supports many popular agentic frameworks, including the Agent Development Kit (ADK). ADK is an open source agentic framework that, while built and optimized for use with Gemini and the Google ecosystem, is model-agnostic. It is designed to make agent development feel more like software development.

In this task, you use Agent Runtime to create an agent that can perform inference.

  • When prompted in the notebook, replace GEMINI_FLASH_MODEL_ID with the model and then run the cell.

Click Check my progress to verify the objective. Configure an agent

Congratulations!

In this lab, you learned how to use BigQuery Studio notebooks to run data science workflows that leverage Google Cloud Serverless for Apache Spark to train and evaluate a classification model. You also deployed an inference server for the model and deployed an agent to query the inference server using natural language with Agent Runtime and the Agent Development Kit (ADK).

Next steps / Learn more

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 November 05, 2026

Lab Last Tested November 11, 2026

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

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We can notify you via email when it becomes available

Great!

We can contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Using an Incognito or private browser window is the best way 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.