diff --git a/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb b/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb index cb1b39fa09..9f95db44c9 100644 --- a/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb +++ b/advanced_functionality/xgboost_bring_your_own_model/xgboost_bring_your_own_model.ipynb @@ -26,7 +26,7 @@ "---\n", "## Background\n", "\n", - "Amazon SageMaker includes functionality to support a hosted notebook environment, distributed, managed 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.\n", + "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.\n", "\n", "This notebook shows how to use a pre-existing scikit-learn model with the Amazon SageMaker XGBoost Algorithm container to quickly create a hosted endpoint for that model.\n", "\n", @@ -53,6 +53,7 @@ "import os\n", "import boto3\n", "import re\n", + "import json\n", "\n", "region = boto3.Session().region_name\n", "\n", @@ -83,7 +84,7 @@ "metadata": {}, "outputs": [], "source": [ - "!conda install -y -c conda-forge xgboost scikit-learn" + "!conda install -y -c conda-forge xgboost" ] }, { @@ -140,7 +141,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "train_set, valid_set, test_set = get_dataset()\n", @@ -165,7 +168,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import xgboost as xgb\n", @@ -191,7 +196,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "model_file_name = \"locally-trained-xgboost-model\"\n", @@ -217,7 +224,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "fObj = open(\"model.tar.gz\", 'rb')\n", @@ -238,7 +247,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest',\n", @@ -356,7 +367,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "runtime_client = boto3.client('sagemaker-runtime')" @@ -372,12 +385,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "import numpy as np\n", - "point_X = test_X[:1]\n", - "point_y = test_y[:1]\n", + "point_X = test_X[0]\n", + "point_X = np.expand_dims(point_X, axis=0)\n", + "point_y = test_y[0]\n", "np.savetxt(\"test_point.csv\", point_X, delimiter=\",\")" ] }, @@ -397,7 +413,7 @@ " payload = f.read().strip()\n", "\n", "response = runtime_client.invoke_endpoint(EndpointName=endpoint_name, \n", - " ContentType='text/x-libsvm', \n", + " ContentType='text/csv', \n", " Body=payload)\n", "result = response['Body'].read().decode('ascii')\n", "print('Predicted Class Probabilities: {}.'.format(result))" @@ -417,8 +433,7 @@ "metadata": {}, "outputs": [], "source": [ - "arr = result[1:len(result)-1].split(',')\n", - "floatArr = np.array(arr).astype(np.float)\n", + "floatArr = np.array(json.loads(result))\n", "predictedLabel = np.argmax(floatArr)\n", "print('Predicted Class Label: {}.'.format(predictedLabel))\n", "print('Actual Class Label: {}.'.format(point_y))" @@ -436,7 +451,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "collapsed": true + }, "outputs": [], "source": [ "# sm_client.delete_endpoint(EndpointName=endpoint_name)" @@ -446,7 +463,7 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Environment (conda_python3)", + "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, @@ -460,7 +477,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.3" + "version": "3.6.2" }, "notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." },