Machine Learning with Amazon SageMaker Cookbook

Book description

A step-by-step solution-based guide to preparing building, training, and deploying high-quality machine learning models with Amazon SageMaker

Key Features

  • Perform ML experiments with built-in and custom algorithms in SageMaker
  • Explore proven solutions when working with TensorFlow, PyTorch, Hugging Face Transformers, and scikit-learn
  • Use the different features and capabilities of SageMaker to automate relevant ML processes

Book Description

Amazon SageMaker is a fully managed machine learning (ML) service that helps data scientists and ML practitioners manage ML experiments. In this book, you'll use the different capabilities and features of Amazon SageMaker to solve relevant data science and ML problems.

This step-by-step guide features 80 proven recipes designed to give you the hands-on machine learning experience needed to contribute to real-world experiments and projects. You'll cover the algorithms and techniques that are commonly used when training and deploying NLP, time series forecasting, and computer vision models to solve ML problems. You'll explore various solutions for working with deep learning libraries and frameworks such as TensorFlow, PyTorch, and Hugging Face Transformers in Amazon SageMaker. You'll also learn how to use SageMaker Clarify, SageMaker Model Monitor, SageMaker Debugger, and SageMaker Experiments to debug, manage, and monitor multiple ML experiments and deployments. Moreover, you'll have a better understanding of how SageMaker Feature Store, Autopilot, and Pipelines can meet the specific needs of data science teams.

By the end of this book, you'll be able to combine the different solutions you've learned as building blocks to solve real-world ML problems.

What you will learn

  • Train and deploy NLP, time series forecasting, and computer vision models to solve different business problems
  • Push the limits of customization in SageMaker using custom container images
  • Use AutoML capabilities with SageMaker Autopilot to create high-quality models
  • Work with effective data analysis and preparation techniques
  • Explore solutions for debugging and managing ML experiments and deployments
  • Deal with bias detection and ML explainability requirements using SageMaker Clarify
  • Automate intermediate and complex deployments and workflows using a variety of solutions

Who this book is for

This book is for developers, data scientists, and machine learning practitioners interested in using Amazon SageMaker to build, analyze, and deploy machine learning models with 80 step-by-step recipes. All you need is an AWS account to get things running. Prior knowledge of AWS, machine learning, and the Python programming language will help you to grasp the concepts covered in this book more effectively.

