Fatskills
Practice. Master. Repeat.
Study Guide: Cloud ML - AWS Certified Machine Learning Engineer – Associate (MLA-C01): Feature Types and Statistics (Descriptive, Inferential)
Source: https://www.fatskills.com/machine-learning-101/chapter/cloud-ml-cert-aws-ml-feature-types-and-statistics-descriptive-inferential

Cloud ML - AWS Certified Machine Learning Engineer – Associate (MLA-C01): Feature Types and Statistics (Descriptive, Inferential)

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~8 min read

AWS_ML – Feature Types and Statistics (Descriptive, Inferential)


AWS Certified Machine Learning – Specialty: Feature Types & Statistics (Descriptive, Inferential) – Exam-Ready Study Guide



What This Is

Feature types and statistics (descriptive and inferential) are the foundation of any ML pipeline. Descriptive statistics (mean, variance, distributions) help you understand your data, while inferential statistics (hypothesis testing, confidence intervals) help you generalize findings from samples to populations. In AWS ML workflows, these concepts are critical for: - Feature engineering (e.g., normalizing numerical features, encoding categorical variables).
- Data validation (e.g., detecting drift in SageMaker Model Monitor).
- Model interpretability (e.g., explaining feature importance in SageMaker Clarify).

Real-world scenario:
A fintech company builds a fraud detection model using Amazon SageMaker. Before training, they use descriptive statistics (e.g., histograms of transaction amounts, correlation matrices) to identify outliers and skewed features. After deployment, they use inferential statistics (e.g., Kolmogorov-Smirnov tests in SageMaker Model Monitor) to detect feature drift (e.g., a sudden spike in high-value transactions) and trigger retraining.


Key Terms & Services


Core Concepts

  • Descriptive Statistics: Summarizes data (e.g., mean, median, standard deviation, percentiles). Used in SageMaker Data Wrangler for EDA (Exploratory Data Analysis).
  • Inferential Statistics: Draws conclusions about a population from a sample (e.g., hypothesis testing, p-values, confidence intervals). Used in SageMaker Model Monitor for drift detection.
  • Feature Types:
  • Numerical: Continuous (e.g., transaction amount) or discrete (e.g., number of transactions).
  • Categorical: Nominal (e.g., merchant category) or ordinal (e.g., risk rating: low/medium/high).
  • Text: Raw text (e.g., customer reviews) → processed via SageMaker Processing (TF-IDF, embeddings).
  • Time-Series: Sequential data (e.g., stock prices) → handled by Amazon Forecast or SageMaker DeepAR.
  • Embeddings: Dense vector representations (e.g., from SageMaker JumpStart LLMs or Amazon Bedrock).
  • Feature Scaling: Normalization (min-max) vs. standardization (z-score). SageMaker Feature Store can apply scaling at ingestion.
  • Feature Encoding:
  • One-Hot Encoding: For nominal categories (e.g., merchant_type=[0,1,0]).
  • Label Encoding: For ordinal categories (e.g., risk_rating=[1,2,3]).
  • Target Encoding: Replaces categories with the mean of the target variable (risky for overfitting; use SageMaker Clarify to detect bias).
  • Feature Importance: Metrics like SHAP values (SageMaker Clarify) or permutation importance (SageMaker built-in algorithms).
  • Drift Detection: SageMaker Model Monitor uses Kolmogorov-Smirnov (KS) tests (for numerical features) and Population Stability Index (PSI) (for categorical features) to detect drift.

AWS Services

  • Amazon SageMaker Data Wrangler: No-code EDA and feature engineering (e.g., compute descriptive stats, visualize distributions).
  • SageMaker Feature Store: Centralized repository for features (online/offline). Ensures consistency between training and inference.
  • SageMaker Processing: Run custom feature engineering scripts (e.g., PySpark, scikit-learn) at scale.
  • SageMaker Model Monitor: Detects data drift (feature drift) and model drift (prediction drift) using inferential statistics.
  • SageMaker Clarify: Detects bias (e.g., disparate impact) and explains feature importance (SHAP values).
  • AWS Glue DataBrew: Visual data preparation (alternative to Data Wrangler for non-SageMaker users).


Step-by-Step / Process Flow


1. Exploratory Data Analysis (EDA) with Descriptive Statistics

