Lesson 4 of 5 Data Transformation and Integration

Preparing Data for ML with SageMaker Data Wrangler

This lesson explains SageMaker Data Wrangler, the visual data preparation tool for ML, now part of SageMaker Canvas, which connects data import, analysis, transformation and export to SageMaker AI pipelines.

Learning outcomes

After completing this lesson, you will be able to:

  • Build a data flow of imports and transformations.
  • Use the Data Quality and Insights Report to find problems such as target leakage.
  • Export a flow to run on the full dataset.

Data flows and transformations

A Data Wrangler data flow is a visual, step-by-step recipe for preparing data. It imports data from Amazon S3, Amazon Athena, Amazon Redshift, Snowflake, Amazon EMR and other sources, then applies a sequence of transformations. More than 300 built-in transforms cover handling missing values, encoding categorical features, scaling numbers, featurising text and dates, and balancing classes.

When the built-in transforms are not enough, custom transforms can be written in PySpark, pandas or SQL. In SageMaker Canvas, users can also describe a transformation in natural language and have it generated. Because the flow records every step, the same preparation can be repeated exactly on new data.

Analysis and insights

Data Wrangler helps decide which preparation matters before a full training job is run. The Data Quality and Insights Report summarises missing values, outliers, duplicate rows, class imbalance and target leakage, which occurs when a feature reveals the label, such as a "cancellation date" column in a churn dataset; a model trained with such a feature looks excellent in testing and fails in production.

A quick model trains a fast baseline on the current data and reports feature importance, which shows whether a transformation improves predictive power. Bias reports use SageMaker Clarify metrics to show whether groups are represented and labelled evenly. These analyses guide which transformations to apply.

The following diagram shows when a loan's collections_status field becomes known compared with when the model must predict default, which makes the field a target leak.

Why collections_status is a target leak. The model must predict default when the loan is scored, but collections_status is populated only after a default has happened, so it is never available at prediction time. Training with it gives 99% accuracy that disappears in production; dropping it, and exporting the corrected flow to a pipeline, gives a realistic model.
The month positions are illustrative.
Match the pairs

Data Wrangler analyses

Exam skills 1.2.1 · 1.3.1

Match each Data Wrangler analysis with what it reveals.

Log in to try this activity Interactive activities are free with an account.

Exporting the flow

A data flow built interactively on a sample must also run on the full dataset in production. Data Wrangler exports a flow in several forms: as a SageMaker AI Processing job that runs the flow at scale, as a step in SageMaker Pipelines so preparation becomes part of an automated workflow, as Python code that engineers can adapt, or directly into SageMaker Feature Store feature groups. Canvas can also use the prepared data to build models with AutoML. Exporting keeps the visual work reproducible in production rather than a one-off manual step. The following table summarises the export options.

Export targetResult
Processing jobRuns the flow on the full dataset and writes output to S3
SageMaker PipelinesAdds the flow as a step in an automated ML pipeline
Feature StoreIngests transformed features into a feature group
Python codeGenerates code that can be edited and version-controlled
Scenario questions

Where the flow goes next

Exam skills 1.2.1

Choose how to export a Data Wrangler flow for each need.

Log in to try this activity Interactive activities are free with an account.
Worked example

Finding target leakage

A data scientist builds a loan default model and gets 99% accuracy on the first attempt. The dataset includes a column collections_status.

The Data Quality and Insights Report flags collections_status as a likely target leak: it is only populated after a loan defaults, so it would not be available at prediction time. Dropping the column brings accuracy to a realistic level. Exporting the corrected flow to a SageMaker pipeline ensures the column is excluded in every retraining run.

Check yourself

Which Data Wrangler report detects target leakage and class imbalance?

Show answer

The Data Quality and Insights Report.

Exam Tips

Remember for the exam

  • Visual ML data preparation integrated with SageMaker AI: Data Wrangler in Canvas.
  • Data Quality and Insights Report detects target leakage and imbalance.
  • Export flows to processing jobs, Pipelines or Feature Store.
  • Custom transforms can use PySpark, pandas or SQL.
  • Suspiciously high accuracy often signals target leakage.