SeriesAWS ML Engineer (Associate)2 / 9

Data Transformation, Integrity, and Feature Engineering

Section 3 of AWS Certified ML Engineer course from Udemy.

Introduction#

Following ingestion of input data for a machine learning project, it must be transformed and standardized to ensure compatibility with mathematical modeling. This section reviews common approaches and AWS services for data transformation.

EMR and Hadoop#

Elastic MapReduce is a managed Hadoop framework which runs on EC2 instances. EMR provides a method for distributing the processing load associated with heavy computational tasks, such as pre-processing massive datasets for machine learning training.

An EMR cluster consists of multiple collaborating EC2 instances, which are referred to as nodes.

Transient EMR clusters automatically terminate after completing their tasks. Long-Running clusters continue to run and remain indefinitely available for computation.

EMR Serverless#

Serverless is a cloud computing framework in which the cloud provider managers the servers, and dynamically allocates instances as appropriate. EMR Serverless is therefore the same as EMR, but with AWS managing the underlying capacity of worker nodes.

Apache Hadoop and Spark#

Hadoop is a distributed computing framework built in layers:

In the modern distributed computing landscape, Apache Spark has taken the place of MapReduce as a simpler service for distributed computing. Spark has APIs for common programming languages (Python, Scala, Java, R) offering many utilities:

Data Transformation Methods#

Feature Engineering#

Feature Engineering refers to the manual derivation of new features, with the intention being to create more useful input features for model training.

"Applied machine learning is basically feature engineering."
- Andrew Ng

Why is feature engineering important in the first place? Couldn’t we simply derive an unbounded amount of features, and plug them all into our machine learning model? The Curse of Dimensionality describes how too many features can be problematic, since the amount of data required to generalize grows exponentially with the number of input dimensions (features).

Most of feature engineering involves using domain knowledge to select the features most relevant to the problem at hand. By limiting the set of input features to relevant predictors, we avoid sparse data (in high dimensionality) without sacrifice to model performance.

Imputing Missing Data#

Prior to training a machine learning model, we must ensure our input dataset does not contain missing values. Imputation is the process of filling missing values according to one of many potential strategies:

Perhaps the best way to fill missing values is to fix the problem at the source by increasing the quantity or improving the quality of input data.

Dealing with Imbalanced Data#

In the context of machine learning, an Imbalanced Dataset has an outcome variable with very different class proportions. For example, consider binary fraud as an outcome - the “positive” class is much less frequent than the “negative” class. This can skew our ML model to favor predicting the majority outcome, inflating accuracy but limiting model utility.

How can we deal with imbalanced data?

Handling Outliers#

Recall that Variance refers to the average of the squared differences from the mean. This estimates the relative spread of our data.

σ2=i(xixˉ)2n\sigma^2 = \frac{\sum_i (x_i - \bar{x})^2}{n}

Standard Deviation is the square root of variance, which places our measure of spread on the same scale as the original variable. Standard deviation is commonly used to identify outliers - for example, data points that lie more than one standard deviation from the mean may be considered unusual.

Given that we’ve identified outliers, how should we deal with them? Depending on the context, we may want to remove records with outliers from our training data.

Binning, Transforming, Encoding, Scaling, and Shuffling#

What other preprocessing steps should we apply to our input data?

SageMaker AI#

SageMaker AI (previously SageMaker) is the AWS service dedicated to machine learning. It supports the entire machine learning lifecycle, including…

How does SageMaker AI work and integrate with other AWS tools?

AWS SageMaker

SageMaker AI Domains#

The first step to using SageMaker AI is creating a domain. Domains organize users, applications, and resources as follows:

Any domain has two Virtual Private Cloud (VPC)‘s by default:

Data Processing, Training, and Deployment#

Okay, so how do we use SageMaker AI to perform the typical steps required for a machine learning project?

STEP 1: Data Processing

STEP 2: Model Training

STEP 3: Model Deployment

SageMaker Data Wrangler#

