Google Professional Machine Learning Engineer Question 514
Single answerGoogle Cloud PlatformYou are tasked with designing a machine learning pipeline on Google Cloud for a recommendation system. The input data consists of user interaction logs, including user IDs, timestamps, and product categories. During feature engineering, you identify that the user ID column has over 10 million unique values. What is the best way to handle this high-cardinality feature in your model to reduce dimensionality while preserving useful information?
- A
One-hot encode the user ID column and pass it to the model directly.
- B
Apply embedding layers to the user ID column to map it to a lower-dimensional space.
- C
Use PCA (Principal Component Analysis) to reduce the dimensionality of the user ID column.
- D
Drop the user ID column entirely to avoid high dimensionality issues.
Show answer and explanation
Correct answer: B
Explanation
In this scenario, the user ID column represents a high-cardinality categorical feature. One-hot encoding would result in an impractically large and sparse representation. Dropping the column would discard important information, and PCA is unsuitable for categorical features. Instead, embedding layers provide an efficient and effective way of reducing dimensionality while retaining valuable insights by mapping each unique ID to a dense vector in a lower-dimensional space.
- A. Incorrect.
One-hot encoding a column with 10 million unique values would create an extremely sparse and high-dimensional matrix, which is computationally expensive and impractical for most models.
- B. Correct.
Applying embedding layers is a common approach for handling high-cardinality categorical features like user IDs. It maps each unique ID to a dense, lower-dimensional vector, preserving relationships and patterns.
- C. Incorrect.
PCA is not suitable for categorical features like user IDs because it is designed for continuous numerical data and works on linear transformations of the input space.
- D. Incorrect.
Dropping the user ID column would result in losing potentially valuable information about user behavior, which is crucial for a recommendation system.