arrow_back

Building a Forecasting Pipeline Using Vertex AI Python SDKs

Sign in Join
Get access to 700+ labs and courses

Building a Forecasting Pipeline Using Vertex AI Python SDKs

Lab 3 hours universal_currency_alt 5 Credits show_chart Advanced
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

Overview

In this lab, you use Python SDKs to build a forecasting pipeline, where you can train a Vertex AI AutoML Forecasting model and then use that model to make batch predictions.

This lab takes about 3 hours including the model training for 2 hours and the batch prediction for 30 min. It's an optional lab associated with the course titled Vertex Forecasting and Time Series in Practice. If you don't have sufficient time to complete the lab, you're recommended to browse the coding (Vertex_AI_Forecasting.ipynb) to get the sense of using SDKs to create a forecasting pipeline.

What you learn

In this lab, you learn how to:

  • Create a Vertex AI Workbench notebook instance.
  • Create a managed dataset using the Vertex AI Python SDK.
  • Train a forecasting model using the Vertex AI Python SDK.
  • Make batch predictions using the Vertex AI Python SDK.

Setup and requirements

Before you click the Start Lab button

Note: 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 Qwiklabs 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.

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab. Note: If you are using a Pixelbook, open an Incognito window to run this lab.

How to start your lab and sign in to the Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.

  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Choose an account page.

    Note: Open the tabs in separate windows, side-by-side.
  3. On the Choose an account page, click Use Another Account. The Sign in page opens.

  4. Paste the username that you copied from the Connection Details panel. Then copy and paste the password.

Note: You must use the credentials from the Connection Details panel. Do not use your Google Cloud Skills Boost credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).
  1. 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 Cloud console opens in this tab.

Note: You can view the menu with a list of Google Cloud Products and Services by clicking the Navigation menu at the top-left.

Task 1. Deploy a Vertex AI notebook instance

In this task, you create the Vertex AI Workbench JupyterLab (iPython) notebook that is used for the rest of the lab.

  1. In the Google Cloud Console, navigate to Vertex AI > Dashboard and click the dropdown Show API list and click Enable on the Vertex AI API tile.

  2. In the Cloud Console, navigate to Vertex AI > Workbench and click the Enable Notebooks API button.

  3. On the Workbench menu bar, click +New Notebook.

  4. In the Customize... pop-up menu, select Python3.

  5. In the New notebook instance dialog for Notebook Name enter vertex-ai.

  6. For Region, select us-central1.

  7. Leave all other fields with their default options and click Create.

After a few minutes, the Vertex AI console displays your instance name, followed by Open JupyterLab. The UI might not automatically refresh so you may need to refresh the page to see the link.

  1. Click Open JupyterLab.

Once you get into it, you find a screen like this.

Task 2. Create a Vertex AI Forecasting Model using the Python SDK

In this task, you create a Vertex AI Forecasting Model using the Python SDK in a JupyterLab notebook.

  1. In the JupyterLab tab, in the Other launcher section, click Terminal to open a new Terminal window.

  2. In the Terminal console shell, paste the following command to copy the JupyterLab notebook for the lab into your JupyterLab instance:

gsutil cp gs://cloud-training/CBL458/setup/Vertex_AI_Forecasting.ipynb Vertex_AI_Forecasting.ipynb
  1. Double-click the filename Vertex_AI_Forecasting.ipynb in the file list to open your lab notebook.

  2. Follow the instructions in the Notebook to prepare the dataset and start training your model.

The model will take approximately 2 hours to train completely. Once the training job reports that it has started, you can return here for instructions on how to load and explore example batch prediction result data so that you can see what the output data looks like and use the code supplied to display the prediction data using Looker Studio.

Task 3. Explore pre-prepared prediction result data

This step guides you through the process of accessing sample batch prediction result data and using a JupyterLab notebook and Looker Studio to visualize the predictions.

  1. Switch to the Terminal console shell in your notebook instance and paste the following command to copy a JupyterLab notebook to analyze the example data into your JupyterLab instance:
gsutil cp gs://cloud-training/CBL458/setup/Results.ipynb Results.ipynb
  1. Paste the following commands into the Terminal console shell to create the example BigQuery dataset and import the tables containing example prediction result data:
bq --location=us mk --dataset $PROJECT_ID:iowa_liquor_sales_predictions_example bq --location=us load --source_format=AVRO \ iowa_liquor_sales_predictions_example.errors_example \ gs://cloud-training/CBL458/setup/batch_prediction_error_example.avro bq --location=us load --source_format=AVRO \ iowa_liquor_sales_predictions_example.predictions_example \ gs://cloud-training/CBL458/setup/batch_prediction_example.avro
  1. Open the JupyterLab notebook file called Results.ipynb and run all the cells to generate a clickable link that will display the data in Looker Studio.

  2. Click the link that is displayed to open the Looker Studio report that will display a chart showing the prediction data.

You can now also explore the BigQuery example batch prediction output data in the iowa_liquor_sales_predictions_example.errors_example and iowa_liquor_sales_predictions_example.predictions_example BigQuery tables if you want to see what the output data and schemata look like.

Task 4. Perform batch predictions using the SDK (optional)

  • If you want to wait for the model to complete, you can return to the original notebook and wait until the job.run cell in the Train the Vertex AI AutoML Forecasting model section has finished.

  • You can monitor progress there or via the Vertex AI console under the Vertex AI > Training page. Remember that the Vertex AI AutoML Forecasting training task takes approximately 2 hours to complete.

  • Once the model is trained, you can then run the remaining cells to display the model evaluation metrics, and perform a batch prediction. Your final output data should be similar to the example data you viewed in the last task.

Congratulations!

You have successfully used the Python SDK to build and train a Vertex AI AutoML Forecasting model and then used that model to make batch predictions.

You are now ready to create models and run batch predictions with Vertex AI AutoML Forecasting with the Python SDK!

End your lab

When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.

You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.

The number of stars indicates the following:

  • 1 star = Very dissatisfied
  • 2 stars = Dissatisfied
  • 3 stars = Neutral
  • 4 stars = Satisfied
  • 5 stars = Very satisfied

You can close the dialog box if you don't want to provide feedback.

For feedback, suggestions, or corrections, please use the Support tab.

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.

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

This content is not currently available

We will notify you via email when it becomes available

Great!

We will 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

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.