Skip to content

Commit 1497d47

Browse files
committed
Fixed xgboost_customer_churn.ipynb after code review
1. Remove the old import of SDK V1. 2. Added imports for TrainingInput and CSVSerializer to keep code cleaner. 3. The check_neo_region was removed since it is not supported in SDK v2, and from Sep 26, 2019, Amazon SageMaker Neo is Available in 12 additional Regions. 5. get_image_uri in Neo compilation was removed since it is not needed at all. 5. Moved the print of cutoffs, and costs to a diffferent cell since it used to throw an error on the first run.
1 parent d6202d5 commit 1497d47

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

introduction_to_applying_machine_learning/xgboost_customer_churn/xgboost_customer_churn.ipynb

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@
9292
"import json\n",
9393
"from IPython.display import display\n",
9494
"from time import strftime, gmtime\n",
95-
"import sagemaker\n",
96-
"from sagemaker.predictor import csv_serializer"
95+
"from sagemaker.inputs import TrainingInput\n",
96+
"from sagemaker.serializers import CSVSerializer"
9797
]
9898
},
9999
{
@@ -331,7 +331,6 @@
331331
"metadata": {},
332332
"outputs": [],
333333
"source": [
334-
"from sagemaker.amazon.amazon_estimator import get_image_uri\n",
335334
"container = sagemaker.image_uris.retrieve('xgboost', boto3.Session().region_name, '1')\n",
336335
"display(container)"
337336
]
@@ -340,7 +339,7 @@
340339
"cell_type": "markdown",
341340
"metadata": {},
342341
"source": [
343-
"Then, because we're training with the CSV file format, we'll create `s3_input`s that our training function can use as a pointer to the files in S3."
342+
"Then, because we're training with the CSV file format, we'll create `TrainingInput`s that our training function can use as a pointer to the files in S3."
344343
]
345344
},
346345
{
@@ -349,8 +348,8 @@
349348
"metadata": {},
350349
"outputs": [],
351350
"source": [
352-
"s3_input_train = sagemaker.inputs.TrainingInput(s3_data='s3://{}/{}/train'.format(bucket, prefix), content_type='csv')\n",
353-
"s3_input_validation = sagemaker.inputs.TrainingInput(s3_data='s3://{}/{}/validation/'.format(bucket, prefix), content_type='csv')"
351+
"s3_input_train = TrainingInput(s3_data='s3://{}/{}/train'.format(bucket, prefix), content_type='csv')\n",
352+
"s3_input_validation = TrainingInput(s3_data='s3://{}/{}/validation/'.format(bucket, prefix), content_type='csv')"
354353
]
355354
},
356355
{
@@ -416,8 +415,7 @@
416415
" framework='xgboost',\n",
417416
" framework_version='latest',\n",
418417
" output_path=output_path)\n",
419-
"compiled_model.name = 'deployed-xgboost-customer-churn'\n",
420-
"compiled_model.image = get_image_uri(sess.boto_region_name, 'xgboost-neo', repo_version='latest')"
418+
"compiled_model.name = 'deployed-xgboost-customer-churn'"
421419
]
422420
},
423421
{
@@ -439,7 +437,7 @@
439437
"xgb_predictor = compiled_model.deploy(\n",
440438
" initial_instance_count = 1, \n",
441439
" instance_type = 'ml.m4.xlarge',\n",
442-
" serializer=sagemaker.serializers.CSVSerializer())"
440+
" serializer=CSVSerializer())"
443441
]
444442
},
445443
{
@@ -590,7 +588,15 @@
590588
"\n",
591589
"costs = np.array(costs)\n",
592590
"plt.plot(cutoffs, costs)\n",
593-
"plt.show()\n",
591+
"plt.show()"
592+
]
593+
},
594+
{
595+
"cell_type": "code",
596+
"execution_count": null,
597+
"metadata": {},
598+
"outputs": [],
599+
"source": [
594600
"print('Cost is minimized near a cutoff of:', cutoffs[np.argmin(costs)], 'for a cost of:', np.min(costs))"
595601
]
596602
},
@@ -651,6 +657,18 @@
651657
"language": "python",
652658
"name": "conda_python3"
653659
},
660+
"language_info": {
661+
"codemirror_mode": {
662+
"name": "ipython",
663+
"version": 3
664+
},
665+
"file_extension": ".py",
666+
"mimetype": "text/x-python",
667+
"name": "python",
668+
"nbconvert_exporter": "python",
669+
"pygments_lexer": "ipython3",
670+
"version": "3.6.10"
671+
},
654672
"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."
655673
},
656674
"nbformat": 4,

0 commit comments

Comments
 (0)