Sitemap

[AWS-AI] Amazon SageMaker Explained: From Data Preparation to Model Deployment

A beginner-friendly guide to building, training, tuning, and deploying Machine Learning models with AWS SageMaker.

Press enter or click to view image in full size

Amazon SageMaker is a fully managed Machine Learning service that helps developers and data scientists build, train, tune, and deploy ML models. It provides the tools and infrastructure needed to develop ML solutions without managing the underlying servers.

  • Servers;
  • CPU/GPU configuration;
  • Training environments;
  • Deployment infrastructure.

With SageMaker, AWS manages the infrastructure, allowing teams to focus more on building and improving Machine Learning models.

The Machine Learning lifecycle in SageMaker can be divided into some main steps:

Data Preparation

Before training a model, the data needs to be prepared. Some common steps are:

  • Import data from Amazon S3.
  • Clean the data by removing missing values and duplicated records.
  • Transform the data into features (numerical representations that the Machine Learning model can understand).
  • Split the data into training and testing datasets.

The quality of the data directly impacts the performance of the model.

Training

During training, the model learns patterns from the training dataset.

  • The user chooses the algorithm, programming language, and Machine Learning framework. SageMaker provides the required infrastructure, such as CPU or GPU instances, to run the training process.
  • During this step, the model adjusts its internal parameters to learn from the data.

Hyperparameter Tuning

  • Hyperparameters are configurations that define how the model will learn during training. They are set before the training process starts.
  • SageMaker can automatically test different combinations of hyperparameters to find the configuration that provides better performance.

Examples of hyperparams:

  • Learning rate: controls how much the model changes after each learning step.
  • Batch size: defines how many data samples are processed at once.
  • Epochs: defines how many times the model goes through the entire dataset.

Model Evaluation

  • After training, the model is evaluated using metrics such as accuracy, precision, recall, and F1-score. If the performance is not satisfactory, the model can be improved by changing the data, algorithm, or hyperparameters and training it again.
  • These metrics help us understand how well the model performs on unseen data.

Example: Building a Recommendation Model with Amazon SageMaker

Automated Pipeline with AWS Services

Imagine an e-commerce company that wants to recommend products to its customers.

The company has historical data about customer interactions, such as:

  • Which products each customer viewed;
  • Which products were purchased;
  • Customer ratings;
  • Previous interactions.

The goal is to predict which products a customer might like based on their previous behavior.

1. Data Preparation

First, the data needs to be stored and prepared.

For example, a dataset could look like this:

Customer
User A
User A
User B
User C

Get Miss Robot’s stories in your inbox

Join Medium for free to get updates from this writer.

Product
Product 1
Product 3
Product 2
Product 1

Interaction
Purchased
Viewed
Purchased
Rated

This data can be stored in Amazon S3 and then processed before training.

During this step, we can:

  • Remove duplicated records;
  • Handle missing values;
  • Transform the data into a format that the algorithm can understand.

2. Model Training with SageMaker

After preparing the data, we can train a Machine Learning model.

In this example, we can use a recommendation algorithm called Singular Value Decomposition (SVD).

SVD analyzes patterns in user interactions to identify relationships between:

  • Users;
  • Products;
  • Preferences.

For example:

Users who purchased Product A and Product B in the past may also be interested in Product C.

The model does not understand why users like these products. Instead, it identifies patterns from previous interactions

SageMaker provides the infrastructure needed to run this training process, using CPU or GPU resources depending on the workload.

3. Generating Predictions (Inference)

After training, the model can generate recommendations.

Example:

The model analyzes:

User A:
- Purchased: Laptop
- Viewed: Keyboard
- Rated: Mouse

Based on learned patterns, the model predicts:

Recommended products:
1. Monitor
2. Headset
3. Webcam

This process is called inference, where the trained model is used to make predictions using new data.

4. Automated Pipeline with AWS Services

In a real-world scenario, this process can be automated using multiple AWS services.

Example architecture:

Press enter or click to view image in full size

The workflow:

1.A CSV file is uploaded to Amazon S3.

2.An event triggers AWS Lambda.

3.Lambda starts a SageMaker Processing Job.

4.SageMaker runs the ML pipeline:

  • Data processing;
  • Model training;
  • Inference.

5.The results are saved back into S3.

Well, that’s it for today

In the next articles, I will explore how AWS services can be used for text processing, computer vision, recommendation systems, conversational AI, and Generative AI.

Here is what is coming next:

AWS AI & ML Services Roadmap

AI & ML
|
┌────────────────┼────────────────┐
| | |
ML Lifecycle AI Services Generative AI
| | |
✅ SageMaker Comprehend Bedrock
Rekognition
Personalize
Lex

See you in the next article! :)