1.2.4

Question Answer & Explanation
### Question 1 - Feature Engineering for Linear Models

A machine learning team is preparing a dataset for a linear regression model in Amazon SageMaker. The dataset contains numerical features with vastly different scales (e.g., annual income in the tens of thousands and age in the tens). To ensure that gradient descent converges efficiently, the team needs to transform the features so they are centered with a mean of 0 and a standard deviation of 1.

Which feature engineering technique should the team apply using SageMaker Data Wrangler to meet this requirement?

- A) Apply Min-Max Normalization.
- B) Apply Standardization (Z-score scaling).
- C) Apply Robust Scaling.
- D) Apply Log Transformation.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
Standardization (or Z-score scaling) transforms the data so that it has a mean of 0 and a standard deviation of 1. This is crucial for linear models that use gradient descent, as it ensures the optimization landscape is spherical, allowing the algorithm to converge faster and more reliably.

Distractor Analysis:
- A is Incorrect: Min-Max Normalization scales the data to a fixed range, typically [0, 1], but does not center the mean at 0 or guarantee a standard deviation of 1.
- C is Incorrect: Robust scaling uses the median and interquartile range (IQR) instead of the mean and standard deviation, making it better for datasets with extreme outliers, but it does not result in a mean of 0 and standard deviation of 1.
- D is Incorrect: Log transformation is used to reduce the skewness of a distribution, not to center the data at a mean of 0 with a standard deviation of 1.

> Key Takeaway: Standardization (Z-score scaling) is the preferred feature engineering technique for linear models requiring normally distributed data centered at zero with unit variance.
### Question 2 - Handling Highly Skewed Data

An e-commerce company is building a model to predict customer lifetime value. The dataset contains a purchase_amount feature that is heavily right-skewed due to a small number of customers making extremely large purchases. The ML engineering team needs to compress the distribution of this feature to make it more symmetric before feeding it into a tree-based model. They are processing the data using AWS Glue DataBrew.

Which transformation should the team apply to handle the skewed data?

- A) Apply Binning to the purchase_amount column.
- B) Apply Log Transformation to the purchase_amount column.
- C) Apply Standardization to the purchase_amount column.
- D) Apply Feature Splitting to the purchase_amount column.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
A log transformation is specifically designed to handle highly right-skewed (positive skew) data. By applying a logarithmic function, the large extreme values are pulled closer to the rest of the data, resulting in a more symmetric, normal-like distribution which many machine learning algorithms process more effectively.

Distractor Analysis:
- A is Incorrect: Binning converts continuous variables into categorical bins, which results in a loss of granular information that a tree-based model could otherwise utilize.
- C is Incorrect: Standardization scales the data around the mean but does not fundamentally change the shape (skewness) of the distribution.
- D is Incorrect: Feature splitting is used to break down compound fields (e.g., extracting a domain from an email address), not for adjusting numerical distributions.

> Key Takeaway: Log transformation is the standard technique for normalizing right-skewed continuous data by compressing the range of large numbers.
### Question 3 - Categorical Grouping of Continuous Variables

A marketing analytics team wants to group customer ages into distinct, manageable categories (e.g., 18-25, 26-35, 36-45) for a categorical targeting model, rather than using the raw continuous age values. They want to achieve this using a low-code visual interface in Amazon SageMaker Canvas (Data Wrangler).

Which feature engineering technique accomplishes this goal with the least operational overhead?

- A) Apply Standardization to the age column.
- B) Apply Binning (Discretization) to the age column.
- C) Apply Min-Max Normalization to the age column.
- D) Apply Log Transformation to the age column.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
Binning (or discretization) is the process of converting a continuous variable into a categorical variable by grouping the values into distinct intervals or "bins." This matches the business requirement of grouping customer ages into specific ranges for categorical analysis.

Distractor Analysis:
- A is Incorrect: Standardization scales the continuous age values to have a mean of 0 and standard deviation of 1; it does not convert them into categorical bins.
- C is Incorrect: Normalization scales the values to a specific range (e.g., 0 to 1) but keeps the data continuous.
- D is Incorrect: Log transformation alters the scale of the data to handle skewness but does not group values into distinct categories.

> Key Takeaway: Binning is used to transform continuous numerical features into categorical groups, which can simplify the model and capture non-linear relationships.
### Question 4 - Extracting Date Components

A logistics company has a delivery_timestamp column (formatted as "2023-10-26 14:30:00") in their Amazon S3 dataset. To improve a delivery time prediction model, the ML team needs to extract the day of the week and hour of the day as separate features. They want to use a visual data preparation tool that minimizes custom coding.

Which AWS service and feature engineering technique should be used to fulfill this requirement?

- A) Use a custom AWS Lambda function to process each record and extract date parts.
- B) Apply a Feature Splitting transform in AWS Glue DataBrew to extract the date components.
- C) Use Amazon SageMaker Feature Store to automatically infer and extract date parts.
- D) Use Amazon Macie to detect and parse the timestamp structure.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
AWS Glue DataBrew provides built-in visual transformations for dates and timestamps, allowing users to easily extract components like year, month, day, hour, or day of the week without writing custom code. This satisfies the requirement for low operational overhead.

Distractor Analysis:
- A is Incorrect: Writing a custom AWS Lambda function introduces unnecessary operational overhead and requires custom code maintenance compared to a native DataBrew transform.
- C is Incorrect: SageMaker Feature Store is used to store and serve already-engineered features, not to perform the extraction/feature engineering itself.
- D is Incorrect: Amazon Macie is a security service for discovering sensitive data (PII) in S3, not a feature engineering tool.

> Key Takeaway: AWS Glue DataBrew offers native, visual feature engineering transforms like splitting and extracting date components, minimizing code overhead.
### Question 5 - Neural Network Input Requirements

An ML team is developing a deep learning neural network in Amazon SageMaker. The network's activation functions require that all input numerical features are strictly bounded within the range of 0 to 1 to prevent exploding gradients. The data is currently unbounded and being processed interactively in SageMaker Data Wrangler.

Which transformation must be applied to the features?

- A) Apply Standardization (Z-score scaling).
- B) Apply Min-Max Normalization.
- C) Apply Robust Scaling.
- D) Apply Log Transformation.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
Min-Max Normalization scales the data to a fixed range, typically [0, 1]. This perfectly meets the constraint of strictly bounding the input features between 0 and 1 for the neural network's activation functions.

Distractor Analysis:
- A is Incorrect: Standardization produces a distribution with a mean of 0 and a standard deviation of 1, meaning the values can be negative and unbounded.
- C is Incorrect: Robust scaling uses the median and IQR, producing values that are not bounded between 0 and 1.
- D is Incorrect: Log transformation compresses the range of skewed data but does not guarantee a fixed [0, 1] boundary.

> Key Takeaway: Min-Max Normalization is the correct scaling technique when an algorithm requires features to be strictly bounded within a specific range, such as [0, 1].
### Question 6 - Preventing Training-Serving Skew in Scaling

An ML engineer has successfully trained a model using a StandardScaler fitted on the training dataset. The engineer is now deploying the model to a SageMaker real-time endpoint for inference. Compliance rules require that the feature distribution seen by the model during inference matches the training distribution exactly.

How should the engineer apply the scaling transformation to the real-time inference data to meet this requirement?

- A) Refit the StandardScaler on a batch of incoming real-time inference data to adapt to current trends.
- B) Apply the StandardScaler parameters (mean and variance) learned during training to the inference data.
- C) Recalculate the scaling parameters using a daily AWS Glue job and push them to the endpoint.
- D) Apply Min-Max Normalization locally on the incoming request payload before sending it to the model.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
To prevent training-serving skew, the exact same transformation parameters (e.g., mean and standard deviation for StandardScaler) that were learned (fitted) on the training data must be applied (transformed) to the inference data. If the scaler is refit on new data, the mapping of input values changes, leading to inaccurate predictions.

Distractor Analysis:
- A is Incorrect: Refitting the scaler on inference data recalculates the mean and variance based on the new data, meaning the same input value will map to a different scaled value than it did during training.
- C is Incorrect: Recalculating parameters daily also changes the mapping over time and introduces skew.
- D is Incorrect: Switching to Min-Max Normalization for inference when Standardization was used for training will completely break the model's expected input distribution.

> Key Takeaway: A scaling transform fitted on training data must be applied, not refitted, on data seen during inference to prevent training-serving skew.
### Question 7 - Sequential Feature Engineering

A financial dataset contains a transaction_value feature that is highly right-skewed. For an upcoming linear regression model, the data must first be made symmetric, and then scaled to have a mean of 0 and a standard deviation of 1. The data is being prepared in Amazon SageMaker Data Wrangler.

Which sequence of feature engineering steps should the ML engineer apply?

- A) Apply Standardization, then Log Transformation.
- B) Apply Log Transformation, then Standardization.
- C) Apply Min-Max Normalization, then Binning.
- D) Apply Binning, then Log Transformation.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
The correct sequence is to first correct the skewness of the distribution using a Log Transformation, and then apply Standardization to the now-symmetric distribution to center it at a mean of 0 and a standard deviation of 1. Applying standardization to highly skewed data first can result in poorly scaled values due to the skewed mean.

Distractor Analysis:
- A is Incorrect: You cannot apply a log transformation after standardization because standardization creates negative values, and the logarithm of a negative number is undefined.
- C is Incorrect: Normalization and binning do not address the requirement for a mean of 0 and standard deviation of 1.
- D is Incorrect: Binning converts continuous data to categorical data, at which point a log transformation is meaningless.

