![](https://cdn.qwiklabs.com/assets/labs/start_lab-f45aca49782d4033c3ff688160387ac98c66941d.png)
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
Calculate trips taken by Yellow taxi in each month of 2015
/ 10
Calculate average speed of Yellow taxi trips in 2015
/ 10
Test whether fields are good inputs to your fare forecasting model
/ 20
Create a BigQuery dataset to store models
/ 10
Create a taxifare model
/ 20
Evaluate classification model performance
/ 10
Predict taxi fare amount
/ 20
BigQuery is Google's fully managed, NoOps, low cost analytics database. With BigQuery you can query terabytes and terabytes of data without having any infrastructure to manage, or needing a database administrator.
BigQuery ML provides data analysts the ability to create, train, evaluate, and predict with machine learning models with minimal coding.
In this lab, you work with millions of New York City yellow taxi cab trips available in a BigQuery Public Dataset. You use this data to create a machine learning model inside of BigQuery to predict the fare of the cab ride given your model inputs and evaluate the performance of your model and make predictions with it.
In this lab, you learn to perform the following tasks:
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:
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 left is the Lab Details pane with the following:
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.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
The Welcome to BigQuery in the Cloud Console message box opens. This message box provides a link to the quickstart guide and the release notes.
The BigQuery console opens.
Question: How many trips did Yellow taxis take each month in 2015?
You should receive the following result:
As we see, every month in 2015 had over 10 million NYC taxi trips—no small amount!
Click Check my progress to verify your performed task. If you have completed the task successfully, you will be granted with an assessment score.
Question: What was the average speed of Yellow taxi trips in 2015?
You should receive the following result:
During the day, the average speed is around 11-12 MPH; but at 5:00 AM the average speed almost doubles to 21 MPH. Intuitively this makes sense since there is likely less traffic on the road at 5:00 AM.
Click Check my progress to verify your performed task. If you have completed the task successfully, you will be granted with an assessment score.
You will now create a machine learning model in BigQuery to predict the price of a cab ride in New York City given the historical dataset of trips and trip data. Predicting the fare before the ride could be very useful for trip planning for both the rider and the taxi agency.
The New York City Yellow Cab dataset is a public dataset provided by the city and has been loaded into BigQuery for your exploration.
Browse the complete list of fields and then preview the dataset to find useful features that will help a machine learning model understand the relationship between data about historical cab rides and the price of the fare.
Your team decides to test whether these below fields are good inputs to your fare forecasting model:
Note a few things about the query:
SELECT * from taxitrips
).taxitrips
does the bulk of the extraction for the NYC dataset, with the SELECT
containing your training features and label.WHERE
removes data that you don't want to train on.WHERE
also includes a sampling clause to pick up only 1/1000th of the data.TRAIN
so that you can quickly build an independent EVAL
set.You should receive a similar result:
What is the label (correct answer)?
total_fare
is the label (what you will be predicting). You created this field out of tolls_amount
and fare_amount
, so you could ignore customer tips as part of the model as they are discretionary.
Click Check my progress to verify your performed task. If you have completed the task successfully, you will be granted with an assessment score.
In this section, you will create a new BigQuery dataset which will store your ML models.
In the left-hand Explorer panel, click on the View actions icon next to your Project ID and then click Create dataset.
In the Create Dataset dialog, enter in the following:
Click Check my progress to verify your performed task. If you have completed the task successfully, you will be granted with an assessment score.
Now that you have your initial features selected, you are now ready to create your first ML model in BigQuery.
There are several model types to choose from:
Next, click Run to train your model.
Wait for the model to train (5 - 10 minutes).
After your model is trained, you will see the message "This statement will create a new model named qwiklabs-gcp-03-xxxxxxxx:taxi.taxifare_model." which indicates that your model has been successfully trained.
Next, you will evaluate the performance of the model against new unseen evaluation data.
Click Check my progress to verify your performed task. If you have completed the task successfully, you will be granted with an assessment score.
For linear regression models you want to use a loss metric like Root Mean Square Error (RMSE). You want to keep training and improving the model until it has the lowest RMSE.
In BQML, mean_squared_error
is a queryable field when evaluating your trained ML model. Add a SQRT()
to get RMSE.
Now that training is complete, you can evaluate how well the model performs with this query using ML.EVALUATE
.
You are now evaluating the model against a different set of taxi cab trips with your params.EVAL
filter.
Row |
rmse |
1 |
9.477056435999074 |
After evaluating your model you get a RMSE of 9.47. Since we took the Root of the Mean Squared Error (RMSE) the 9.47 error can be evaluated in the same units as the total_fare so it's +-$9.47.
Knowing whether or not this loss metric is acceptable to productionalize your model is entirely dependent on your benchmark criteria, which is set before model training begins. Benchmarking is establishing a minimum level of model performance and accuracy that is acceptable.
Click Check my progress to verify your performed task. If you have completed the task successfully, you will be granted with an assessment score.
Next, write a query to use your new model to make predictions.
Now you will see the model's predictions for taxi fares alongside the actual fares and other features for those rides. Your results should look similar to those below:
Click Check my progress to verify your performed task. If you have completed the task successfully, you will be granted with an assessment score.
Building Machine Learning models is an iterative process. Once we have evaluated the performance of our initial model, we often go back and prune our features and rows to see if we can get an even better model.
Now view the common statistics for taxi cab fares.
You should receive a similar output:
As you can see, there are some strange outliers in our dataset (negative fares or fares over $50,000). Apply some of our subject matter expertise to help the model avoid learning on strange outliers.
Limit the data to only fares between $$6 and $$200.
You should receive a similar output:
That's a little bit better. While you're at it, limit the distance traveled so you're really focusing on New York City.
You should receive a similar output:
You still have a large training dataset of over 800 million rides for our new model to learn from. Re-train the model with these new constraints and see how well it performs.
Call the new model taxi.taxifare_model_2
and retrain the linear regression model to predict total fare. You'll note that you've also added a few calculated features for the Euclidean distance (straight line) between the pick up and drop off.
It may take a couple minutes to retrain the model. You can move onto the next step when you receive the following message in the Console:
Now that the linear regression model has been optimized, evaluate the dataset with it and see how it performs.
You should receive a similar output:
As you see, you've gotten the RMSE down to: +-$$5.12 which is significantly better than +-$$9.47 for your first model.
Since RMSE defines the standard deviation of prediction errors, we see that the retrained linear regression made our model a lot more accurate.
Below are multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.
You can use the bigquery-public-data project if you want to explore modeling on other datasets like forecasting fares for Chicago taxi trips.
To open the bigquery-public-data dataset, click +Add > Star a project by name > Enter Project Name, then write the bigquery-public-data
name.
Click Star.
The bigquery-public-data
project is listed in the Explorer section.
You've successfully built a machine learning model in BigQuery to forecast taxi cab fare for New York City cabs.
...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 February 07, 2024
Lab Last Tested August 24, 2023
Copyright 2025 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.
Questi contenuti non sono al momento disponibili
Ti invieremo una notifica via email quando sarà disponibile
Bene.
Ti contatteremo via email non appena sarà disponibile
One lab at a time
Confirm to end all existing labs and start this one