Notebooks
A
Amazon Web Services
Sm Xgboost Bring Your Own Model

Sm Xgboost Bring Your Own Model

deploy_and_monitordata-scienceinferenceamazon-sagemaker-examplesreinforcement-learningmachine-learningsm-xgboost_bring_your_own_modelawsexamplesdeep-learningsagemakerjupyter-notebooktrainingmlops
[ ]

Amazon SageMaker XGBoost Bring Your Own Model


This notebook's CI test result for us-west-2 is as follows. CI test results in other regions can be found at the end of the notebook.

This us-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable


Hosting a Pre-Trained scikit-learn Model in Amazon SageMaker XGBoost Algorithm Container



Contents

  1. Background
  2. Setup
  3. Optionally, train a scikit learn XGBoost model
  4. Upload the pre-trained model to S3
  5. Set up hosting for the model
  6. Validate the model for use

Background

Amazon SageMaker includes functionality to support a hosted notebook environment, distributed, serverless training, and real-time hosting. We think it works best when all three of these services are used together, but they can also be used independently. Some use cases may only require hosting. Maybe the model was trained prior to Amazon SageMaker existing, in a different service.

This notebook shows how to use a pre-existing scikit-learn trained XGBoost model with the Amazon SageMaker XGBoost Algorithm container to quickly create a hosted endpoint for that model. Please note that scikit-learn XGBoost model is compatible with SageMaker XGBoost container, whereas other gradient boosted tree models (such as one trained in SparkML) are not.


Setup

Let's start by specifying:

  • AWS region.
  • The IAM role arn used to give learning and hosting access to your data. See the documentation for how to specify these.
  • The S3 bucket that you want to use for training and model data.
[ ]
[ ]

Optionally, train a scikit learn XGBoost model

These steps are optional and are needed to generate the scikit-learn model that will eventually be hosted using the SageMaker Algorithm contained.

Install XGboost

Note that for conda based installation, you'll need to change the Notebook kernel to the environment with conda and Python3.

[ ]

Prepare the dataset for training

[ ]
[ ]

Train the XGBClassifier

[ ]

Save the trained model file

Note that the model file name must satisfy the regular expression pattern: ^[a-zA-Z0-9](-*[a-zA-Z0-9])*;. The model file also need to tar-zipped.

[ ]
[ ]

Upload the pre-trained model to S3

[ ]

Set up hosting for the model

Import model into hosting

This involves creating a SageMaker model from the model file previously uploaded to S3.

[ ]
[ ]

Create endpoint configuration

SageMaker supports configuring REST endpoints in hosting with multiple models, e.g. for A/B testing purposes. In order to support this, you can create an endpoint configuration, that describes the distribution of traffic across the models, whether split, shadowed, or sampled in some way. In addition, the endpoint configuration describes the instance type required for model deployment.

[ ]

Create endpoint

Lastly, you create the endpoint that serves up the model, through specifying the name and configuration defined above. The end result is an endpoint that can be validated and incorporated into production applications. This takes 9-11 minutes to complete.

[ ]

Validate the model for use

Now you can obtain the endpoint from the client library using the result from previous operations and generate classifications from the model using that endpoint.

[ ]

Lets generate the prediction for a single datapoint. We'll pick one from the test data generated earlier.

[ ]
[ ]

Post process the output

Since the result is a string, let's process it to determine the the output class label.

[ ]

(Optional) Delete the Endpoint

If you're ready to be done with this notebook, please run the delete_endpoint line in the cell below. This will remove the hosted endpoint you created and avoid any charges from a stray instance being left on.

[ ]

Notebook CI Test Results

This notebook was tested in multiple regions. The test results are as follows, except for us-west-2 which is shown at the top of the notebook.

This us-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This us-east-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This us-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ca-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This sa-east-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-west-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-west-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-west-3 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-central-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This eu-north-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-southeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-southeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-northeast-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-northeast-2 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable

This ap-south-1 badge failed to load. Check your device's internet connectivity, otherwise the service is currently unavailable