> Key Takeaway: When a dataset is both skewed and needs to be standardized, apply the log transformation first to handle the skewness, then apply the standard scaling.
### Question 8 - Robust Scaling for Outlier-Heavy Data

An industrial IoT team is processing sensor data in AWS Glue DataBrew. The dataset contains a temperature_reading feature that occasionally records extreme, erroneous spikes (outliers) due to sensor malfunctions. These outliers are severely distorting the mean and standard deviation of the dataset. The team needs a scaling method that is resilient to these outliers for a regression model.

Which feature engineering technique should the team use?

- A) Apply Standardization (Z-score scaling).
- B) Apply Min-Max Normalization.
- C) Apply Robust Scaling.
- D) Apply Feature Splitting.
Correct Answer & Explanation
Correct Answer: C

Correct Answer Analysis:
Robust Scaling uses the median and the interquartile range (IQR) to scale the data. Because the median and IQR are not heavily influenced by extreme outliers (unlike the mean and standard deviation), this method is highly effective for datasets containing severe outliers.

Distractor Analysis:
- A is Incorrect: Standardization relies on the mean and standard deviation, both of which are highly sensitive to extreme outliers.
- B is Incorrect: Min-Max Normalization scales data based on the minimum and maximum values. Extreme outliers will stretch the scale, compressing all normal data into a tiny range.
- D is Incorrect: Feature splitting is for breaking down compound strings, not for handling numerical outliers.

> Key Takeaway: Robust Scaling (using median and IQR) is the best feature engineering technique for datasets where extreme outliers would distort standard mean-based scaling.
### Question 9 - Managing Engineered Features Consistently

A retail company wants to ensure that engineered features (such as scaled purchase amounts and binned age groups) are consistently available for both batch training workflows and low-latency real-time inference. The goal is to strictly minimize the risk of training-serving skew while reducing the operational overhead of managing these features.

Which AWS service is specifically designed to store and serve these engineered features?

- A) Amazon S3 with versioning enabled.
- B) Amazon DynamoDB with global tables.
- C) Amazon SageMaker Feature Store.
- D) Amazon Redshift.
Correct Answer & Explanation
Correct Answer: C

Correct Answer Analysis:
Amazon SageMaker Feature Store is explicitly designed to create, store, and manage engineered features. It provides both an offline store (for batch training) and an online store (for low-latency real-time inference), ensuring that the exact same feature definition is used in both environments, which eliminates training-serving skew.

Distractor Analysis:
- A is Incorrect: Amazon S3 is great for storing raw data or offline training datasets but lacks the low-latency online retrieval capability needed for real-time inference.
- B is Incorrect: While DynamoDB can serve features at low latency, it does not natively provide the feature group management, offline store synchronization, or inherent training-inference consistency features of SageMaker Feature Store.
- D is Incorrect: Amazon Redshift is a data warehouse optimized for analytical queries, not for low-latency feature serving or managing feature definitions for ML models.

> Key Takeaway: Amazon SageMaker Feature Store provides a unified repository for engineered features, serving both offline batch training and online low-latency inference to prevent skew.
### Question 10 - Handling Non-Uniform Distributions with Binning

A healthcare provider is preparing patient data for a predictive model. They want to group patients into 4 equal-sized tiers based on their annual_visits count. However, the distribution of visits is highly non-uniform (most patients have 0-2 visits, but a few have many). They need to ensure each bin contains an approximately equal number of patients. They are using AWS Glue DataBrew.

Which binning strategy should they apply to meet this requirement?

- A) Apply equal-width binning.
- B) Apply quantile (equal-frequency) binning.
- C) Apply standardization, then equal-width binning.
- D) Apply Min-Max normalization, then equal-width binning.
Correct Answer & Explanation
Correct Answer: B

Correct Answer Analysis:
Quantile binning (also known as equal-frequency binning) divides the data into bins such that each bin contains approximately the same number of samples. This is ideal for non-uniform distributions, as it prevents a situation where one bin contains almost all the data and the others are empty.

Distractor Analysis:
- A is Incorrect: Equal-width binning divides the range of the data into equal intervals. For a highly non-uniform distribution, this would result in the first bin containing 99% of the data and the remaining bins being nearly empty.
- C is Incorrect: Standardizing the data does not change the underlying frequency distribution; applying equal-width binning afterward would still result in uneven bin populations.
- D is Incorrect: Similar to C, normalizing the data does not fix the non-uniform distribution issue for equal-width binning.

> Key Takeaway: Use quantile (equal-frequency) binning when you need to group a non-uniformly distributed continuous variable into bins that each contain a roughly equal number of samples.