{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Use Your Own Inference Code with Amazon SageMaker XGBoost Algorithm\n" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "\n", "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. \n", "\n", "\n", "\n", "---" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "_**Customized inference for computing SHAP values with Amazon SageMaker XGBoost script mode**_\n", "\n", "---\n", "\n", "## Contents\n", "1. [Introduction](#Introduction)\n", "2. [Setup](#Setup)\n", "3. [Train the XGBoost Model](#Train-the-XGBoost-model)\n", " 1. [Train with XGBoost Estimator and SageMaker Training](#Train-with-XBoost-estimator-and-sagemaker-training)\n", " 2. [Train with Automatic Model Tuning (HPO)](#Train-with-automatic-model-tuning)\n", "4. [Deploying the XGBoost endpoint](#Deploying-the-XGBoost-endpoint)\n", "\n", "---" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\n", "\n", "This notebook shows how you can configure the SageMaker XGBoost model server by defining the following three functions in the Python source file you pass to the XGBoost constructor in the SageMaker Python SDK:\n", "- `input_fn`: Takes request data and deserializes the data into an object for prediction,\n", "- `predict_fn`: Takes the deserialized request object and performs inference against the loaded model, and\n", "- `output_fn`: Takes the result of prediction and serializes this according to the response content type.\n", "We will write a customized inference script that is designed to illustrate how [SHAP](https://github.com/slundberg/shap) values enable the interpretion of XGBoost models.\n", "\n", "We use the [Abalone data](https://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/regression.html), originally from the [UCI data repository](https://archive.ics.uci.edu/ml/datasets/abalone). More details about the original dataset can be found [here](https://archive.ics.uci.edu/ml/machine-learning-databases/abalone/abalone.names). In this libsvm converted version, the nominal feature (Male/Female/Infant) has been converted into a real valued feature as required by XGBoost. Age of abalone is to be predicted from eight physical measurements.\n", "\n", "This notebook uses the Abalone dataset to deploy a model server that returns SHAP values, which enable us to create model explanation such as the following plots that show each features contributing to push the model output from the base value.\n", "\n", "
![]() | \n",
" ![]() | \n",
"