
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
BigQuery Machine Learning (BigQuery ML) enables users to create and execute machine learning models in BigQuery using SQL queries. The goal is to democratise machine learning by enabling SQL practitioners to build models using their existing tools and to increase development speed by eliminating the need for data movement.
There is an ecommerce dataset that has millions of Google Analytics records for the Google Merchandise Store loaded into BigQuery. In this lab you will use this data to create a model that predicts whether a visitor will make a transaction.
How to create, evaluate and use machine learning models in BigQuery
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
The Welcome to BigQuery in the Cloud Console message box opens. This message box provides a link to the quickstart guide and lists UI updates.
The Create dataset dialog opens.
bqml_lab
for Dataset ID, and click on CREATE DATASET (accepting the other default values).The data we will use in this lab sits in the bigquery-public-data project, that is available to all. Let's take a look at a sample of this data.
The data tables have a lot of columns, but there are few of interest to us that we will use to create our ML model. Here the visitor's device's operating system is used, whether said device is a mobile device, the visitor's country or region and the number of page views will be used as the criteria for whether a transaction has been made. In this case, label
is what you're trying to fit to (or predict).
This data will be the training data for the ML model you create. The training data is being limited to those collected from 1 August 2016 to 31 June 2017. This is done to save the last month of data for "prediction". It is further limited to 10,000 data points to save some time.
bqml_lab
and type training_data
as the Table Name and click Save.In this case, bqml_lab
is the name of the dataset, sample_model
is the name of the model, training_data
is the transactions data we looked at in the previous task. The model type specified is binary logistic regression.
Running the CREATE MODEL
command creates a Query Job that will run asynchronously so you can, for example, close or refresh the BigQuery UI window.
If interested, you can get information about the model by clicking on bqml_lab
dataset on the left-hand menu and then click the sample_model
dataset in the UI. Under Details, you should find some basic model info and training options used to produce the model. Under Training, you should see a table similar to this:
In this query, you use the ml.EVALUATE
function to evaluate the predicted values against the actual data, and it shares some metrics of how the model performed. You should see a table similar to this:
You'll realize the SELECT
and FROM
portions of the query is similar to that used to generate training data. There is the additional fullVisitorId column which you will use for predicting transactions by individual user.The WHERE
portion reflects the change in time frame (July 1 to August 1 2017).
Let's save this July data so we can use it in the next 2 steps to make predictions using our model. Click on the Save and then select Save view from the dropdown to save this query as a view. In the popup, select Dataset as bqml_lab
and type july_data
as the Table Name and click Save.
Predict purchases per country/region
With this query you will try to predict the number of transactions made by visitors of each country or region, sort the results, and select the top 10 by purchases:
In this query, you're using ml.PREDICT
and the BigQuery ML portion of the query is wrapped with standard SQL commands. For this lab you''re interested in the country and the sum of purchases for each country, so that's why SELECT
, GROUP BY
and ORDER BY
. LIMIT
is used to ensure you only get the top 10 results.
You should see a table similar to this:
Here is another example. This time you will try to predict the number of transactions each visitor makes, sort the results, and select the top 10 visitors by transactions:
You should see a table similar to this:
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:
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.
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