Goal: Understand feature distributions, missing values, and outliers.
Steps:
1. Load data into SageMaker Data Wrangler (or a SageMaker Notebook with pandas).
2. Compute descriptive stats:
- Numerical: df.describe() (mean, std, min/max, quartiles).
- Categorical: df['category'].value_counts().
3. Visualize distributions:
- Histograms (numerical), bar plots (categorical), box plots (outliers).
- Use SageMaker Data Wrangler’s built-in visualizations or matplotlib/seaborn.
4. Handle missing data:
- Drop rows/columns (df.dropna()) or impute (mean/median for numerical, mode for categorical).
- Use SageMaker Processing for large-scale imputation.

2. Feature Engineering

Goal: Transform raw data into features usable by ML models.
Steps:
1. Encode categorical features:
- One-hot encoding (for nominal categories) → pd.get_dummies().
- Label encoding (for ordinal categories) → sklearn.preprocessing.LabelEncoder.
- Target encoding (for high-cardinality categories) → Use SageMaker Processing to avoid leakage.
2. Scale numerical features:
- Standardization (z-score) → sklearn.preprocessing.StandardScaler.
- Normalization (min-max) → sklearn.preprocessing.MinMaxScaler.
3. Create new features:
- Time-based: Extract day/month/year from timestamps.
- Aggregations: Rolling averages (for time-series).
- Text: TF-IDF or embeddings (via SageMaker JumpStart or Amazon Comprehend).
4. Store features in SageMaker Feature Store:
- Create a Feature Group (online/offline).
- Ingest data via SageMaker Processing or AWS Glue.
- Query features for training/inference via FeatureStore SDK.

3. Inferential Statistics for Drift Detection

Goal: Monitor features for drift in production.
Steps:
1. Set up SageMaker Model Monitor:
- Attach a Monitoring Schedule to a SageMaker endpoint.
- Configure baseline statistics (from training data).
2. Define drift thresholds:
- KS test (numerical features): Default threshold = 0.01 (p-value).
- PSI (categorical features): Default threshold = 0.25 (moderate drift).
3. Run drift analysis:
- Model Monitor compares current data (inference) vs. baseline (training).
- Generates CloudWatch alerts if drift exceeds thresholds.
4. Take action:
- Retrain model if drift is detected.
- Investigate root cause (e.g., data pipeline changes).


Common Mistakes


Mistake 1: Ignoring Feature Scaling for Distance-Based Models

  • Mistake: Using raw numerical features (e.g., transaction amounts in dollars) for k-NN, SVM, or k-means.
  • Correction: Always scale features (standardization for Gaussian data, normalization for bounded ranges). SageMaker’s built-in algorithms (e.g., k-means) automatically scale features, but custom models (e.g., PyTorch) require manual scaling.

Mistake 2: One-Hot Encoding High-Cardinality Categories

  • Mistake: One-hot encoding a categorical feature with 100+ unique values (e.g., user_id), leading to sparse matrices and curse of dimensionality.
  • Correction: Use target encoding (with smoothing to avoid overfitting) or embeddings (for deep learning). SageMaker Clarify can detect bias from high-cardinality encoding.

Mistake 3: Not Validating Feature Distributions Before Training

  • Mistake: Assuming training and inference data have the same distribution (e.g., skewed transaction amounts in production vs. uniform in training).
  • Correction: Use SageMaker Model Monitor to detect feature drift (KS test for numerical, PSI for categorical). Set up CloudWatch alerts for drift events.

Mistake 4: Using Mean Imputation for Missing Data Without Analysis

  • Mistake: Blindly imputing missing values with the mean, which can bias the model (e.g., imputing missing income with the mean may skew predictions).
  • Correction: Analyze missingness patterns (MCAR, MAR, MNAR). Use SageMaker Data Wrangler to visualize missing data. Consider multiple imputation (e.g., sklearn.impute.IterativeImputer) or flagging missing values as a separate category.

Mistake 5: Confusing Descriptive vs. Inferential Statistics in Drift Detection

  • Mistake: Using descriptive stats (e.g., mean/median) to detect drift, which doesn’t account for statistical significance.
  • Correction: Use inferential stats (e.g., KS test for numerical features, PSI for categorical) in SageMaker Model Monitor. Descriptive stats are for EDA; inferential stats are for monitoring.


Certification Exam Insights


