|
684 | 684 | "metadata": {},
|
685 | 685 | "outputs": [],
|
686 | 686 | "source": [
|
687 |
| - "boto3.client(\"s3\").copy(\n", |
688 |
| - " {\n", |
689 |
| - " \"Bucket\": \"amazon-reviews-pds\",\n", |
690 |
| - " \"Key\": \"tsv/amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n", |
691 |
| - " },\n", |
692 |
| - " bucket,\n", |
693 |
| - " prefix + \"/train/amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n", |
| 687 | + "s3 = boto3.client(\"s3\")\n", |
| 688 | + "s3.download_file(\n", |
| 689 | + " f\"amazon-reviews-pds\",\n", |
| 690 | + " \"tsv/amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n", |
| 691 | + " \"amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n", |
| 692 | + ")\n", |
| 693 | + "\n", |
| 694 | + "sagemaker.Session().upload_data(\n", |
| 695 | + " \"amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\", key_prefix=prefix + \"/train\"\n", |
694 | 696 | ")"
|
695 | 697 | ]
|
696 | 698 | },
|
|
753 | 755 | "metadata": {},
|
754 | 756 | "outputs": [],
|
755 | 757 | "source": [
|
756 |
| - "predictor = m.deploy(initial_instance_count=1, instance_type=\"ml.m4.xlarge\")\n", |
757 |
| - "predictor.serializer = None" |
| 758 | + "predictor = m.deploy(initial_instance_count=1, instance_type=\"ml.m4.xlarge\")" |
758 | 759 | ]
|
759 | 760 | },
|
760 | 761 | {
|
|
773 | 774 | "outputs": [],
|
774 | 775 | "source": [
|
775 | 776 | "predictor.predict(\n",
|
776 |
| - " json.dumps(\n", |
777 |
| - " {\n", |
778 |
| - " \"customer_id\": customer_index[customer_index[\"user\"] == 6][\n", |
779 |
| - " \"customer_id\"\n", |
780 |
| - " ].values.tolist(),\n", |
781 |
| - " \"product_id\": [\"B00KH1O9HW\", \"B00M5KODWO\"],\n", |
782 |
| - " }\n", |
783 |
| - " )\n", |
| 777 | + " {\n", |
| 778 | + " \"customer_id\": customer_index[customer_index[\"user\"] == 6][\"customer_id\"].values.tolist(),\n", |
| 779 | + " \"product_id\": [\"B00KH1O9HW\", \"B00M5KODWO\"],\n", |
| 780 | + " }\n", |
784 | 781 | ")"
|
785 | 782 | ]
|
786 | 783 | },
|
|
829 | 826 | "test_preds = []\n",
|
830 | 827 | "for array in np.array_split(test_df[[\"customer_id\", \"product_id\"]].values, 40):\n",
|
831 | 828 | " test_preds += predictor.predict(\n",
|
832 |
| - " json.dumps({\"customer_id\": array[:, 0].tolist(), \"product_id\": array[:, 1].tolist()})\n", |
| 829 | + " {\"customer_id\": array[:, 0].tolist(), \"product_id\": array[:, 1].tolist()}\n", |
833 | 830 | " )\n",
|
834 | 831 | "\n",
|
835 | 832 | "test_preds = np.array(test_preds)\n",
|
|
872 | 869 | "predictions = []\n",
|
873 | 870 | "for array in np.array_split(product_index[\"product_id\"].values, 40):\n",
|
874 | 871 | " predictions += predictor.predict(\n",
|
875 |
| - " json.dumps(\n", |
876 |
| - " {\n", |
877 |
| - " \"customer_id\": customer_index[customer_index[\"user\"] == 6][\n", |
878 |
| - " \"customer_id\"\n", |
879 |
| - " ].values.tolist()\n", |
880 |
| - " * array.shape[0],\n", |
881 |
| - " \"product_id\": array.tolist(),\n", |
882 |
| - " }\n", |
883 |
| - " )\n", |
| 872 | + " {\n", |
| 873 | + " \"customer_id\": customer_index[customer_index[\"user\"] == 6][\n", |
| 874 | + " \"customer_id\"\n", |
| 875 | + " ].values.tolist()\n", |
| 876 | + " * array.shape[0],\n", |
| 877 | + " \"product_id\": array.tolist(),\n", |
| 878 | + " }\n", |
884 | 879 | " )\n",
|
885 | 880 | "\n",
|
886 | 881 | "predictions = pd.DataFrame({\"product_id\": product_index[\"product_id\"], \"prediction\": predictions})"
|
|
917 | 912 | "predictions_user7 = []\n",
|
918 | 913 | "for array in np.array_split(product_index[\"product_id\"].values, 40):\n",
|
919 | 914 | " predictions_user7 += predictor.predict(\n",
|
920 |
| - " json.dumps(\n", |
921 |
| - " {\n", |
922 |
| - " \"customer_id\": customer_index[customer_index[\"user\"] == 7][\n", |
923 |
| - " \"customer_id\"\n", |
924 |
| - " ].values.tolist()\n", |
925 |
| - " * array.shape[0],\n", |
926 |
| - " \"product_id\": array.tolist(),\n", |
927 |
| - " }\n", |
928 |
| - " )\n", |
| 915 | + " {\n", |
| 916 | + " \"customer_id\": customer_index[customer_index[\"user\"] == 7][\n", |
| 917 | + " \"customer_id\"\n", |
| 918 | + " ].values.tolist()\n", |
| 919 | + " * array.shape[0],\n", |
| 920 | + " \"product_id\": array.tolist(),\n", |
| 921 | + " }\n", |
929 | 922 | " )\n",
|
930 | 923 | "plt.scatter(predictions[\"prediction\"], np.array(predictions_user7))\n",
|
931 | 924 | "plt.show()"
|
|
964 | 957 | "metadata": {},
|
965 | 958 | "outputs": [],
|
966 | 959 | "source": [
|
967 |
| - "sagemaker.Session().delete_endpoint(predictor.endpoint)" |
| 960 | + "predictor.delete_model()\n", |
| 961 | + "predictor.delete_endpoint()" |
968 | 962 | ]
|
969 | 963 | }
|
970 | 964 | ],
|
971 | 965 | "metadata": {
|
972 | 966 | "celltoolbar": "Tags",
|
| 967 | + "instance_type": "ml.g4dn.xlarge", |
973 | 968 | "kernelspec": {
|
974 |
| - "display_name": "conda_mxnet_p36", |
| 969 | + "display_name": "Python 3 (MXNet 1.6 Python 3.6 GPU Optimized)", |
975 | 970 | "language": "python",
|
976 |
| - "name": "conda_mxnet_p36" |
| 971 | + "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-west-2:236514542706:image/mxnet-1.6-gpu-py36" |
977 | 972 | },
|
978 | 973 | "language_info": {
|
979 | 974 | "codemirror_mode": {
|
|
985 | 980 | "name": "python",
|
986 | 981 | "nbconvert_exporter": "python",
|
987 | 982 | "pygments_lexer": "ipython3",
|
988 |
| - "version": "3.6.10" |
| 983 | + "version": "3.6.13" |
989 | 984 | },
|
990 | 985 | "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."
|
991 | 986 | },
|
|
0 commit comments