Skip to content

tmastny/sagemaker

Repository files navigation

sagemaker

The sagemaker R package provides a simplified interface to the AWS Sagemaker API by:

  1. adding sensible defaults so you can dive in quickly

  2. creating helper functions to streamline model analysis

  3. supporting data.frames and tibbles

Check out the Get started guide for examples!

Installation

You can install sagemaker from GitHub with:

# install.packages("devtools")
devtools::install_github("tmastny/sagemaker")

You will also need boto3, sagemaker, and awscli python packages. If you don’t have them, or aren’t sure, install with:

sagemaker::sagemaker_install()

Next, you’ll need an AWS account. This is a complicated process and unfortunately I don’t have a good guide to share. Please reach out if you find one and I’ll post it here!

Once you have the account and user setup you’ll want to save your account access keys. This is a good guide to follow.

Lastly, you need a AWS Sagemaker Execution Role. The easiest way is to create a AWS Sagemaker Notebook Instance. Try this guide to get the notebook running. Once the notebook is deployed, inside the instance run:

from sagemaker import get_execution_role

role = get_execution_role()
print(role)

Once you have that role, run this command locally to save it with your local AWS config:

sagemaker::sagemaker_save_execution_role(
  "arn:aws:iam::[account_number]:role/service-role/[SageMakerExecutionRole]"
)

Streamlined Analysis

Compare the AWS Sagemaker API vs. to the sagemaker R package yourself with this side-by-side comparsion . The R package hides the details for latter, and lets you get started ASAP.

You start with this:

library(sagemaker)
xgb <- sagemaker_xgb_estimator()

instead of this:

library(reticulate)
sagemaker <- reticulate::import("sagemaker")
boto3 <- reticulate::import("boto3")

xgb_container <- sagemaker$amazon$amazon_estimator$get_image_uri(
  boto3$Session()$region_name,
  "xgboost",
  repo_version = "latest"
)

xgb <- sagemaker$estimator$Estimator(
  xgb_container,
  sagemaker_get_execution_role(),
  train_instance_count = 1L,
  train_instance_type = "ml.m4.xlarge",
  output_path = s3(s3_bucket(), "/models/"),
  sagemaker_session = sagemaker$Session()
)

About

AWS Sagemaker R Interface

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages