Customer Segmentation with BigQuery ML K-Means

PMLE By islever Editorial Last updated

Building AI solutions using Google Cloud AI APIs or foundational models. Building models given the task considering cost, complexity, latency, and scalability.

Short answer

A Use k-means clustering in BigQuery ML to automatically optimize cluster count for efficient customer segmentation.

Question

You work for a large retailer and have been asked to segment your customers by their purchasing habits. The purchase history of all customers has been uploaded to BigQuery. You suspect that there may be several distinct customer segments, however you are unsure of how many, and you don’t yet understand the commonalities in their behavior. You want to find the most efficient solution. What should you do?
  1. Create a k-means clustering model using BigQuery ML. Allow BigQuery to automatically optimize the number of clusters. Correct Answer
  2. Create a new dataset in Dataprep that references your BigQuery table. Use Dataprep to identify similarities within each column.
  3. Use the Data Labeling Service to label each customer record in BigQuery. Train a model on your labeled data using AutoML Tables. Review the evaluation metrics to understand whether there is an underlying pattern in the data.
  4. Get a list of the customer segments from your company’s Marketing team. Use the Data Labeling Service to label each customer record in BigQuery according to the list. Analyze the distribution of labels in your dataset using Data Studio.

Key Takeaways

K-means clustering in BigQuery ML automatically determines the optimal number of clusters when the parameter is unspecified, solving the problem of unknown segment counts.

Learn how to efficiently segment customers with unknown group counts using BigQuery ML's automatic k-means clustering capabilities.

Common mistake: Choosing AutoML Tables (C or D) because it sounds like a powerful AI tool; however, it requires labeled data, which is unavailable in this unsupervised segmentation scenario.

Expert Analysis

The scenario describes a classic unsupervised learning problem: customer segmentation where the number of segments (clusters) is unknown and no labeled data exists. The goal is to find distinct groups based on purchasing habits stored in BigQuery.

Option A leverages BigQuery ML (BQML), which allows users to create machine learning models directly using standard SQL queries without moving data out of BigQuery. K-means clustering is the appropriate algorithm for grouping similar data points. Crucially, BQML's CREATE MODEL statement for k-means allows the system to automatically determine the optimal number of clusters if the num_clusters parameter is omitted or set to auto-optimize. This aligns perfectly with the requirement for the 'most efficient solution' given the uncertainty about the number of segments.

Option B suggests using Dataprep. While Dataprep helps with data preparation and visualization, it does not inherently perform automated clustering to define customer segments in an ML pipeline context as efficiently as BQML does for this specific use case. It is more of a data cleaning tool.

Options C and D both involve the Data Labeling Service and AutoML Tables. These are supervised learning tools that require pre-labeled training data. Since the prompt explicitly states you do not understand the commonalities and don't know the segments, labeling data would be impossible or highly inefficient, making these options incorrect.

Official Reference

https://cloud.google.com/bigquery/docs/kmeans-tutorial

This link opens the official vendor documentation in a new tab.

Exam Strategy

When facing segmentation problems with unknown group counts, immediately identify unsupervised learning requirements. Prioritize native cloud services like BigQuery ML over external labeling or manual preprocessing tools, as they offer scalability and automation features like automatic hyperparameter tuning or cluster optimization built into SQL commands.

Frequently Asked Questions

Why not use AutoML Tables for customer segmentation?

AutoML Tables is designed for supervised learning tasks like classification and regression, which require labeled training data. Customer segmentation is typically unsupervised, meaning labels are not predefined.

How does BigQuery ML handle the number of clusters in K-means?

If you do not specify the num_clusters option in the CREATE MODEL statement, BigQuery ML automatically selects a reasonable default value based on the total number of rows in the training dataset.

More PMLE FAQ →

Community Votes

A
90%
B
10%

90% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 14 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 14

  1. CloudKida 👍 5 Answered A
    when to use k-means : Your data may contain natural groupings or clusters of data. You may want to identify these groupings descriptively in order to make data-driven decisions. For example, a retailer may want to identify natural groupings of customers who have similar purchasing habits or locations. This process is known as customer segmentation. https://cloud.google.com/bigquery/docs/kmeans-tutorial
  2. wish0035 👍 4 Answered A
    ans: A, pretty sure. C, D => discarded, very time consuming. B => yes, you can identify similarities within each column, but when i read "you don’t yet understand the commonalities in their behavior" i understand that this job would be difficult, because there could be many columns to analyze, and i don't think that this would be efficient. A => BigQuery ML is compatible with kmeans clustering, it's easy and efficient to create, and i would automatically detect the number of clusters. Also from the BigQuery ML docs: "K-means clustering for data segmentation; for example, identifying customer segments." (Source: https://cloud.google.com/bigquery-ml/docs/introduction#supported_models_in)
  3. LearnSodas 👍 4 Answered A
    K-means is a good unsupervised learning algorithm to segment a population based on similarity We can usa K-means directly in BQ, so I think it's "the most efficient way" Labeling is not a good option since we don't really know what make a customer similar to another, and why dataprep if we can use directly BQ?
  4. Vedjha 👍 4
    Will go for 'A' as it is easy to build model in BQML where data is already present and optimization would be auto in case of K-mean algo
  5. M25 👍 4 Answered A
    Went with A
Show 9 more comments
  1. tavva_prudhvi 👍 3
    A This is the most efficient solution for segmenting customers based on their purchasing habits, as it utilizes BigQuery's built-in machine learning capabilities to identify distinct clusters of customers based on their purchasing behavior. By allowing BigQuery to automatically optimize the number of clusters, you can ensure that the model identifies the most appropriate number of segments based on the data, without having to manually select the number of clusters.
  2. hiromi 👍 3 Answered A
    A https://cloud.google.com/bigquery-ml/docs/kmeans-tutorial https://towardsdatascience.com/how-to-use-k-means-clustering-in-bigquery-ml-to-understand-and-describe-your-data-better-c972c6f5733b
  3. MultiCloudIronMan 👍 3 Answered A
    K-means algorithm is used for grouping/clustering data in unsupervised learning experiments.
  4. PhilipKoku 👍 3 Answered A
    A) K-means is ideal for unsupervised clustering
  5. ares81 👍 2 Answered A
    I correct myself. It's A: According to the documentation, if you omit the num_clusters option, BigQuery ML will choose a reasonable default based on the total number of rows in the training data.
  6. taylz876 👍 1 Answered A
    The clues are that you have no labels (you don't know the segments), you're unsure how many groups there are, the data is already in BigQuery, and you want the most efficient solution. That's unsupervised clustering. K-means in BigQuery ML runs with a SQL statement, directly where the data lives. If you don't set the number of clusters, BigQuery picks a good number for you.
  7. japoji 👍 1
    The question is about commonalities of clients by characteristics, no about characteristics by client. I mean with B you are looking for segments of the characteristics which define a client. But you need segments of clients defined by characteristics.
  8. neochaotic 👍 1 Answered B
    Its B! Dataprep provides Data profiling functionalities
  9. ares81 👍 1
    It seems B, to me.

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Practice All PMLE Questions

Access 65 questions with complete answers and detailed explanations.

View Full PMLE Practice Test →

← Back to PMLE Study Guide