|
26 | 26 | "---\n",
|
27 | 27 | "## Background\n",
|
28 | 28 | "\n",
|
29 |
| - "Amazon SageMaker includes functionality to support a hosted notebook environment, distributed, serverless training, and real-time, autoscaling 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", |
| 29 | + "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", |
30 | 30 | "\n",
|
31 | 31 | "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",
|
32 | 32 | "\n",
|
|
44 | 44 | "cell_type": "code",
|
45 | 45 | "execution_count": null,
|
46 | 46 | "metadata": {
|
| 47 | + "collapsed": true, |
47 | 48 | "isConfigCell": true
|
48 | 49 | },
|
49 | 50 | "outputs": [],
|
|
80 | 81 | {
|
81 | 82 | "cell_type": "code",
|
82 | 83 | "execution_count": null,
|
83 |
| - "metadata": {}, |
| 84 | + "metadata": { |
| 85 | + "collapsed": true |
| 86 | + }, |
84 | 87 | "outputs": [],
|
85 | 88 | "source": [
|
86 | 89 | "!conda install -y -c conda-forge xgboost scikit-learn"
|
|
96 | 99 | {
|
97 | 100 | "cell_type": "code",
|
98 | 101 | "execution_count": null,
|
99 |
| - "metadata": {}, |
| 102 | + "metadata": { |
| 103 | + "collapsed": true |
| 104 | + }, |
100 | 105 | "outputs": [],
|
101 | 106 | "source": [
|
102 | 107 | "%%time\n",
|
|
119 | 124 | {
|
120 | 125 | "cell_type": "code",
|
121 | 126 | "execution_count": null,
|
122 |
| - "metadata": {}, |
| 127 | + "metadata": { |
| 128 | + "collapsed": true |
| 129 | + }, |
123 | 130 | "outputs": [],
|
124 | 131 | "source": [
|
125 | 132 | "%%time\n",
|
|
140 | 147 | {
|
141 | 148 | "cell_type": "code",
|
142 | 149 | "execution_count": null,
|
143 |
| - "metadata": {}, |
| 150 | + "metadata": { |
| 151 | + "collapsed": true |
| 152 | + }, |
144 | 153 | "outputs": [],
|
145 | 154 | "source": [
|
146 | 155 | "train_set, valid_set, test_set = get_dataset()\n",
|
|
165 | 174 | {
|
166 | 175 | "cell_type": "code",
|
167 | 176 | "execution_count": null,
|
168 |
| - "metadata": {}, |
| 177 | + "metadata": { |
| 178 | + "collapsed": true |
| 179 | + }, |
169 | 180 | "outputs": [],
|
170 | 181 | "source": [
|
171 | 182 | "import xgboost as xgb\n",
|
|
191 | 202 | {
|
192 | 203 | "cell_type": "code",
|
193 | 204 | "execution_count": null,
|
194 |
| - "metadata": {}, |
| 205 | + "metadata": { |
| 206 | + "collapsed": true |
| 207 | + }, |
195 | 208 | "outputs": [],
|
196 | 209 | "source": [
|
197 | 210 | "model_file_name = \"locally-trained-xgboost-model\"\n",
|
|
201 | 214 | {
|
202 | 215 | "cell_type": "code",
|
203 | 216 | "execution_count": null,
|
204 |
| - "metadata": {}, |
| 217 | + "metadata": { |
| 218 | + "collapsed": true |
| 219 | + }, |
205 | 220 | "outputs": [],
|
206 | 221 | "source": [
|
207 | 222 | "!tar czvf model.tar.gz $model_file_name"
|
|
217 | 232 | {
|
218 | 233 | "cell_type": "code",
|
219 | 234 | "execution_count": null,
|
220 |
| - "metadata": {}, |
| 235 | + "metadata": { |
| 236 | + "collapsed": true |
| 237 | + }, |
221 | 238 | "outputs": [],
|
222 | 239 | "source": [
|
223 | 240 | "fObj = open(\"model.tar.gz\", 'rb')\n",
|
|
238 | 255 | {
|
239 | 256 | "cell_type": "code",
|
240 | 257 | "execution_count": null,
|
241 |
| - "metadata": {}, |
| 258 | + "metadata": { |
| 259 | + "collapsed": true |
| 260 | + }, |
242 | 261 | "outputs": [],
|
243 | 262 | "source": [
|
244 | 263 | "containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/xgboost:latest',\n",
|
|
251 | 270 | {
|
252 | 271 | "cell_type": "code",
|
253 | 272 | "execution_count": null,
|
254 |
| - "metadata": {}, |
| 273 | + "metadata": { |
| 274 | + "collapsed": true |
| 275 | + }, |
255 | 276 | "outputs": [],
|
256 | 277 | "source": [
|
257 | 278 | "%%time\n",
|
|
282 | 303 | "source": [
|
283 | 304 | "### Create endpoint configuration\n",
|
284 | 305 | "\n",
|
285 |
| - "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 and the autoscaling configuration." |
| 306 | + "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." |
286 | 307 | ]
|
287 | 308 | },
|
288 | 309 | {
|
289 | 310 | "cell_type": "code",
|
290 | 311 | "execution_count": null,
|
291 |
| - "metadata": {}, |
| 312 | + "metadata": { |
| 313 | + "collapsed": true |
| 314 | + }, |
292 | 315 | "outputs": [],
|
293 | 316 | "source": [
|
294 | 317 | "from time import gmtime, strftime\n",
|
|
318 | 341 | {
|
319 | 342 | "cell_type": "code",
|
320 | 343 | "execution_count": null,
|
321 |
| - "metadata": {}, |
| 344 | + "metadata": { |
| 345 | + "collapsed": true |
| 346 | + }, |
322 | 347 | "outputs": [],
|
323 | 348 | "source": [
|
324 | 349 | "%%time\n",
|
|
356 | 381 | {
|
357 | 382 | "cell_type": "code",
|
358 | 383 | "execution_count": null,
|
359 |
| - "metadata": {}, |
| 384 | + "metadata": { |
| 385 | + "collapsed": true |
| 386 | + }, |
360 | 387 | "outputs": [],
|
361 | 388 | "source": [
|
362 | 389 | "runtime_client = boto3.client('sagemaker-runtime')"
|
|
372 | 399 | {
|
373 | 400 | "cell_type": "code",
|
374 | 401 | "execution_count": null,
|
375 |
| - "metadata": {}, |
| 402 | + "metadata": { |
| 403 | + "collapsed": true |
| 404 | + }, |
376 | 405 | "outputs": [],
|
377 | 406 | "source": [
|
378 | 407 | "import numpy as np\n",
|
|
384 | 413 | {
|
385 | 414 | "cell_type": "code",
|
386 | 415 | "execution_count": null,
|
387 |
| - "metadata": {}, |
| 416 | + "metadata": { |
| 417 | + "collapsed": true |
| 418 | + }, |
388 | 419 | "outputs": [],
|
389 | 420 | "source": [
|
390 | 421 | "%%time\n",
|
|
414 | 445 | {
|
415 | 446 | "cell_type": "code",
|
416 | 447 | "execution_count": null,
|
417 |
| - "metadata": {}, |
| 448 | + "metadata": { |
| 449 | + "collapsed": true |
| 450 | + }, |
418 | 451 | "outputs": [],
|
419 | 452 | "source": [
|
420 | 453 | "arr = result[1:len(result)-1].split(',')\n",
|
|
435 | 468 | {
|
436 | 469 | "cell_type": "code",
|
437 | 470 | "execution_count": null,
|
438 |
| - "metadata": {}, |
| 471 | + "metadata": { |
| 472 | + "collapsed": true |
| 473 | + }, |
439 | 474 | "outputs": [],
|
440 | 475 | "source": [
|
441 | 476 | "# sm_client.delete_endpoint(EndpointName=endpoint_name)"
|
442 | 477 | ]
|
443 | 478 | }
|
444 | 479 | ],
|
445 | 480 | "metadata": {
|
| 481 | + "anaconda-cloud": {}, |
446 | 482 | "kernelspec": {
|
447 |
| - "display_name": "Environment (conda_python3)", |
| 483 | + "display_name": "Python [conda root]", |
448 | 484 | "language": "python",
|
449 |
| - "name": "conda_python3" |
| 485 | + "name": "conda-root-py" |
450 | 486 | },
|
451 | 487 | "language_info": {
|
452 | 488 | "codemirror_mode": {
|
453 | 489 | "name": "ipython",
|
454 |
| - "version": 3 |
| 490 | + "version": 2 |
455 | 491 | },
|
456 | 492 | "file_extension": ".py",
|
457 | 493 | "mimetype": "text/x-python",
|
458 | 494 | "name": "python",
|
459 | 495 | "nbconvert_exporter": "python",
|
460 |
| - "pygments_lexer": "ipython3", |
461 |
| - "version": "3.6.3" |
| 496 | + "pygments_lexer": "ipython2", |
| 497 | + "version": "2.7.12" |
462 | 498 | },
|
463 | 499 | "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."
|
464 | 500 | },
|
|
0 commit comments