1. Feature Engineering Service Selection

  • When to use SageMaker Data Wrangler vs. SageMaker Processing:
  • Data Wrangler: No-code EDA and feature engineering (best for quick prototyping).
  • SageMaker Processing: Custom Python/R scripts (best for large-scale, complex transformations).
  • When to use AWS Glue DataBrew vs. SageMaker Data Wrangler:
  • DataBrew: For non-SageMaker users (e.g., data engineers using AWS Glue).
  • Data Wrangler: Tightly integrated with SageMaker (e.g., direct export to Feature Store).

2. Drift Detection Traps

  • KS Test vs. PSI:
  • KS test: For numerical features (compares distributions).
  • PSI: For categorical features (compares proportions).
  • Exam trap: The exam may ask which test to use for a given feature type.
  • Model Monitor Thresholds:
  • Default KS p-value threshold = 0.01 (reject null hypothesis if p < 0.01).
  • Default PSI threshold = 0.25 (moderate drift).
  • Exam trap: Know that lower KS p-values = more drift, while higher PSI = more drift.

3. Feature Store vs. S3 for Feature Storage

  • SageMaker Feature Store:
  • Pros: Low-latency online access, versioning, consistency between training/inference.
  • Cons: Costlier than S3 (pay per read/write).
  • S3:
  • Pros: Cheap, scalable, works with Athena/Glue for batch access.
  • Cons: No built-in online serving, risk of feature drift if training/inference data diverge.
  • Exam trap: The exam may ask when to use Feature Store (real-time inference) vs. S3 (batch training).

4. Bias Detection in Feature Engineering

  • SageMaker Clarify detects:
  • Disparate impact (e.g., a feature like gender causing biased predictions).
  • SHAP values (feature importance explanations).
  • Exam trap: Know that Clarify is for bias detection, not drift detection (that’s Model Monitor).


Quick Check Questions


Question 1

A retail company uses SageMaker to train a demand forecasting model. After deployment, they notice that the model’s predictions are consistently off for high-value items. SageMaker Model Monitor reports a KS test p-value of 0.001 for the item_price feature. What does this indicate, and what action should they take?

Answer:
The KS test p-value of 0.001 indicates statistically significant drift in the item_price feature (p < 0.01). The team should retrain the model with updated data and investigate why the price distribution changed (e.g., new pricing strategy, data pipeline error).


Question 2

A data scientist is building a fraud detection model using SageMaker XGBoost. They have a categorical feature merchant_category with 50 unique values. Which encoding method should they use to avoid the curse of dimensionality, and why?

Answer:
They should use target encoding (with smoothing) or embeddings (for deep learning). One-hot encoding would create 50 new features, leading to sparse data and poor model performance. Target encoding replaces categories with the mean of the target variable (fraud rate per category), reducing dimensionality.


Question 3

A team is using SageMaker Feature Store to serve features for a real-time recommendation system. During inference, they notice that online feature retrieval latency is high. What are two possible causes, and how can they fix them?

Answer:
1. Cause: The Feature Group is not optimized for online access (e.g., too many features or large feature values).
Fix: Use smaller feature groups or compress feature values (e.g., use float32 instead of float64).
2. Cause: The Feature Store TTL (Time-to-Live) is too short, causing frequent cache misses.
Fix: Increase the TTL (default = 1 hour) to reduce backend queries.


Last-Minute Cram Sheet

  1. Descriptive stats = EDA (mean, std, histograms). Inferential stats = hypothesis testing (KS test, PSI).
  2. KS test (numerical features) and PSI (categorical features) are used in SageMaker Model Monitor for drift detection.
  3. Default KS p-value threshold = 0.01 (lower = more drift). Default PSI threshold = 0.25 (higher = more drift).
  4. One-hot encoding = nominal categories. Label encoding = ordinal categories. Target encoding = high-cardinality categories.
  5. SageMaker Feature Store = online/offline feature serving. S3 = cheap batch storage.
  6. Standardization (z-score) = Gaussian data. Normalization (min-max) = bounded ranges.
  7. SageMaker Clarify = bias detection (disparate impact, SHAP values). Model Monitor = drift detection.
  8. ⚠️ Data Wrangler is for EDA/feature engineering, not training. Use SageMaker Processing for large-scale transformations.
  9. ⚠️ Mean imputation can bias models. Analyze missingness patterns first (MCAR, MAR, MNAR).
  10. ⚠️ Feature Store online latency issues? Check TTL and feature group size. Use float32 instead of float64.


ADVERTISEMENT