准备工作
- 实验会创建一个 Google Cloud 项目和一些资源,供您使用限定的一段时间
- 实验有时间限制,并且没有暂停功能。如果您中途结束实验,则必须重新开始。
- 在屏幕左上角,点击开始实验即可开始
Create a dataset
/ 25
Load Data to BigQuery Tables
/ 25
Explore and Investigate the Data with BigQuery
/ 10
Prepare Your Data
/ 10
Train an Unsupervised Model to Detect Anomalies
/ 10
Train a Supervised Machine Learning Model
/ 10
Predict Fraudulent Transactions on Test Data
/ 10
Create a dataset
/ 25
Load Data to BigQuery Tables
/ 25
Explore and Investigate the Data with BigQuery
/ 10
Prepare Your Data
/ 10
Train an Unsupervised Model to Detect Anomalies
/ 10
Train a Supervised Machine Learning Model
/ 10
Predict Fraudulent Transactions on Test Data
/ 10
In this lab, you explore financial transactions data for fraud analysis, and apply feature engineering and machine learning techniques to detect fraudulent activities using BigQuery ML.
You use public financial transactions data that contains the following columns:
isFraud flagThe target column isFraud includes the labels for the fraudulent transactions. Using these labels, you train supervised models for fraud detection and apply unsupervised models to detect anomalies.
The data for this lab is from the Kaggle site. If you do not have a Kaggle account, it's free to create one.
In this lab, you learn how to perform the following tasks:
In this lab, you use the BigQuery interface for feature engineering, model development, evaluation, and prediction.
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 right is the Lab setup and access panel with the following:
Note that the lab timer is located near the top of the page, showing the remaining time.
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 setup and access panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab setup and access panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
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.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project 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.
Output:
Output:
gcloud, in Google Cloud, refer to the gcloud CLI overview guide.
unzip command:The command inflates 1 file.
<project_id> with your copied Project ID:finance to store tables and models for this lab:Successful execution of the command produces the following output:
Click Check my progress to verify the objective.
To load your data into BigQuery, you can use either the BigQuery user interface or the terminal in Cloud Shell. Choose one of the following options to load your data.
finance.fraud_data by running the following command:The --autodetect flag reads the schema of the table (such as variable names and types) automatically.
You can load data from your Cloud Storage bucket by opening BigQuery in the Google Cloud console.
fraud_data, and under Schema, select the Auto detect checkbox so that the variable names are read from the first line of the raw file automatically.The loading process takes one or two minutes.
Click Check my progress to verify the objective.
Next, you explore the data in BigQuery to understand it better and prepare it for machine learning models.
If you haven't opened BigQuery in the Google Cloud console yet, click Navigation menu > BigQuery.
In the query Editor, add the following query to check the number of fraudulent transactions for each transaction type, and then click Run:
Look in the isFraud column for 1 (yes).
TRANSFER and CASH_OUT transaction types (the counts of isFraud):Pause and reflect:
isFraud count by the total number of observations, you get the proportion of fraudulent transactions.In the next task, you address these questions and improve the data for machine learning models.
Click Check my progress to verify the objective.
You can improve the modeling data by adding new features, filtering unnecessary transaction types, and increasing the proportion of the target variable isFraud by applying undersampling.
Based on your findings from the analysis phase, you only need to analyze the transaction types "TRANSFER" and "CASH_OUT" and filter the rest. You can also compute new variables from the existing amount values.
The dataset contains an extremely unbalanced target for fraud (fraud rate in the raw data = 0.0013%). Having rare events is common for fraud. To make the pattern of fraudulent behavior more obvious for the machine learning algorithms and make it easier to interpret the results, stratify the data and increase the proportion of the fraudulent flags.
fraud_data_test table by selecting a random sample of 20%:This test data is kept separate and is not included in training. You use it for scoring the model in the final task.
BigQuery ML and AutoML automatically partition the model data into TRAIN and VALIDATE splits while training machine learning algorithms to test the error rate on both the training and validation data and avoid overfitting.
fraud_data_model):The sample data that you created for modeling contains approximately 228,000 rows of banking transactions.
You can also manually partition your dataset into TRAIN, VALIDATE, and TEST splits, especially when you want to compare models from different environments such as Vertex AI and maintain consistency.
Pause and reflect:
Click Check my progress to verify the objective.
Unsupervised methods are commonly used in fraud detection to explore abnormal behavior in the data. They also help when there are no labels for fraud or when the event rate is very low and the number of occurrences does not allow you to build a supervised model.
In this task, you use the k-means clustering algorithm to create segments of transactions, analyze each segment, and detect the segments with anomalies.
CREATE OR REPLACE MODEL and model_type set to kmeans:This statement creates a k-means model named model_unsupervised with 5 clusters using the selected variables from fraud_data_model.
After the model finishes training, it appears under finance > Models.
The k-means algorithm creates an output variable named centroid_id. Each transaction is assigned to a centroid_id. The transactions that are similar or closer to each other are assigned to the same cluster by the algorithm.
The Davies-Bouldin index indicates how homogeneous the clusters are. The lower the value is, the more distant the clusters are from each other, which is the desired outcome.
The numeric features are displayed with bar charts for each centroid (cluster) on the Evaluation tab. The numbers next to the bars show the average value of the variables within each cluster. As a best practice, the input variables can be standardized or grouped into buckets to avoid the impact of large numbers or outliers in the distance calculations for clustering. For simplicity, this lab uses the original variables.
The categorical variables that are used as input are displayed separately, showing the distribution of TRANSFER and CASH_OUT transactions in each segment.
The charts might look different for your model; focus on the smaller segments and interpret the distributions.
The target variable isFraud hasn't been used in this unsupervised model. Instead, you can save that variable for profiling and use it to explore the distribution of fraudulent activities within each cluster.
The clustering algorithms create homogeneous groups of observations. You can score the test data (fraud_data_test) using ML.PREDICT to call the model and generate the centroid_id for each transaction in the test data.
centroid_id:Pause and reflect:
Click Check my progress to verify the objective.
Now you are ready to build supervised models using BigQuery ML to predict the likelihood of fraudulent transactions. Start with a simple model by using BigQuery ML to create a binary logistic regression model for classification. This model predicts whether a transaction is likely to be fraudulent.
For all non-numeric (categorical) variables, BigQuery ML automatically performs a one-hot encoding transformation. This transformation generates a separate feature for each unique value in the variable. In this task, BigQuery ML performs one-hot encoding for the type variable automatically.
When it is ready, model_supervised_initial appears under finance > Models.
After the model is created, you can view the model metadata, training, and evaluation statistics in the BigQuery console.
On the Evaluation tab, you find performance metrics specific to the classification model.
Understanding the performance of the model is a key topic in machine learning. Because you performed a logistic regression for classification, the following key concepts are useful to understand:
The Precision and recall page on Wikipedia illustrates the concepts of precision and recall.
The ROC AUC value for this regression model is very high. You can get a better understanding of the accuracy by testing the outcomes for different probability thresholds.
Now, inspect the most influential features in the model.
The weights are standardized to eliminate the impact of the scale of the variables using the standardize option. Larger weights indicate more important features. The sign of the weight indicates the direction, depending on the direct or inverse relationship with the target.
Pause and reflect:
oldbalanceOrig and type are the most important variables.Click Check my progress to verify the objective.
Now create a second supervised model to compare accuracy.
Next, you compare the two models you created and choose the best one.
After creating the models, you can evaluate the performance of each classifier using the ML.EVALUATE function. The ML.EVALUATE function evaluates the predicted values against actual data.
Pause and reflect:
model_supervised_initial), and then you trained a boosted tree model (model_supervised_boosted_tree) as the second supervised model. The boosted tree model performs better when you compare the performance metrics in finance.table_perf.The last step in machine learning is to use a trained model to predict outcomes on new datasets.
The machine learning algorithms in BigQuery ML create a nested variable named predicted_<target_name>_probs. This variable includes the probability scores for the model decision (either fraudulent or genuine).
WHERE clause filters for transactions with a fraud probability score greater than 0.5):Pause and reflect:
Click Check my progress to verify the objective.
...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 on November 06, 2026
Lab Last Tested November 05, 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.
此内容目前不可用
一旦可用,我们会通过邮件告知您
太好了!
一旦可用,我们会通过邮件联系您
一次一个实验
确认结束所有现有实验并开始此实验