Data Wrangler is a visual interface for ETL integrated into SageMaker Studio, and is primarily used to prepare data for machine learning. It assists the user with code generation to match their specific needs for preprocessing. In addition to preprocessing, Data Wrangler provides basic tools for visualization and statistical analysis.

SageMaker Model Monitor#

Model Monitor is a tool offered through SageMaker AI which enables users to receive automated AWS CloudWatch alerts on quality deviations for deployed models. It offers functionality for…

Whereas Model Monitor is a code-free service baked into SageMaker, other cloud and language-agnostic coding frameworks such as MLflow can be integrated with deployed models to support monitoring efforts.

SageMaker Feature Store#

In the context of machine learning, a feature is a particular column / variable of the input dataset. SageMaker Feature Store provides a centralized location for feature storage, enabling integration with many different models or services. It is compatible with both streaming and batch data loading options, and encrypts data at rest and in transit.

AWS Glue#

Glue is a serverless AWS system which 1) provides table definitions and schema to unstructured data (ex: S3 data lakes, RDS, etc.), and 2) enables custom event-driven ETL jobs on an Apache Spark cluster.

The Glue Crawler scans data in S3 to construct a schema (table definition, data types) for unstructured data. Once cataloged, this enables users to query unstructured data as if it were stored within a structured data warehouse. Glue provides the “glue” between the relational database interface and unstructured data lake without copying data into a data warehouse.

Tools within Glue#

Glue Studio is a visual (GUI) interface for setting up ETL workflows in Glue. The services offered by Glue Studio are very similar to those found in Azure Synapse Analytics pipelines. We define our data source(s), any transformations, and data target destionation(s) by creating a Directed Acyclic Graph (DAG) within Glue Studio’s visaul interface.

Glue Data Quality integrates into Glue jobs to monitor and detect aspects of data quality, including expected values / range / standard deviation for a given feature. Data quality alerts may terminate the job, or simply appear as log messages in CloudWatch.

Glue DataBrew is a visual data preparation tool used to preprocess large datasets. DataBrew serves the “transform” stage of an ETL process. The user creates “recipes” of transformations, which may be saved as jobs within a larger Glue project. How do we handle personally-identifiable information (PII) in DataBrew transformations?

Amazon Athena#

Athena is a serverless interactive query service for S3, enabling the user to utilize SQL queries with raw S3 data. Athena supports various data types (structured, unstructured, semi-structured), in addition to a wide range of data formats:

How does Athena integrate with Glue? Any S3 bucket with a published Glue catalog is accessible via Athena.

AWS Athena

Athena defines workgroups to organize users / teams / apps / workloads to control query access, track costs, and define data limits. Workgroups integrate with IAM, CloudWatch, and SNS for data governance and monitoring capabilities.

At its core, Athena is a SQL query engine. It should not be utilized for highly formatted reports / data visualization (QuickSight) or pure ETL workloads (Glue).

CREATE TABLE AS SELECT and Performance#

Recall that all data queried through Athena is stored in its native format within Amazon S3. In the context of SQL, CREATE TABLE AS SELECT is used to create a new table from query results. When combined with Athena, this statement can be used to convert data into a new underlying format which may improve querying performance.

CREATE TABLE my_orc_ctas_table
WITH (
external_location = 's3://my_athena_results/my_orc_ctas_table/', format='ORC'
) AS SELECT * FROM old_table;

Okay, so how do data formats influence performance in Athena? Athena tends to prefer columnar data (ORC, Parquet), and a small number of large files over a large number of small files.

ACID Transactions#

ACID is a set of properties for database transactions which guarantee data validity despite any errors or failures in the application.

More on ACID Transactions

Athena supports ACID transactions powered via Apache Iceberg. Users must create ACID-compatible tables with table_type = 'ICEBERG'.


(all information obtained from AWS Certified Machine Learning Engineer Associate: Hands On! course on Udemy)

License

CC BY-NC-SA 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Related Posts