Table of contents

  1. Machine Learning with Amazon SageMaker Cookbook
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    9. Get in touch
    10. Share Your Thoughts
  6. Chapter 1: Getting Started with Machine Learning Using Amazon SageMaker
    1. Technical requirements
    2. Launching an Amazon SageMaker Notebook Instance
      1. Getting ready
      2. How to do it…
      3. How it works…
    3. Checking the versions of the SageMaker Python SDK and the AWS CLI
      1. Getting ready
      2. How to do it…
      3. How it works…
    4. Preparing the Amazon S3 bucket and the training dataset for the linear regression experiment
      1. Getting ready
      2. How to do it…
      3. How it works…
    5. Visualizing and understanding your data in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
    6. Training your first model in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    7. Loading a linear learner model with Apache MXNet in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
    8. Evaluating the model in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    9. Deploying your first model in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
    10. Invoking an Amazon SageMaker model endpoint with the SageMakerRuntime client from boto3
      1. Getting ready
      2. How to do it…
      3. How it works…
  7. Chapter 2: Building and Using Your Own Algorithm Container Image
    1. Technical requirements
    2. Launching and preparing the Cloud9 environment
      1. Getting ready
      2. How to do it…
      3. How it works…
    3. Setting up the Python and R experimentation environments
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    4. Preparing and testing the train script in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    5. Preparing and testing the serve script in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
    6. Building and testing the custom Python algorithm container image
      1. Getting ready
      2. How to do it…
      3. How it works…
    7. Pushing the custom Python algorithm container image to an Amazon ECR repository
      1. Getting ready
      2. How to do it…
      3. How it works…
    8. Using the custom Python algorithm container image for training and inference with Amazon SageMaker Local Mode
      1. Getting ready
      2. How to do it…
      3. How it works…
    9. Preparing and testing the train script in R
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There's more…
    10. Preparing and testing the serve script in R
      1. Getting ready
      2. How to do it...
      3. How it works…
    11. Building and testing the custom R algorithm container image
      1. Getting ready
      2. How to do it...
      3. How it works…
    12. Pushing the custom R algorithm container image to an Amazon ECR repository
      1. Getting ready
      2. How to do it...
      3. How it works…
    13. Using the custom R algorithm container image for training and inference with Amazon SageMaker Local Mode
      1. Getting ready
      2. How to do it...
      3. How it works…
  8. Chapter 3: Using Machine Learning and Deep Learning Frameworks with Amazon SageMaker
    1. Technical requirements
    2. Preparing the SageMaker notebook instance for multiple deep learning local experiments
      1. Getting ready
      2. How to do it
      3. How it works...
      4. There's more...
    3. Generating a synthetic dataset for deep learning experiments
      1. Getting ready
      2. How to do it
      3. How it works...
    4. Preparing the entrypoint TensorFlow and Keras training script
      1. Getting ready
      2. How to do it
      3. How it works...
      4. There's more...
    5. Training and deploying a TensorFlow and Keras model with the SageMaker Python SDK
      1. Getting ready
      2. How to do it
      3. How it works...
      4. There's more...
      5. See also
    6. Preparing the entrypoint PyTorch training script
      1. Getting ready
      2. How to do it
      3. How it works...
    7. Preparing the entrypoint PyTorch inference script
      1. Getting ready
      2. How to do it
      3. How it works...
    8. Training and deploying a PyTorch model with the SageMaker Python SDK
      1. Getting ready
      2. How to do it
      3. How it works...
      4. See also
    9. Preparing the entrypoint scikit-learn training script
      1. Getting ready
      2. How to do it
      3. How it works...
    10. Training and deploying a scikit-learn model with the SageMaker Python SDK
      1. Getting ready
      2. How to do it
      3. How it works...
      4. See also
    11. Debugging disk space issues when using local mode
      1. Getting ready
      2. How to do it
      3. How it works...
      4. There's more...
    12. Debugging container execution issues when using local mode
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  9. Chapter 4: Preparing, Processing, and Analyzing the Data
    1. Technical requirements
    2. Generating a synthetic dataset for anomaly detection experiments
      1. Getting ready
      2. How to do it…
      3. How it works…
    3. Training and deploying an RCF model
      1. Getting ready…
      2. How to do it…
      3. How it works…
      4. See also
    4. Invoking machine learning models with Amazon Athena using SQL queries
      1. Getting ready
      2. How to do it…
      3. How it works…
    5. Analyzing data with Amazon Athena in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
    6. Generating a synthetic dataset for analysis and transformation
      1. Getting ready
      2. How to do it…
      3. How it works…
    7. Performing dimensionality reduction with the built-in PCA algorithm
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    8. Performing cluster analysis with the built-in KMeans algorithm
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    9. Converting CSV data into protobuf recordIO format
      1. Getting ready
      2. How to do it…
      3. How it works…
    10. Training a KNN model using the protobuf recordIO training input type
      1. Getting ready
      2. How to do it…
      3. How it works…
    11. Preparing the SageMaker Processing prerequisites using the AWS CLI
      1. Getting ready
      2. How to do it…
      3. How it works…
    12. Managed data processing with SageMaker Processing in Python
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    13. Managed data processing with SageMaker Processing in R
      1. Getting ready
      2. How to do it…
      3. How it works…
  10. Chapter 5: Effectively Managing Machine Learning Experiments
    1. Technical requirements
    2. Synthetic data generation for classification problems
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    3. Identifying issues with SageMaker Debugger
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Inspecting SageMaker Debugger logs and results
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Running and managing multiple experiments with SageMaker Experiments
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    6. Experiment analytics with SageMaker Experiments
      1. Getting ready
      2. How to do it…
      3. How it works…
    7. Inspecting experiments, trials, and trial components with SageMaker Experiments
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
  11. Chapter 6: Automated Machine Learning in Amazon SageMaker
    1. Technical requirements
    2. Onboarding to SageMaker Studio
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    3. Generating a synthetic dataset with additional columns containing random values
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    4. Creating and monitoring a SageMaker Autopilot experiment in SageMaker Studio (console)
      1. Getting ready
      2. How to do it…
      3. How it works…
    5. Creating and monitoring a SageMaker Autopilot experiment using the SageMaker Python SDK
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    6. Inspecting the SageMaker Autopilot experiment's results and artifacts
      1. Getting ready
      2. How to do it…
      3. How it works…
    7. Performing Automatic Model Tuning with the SageMaker XGBoost built-in algorithm
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    8. Analyzing the Automatic Model Tuning job results
      1. Getting ready
      2. How to do it…
      3. How it works…
  12. Chapter 7: Working with SageMaker Feature Store, SageMaker Clarify, and SageMaker Model Monitor
    1. Technical requirements
    2. Generating a synthetic dataset and using SageMaker Feature Store for storage and management
      1. Getting ready
      2. How to do it…
      3. How it works…
    3. Querying data from the offline store of SageMaker Feature Store and uploading it to Amazon S3
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    4. Detecting pre-training bias with SageMaker Clarify
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    5. Detecting post-training bias with SageMaker Clarify
      1. Getting ready
      2. How to do it…
      3. How it works…
    6. Enabling ML explainability with SageMaker Clarify
      1. Getting ready
      2. How to do it…
      3. How it works…
    7. Deploying an endpoint from a model and enabling data capture with SageMaker Model Monitor
      1. Getting ready
      2. How to do it…
      3. How it works…
    8. Baselining and scheduled monitoring with SageMaker Model Monitor
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
  13. Chapter 8: Solving NLP, Image Classification, and Time-Series Forecasting Problems with Built-in Algorithms
    1. Technical requirements
    2. Generating a synthetic dataset for text classification problems
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    3. Preparing the test dataset for batch transform inference jobs
      1. Getting ready
      2. How to do it…
      3. How it works…
    4. Training and deploying a BlazingText model
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See more
    5. Using Batch Transform for inference
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    6. Preparing the datasets for image classification using the Apache MXNet Vision Datasets classes
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Training and deploying an image classifier using the built-in Image Classification Algorithm in SageMaker
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    8. Generating a synthetic time series dataset
      1. Getting ready
      2. How to do it…
      3. How it works…
    9. Performing the train-test split on a time series dataset
      1. Getting ready
      2. How to do it…
      3. How it works…
    10. Training and deploying a DeepAR model
      1. Getting ready
      2. How to do it…
      3. How it works…
    11. Performing probabilistic forecasting with a deployed DeepAR model
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. See also
  14. Chapter 9: Managing Machine Learning Workflows and Deployments
    1. Technical requirements
    2. Working with Hugging Face models
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    3. Preparing the prerequisites of a multi-model endpoint deployment
      1. Getting ready
      2. How to do it…
      3. How it works…
    4. Hosting multiple models with multi-model endpoints
      1. Getting ready
      2. How to do it…
      3. How it works…
    5. Setting up A/B testing on multiple models with production variants
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    6. Preparing the Step Functions execution role
      1. Getting ready
      2. How to do it…
      3. How it works…
    7. Managing ML workflows with AWS Step Functions and the Data Science SDK
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    8. Managing ML workflows with SageMaker Pipelines
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    9. Why subscribe?
  15. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts

Product information

  • Title: Machine Learning with Amazon SageMaker Cookbook
  • Author(s): Joshua Arvin Lat
  • Release date: October 2021
  • Publisher(s): Packt Publishing
  • ISBN: 9781800567030