{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting the test dataset prepared in Lab `1-DataPrep`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's load the test dataset from the previous lab 1-DataPrep.\n", "\n", "(If you want, just run all cells. Go to the top toolbar click on `Run -> Run All Cells`)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import boto3\n", "import sagemaker\n", "\n", "sess = boto3.Session()\n", "sm = sess.client('sagemaker')\n", "role = sagemaker.get_execution_role()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set the paths for the datasets saved locally\n", "local_test_path = 'test.csv'\n", "test_df = pd.read_csv(local_test_path, header=None)\n", "\n", "pd.set_option('display.max_columns', 500) # Make sure we can see all of the columns\n", "pd.set_option('display.max_rows', 10) # Keep the output on one page\n", "test_df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you remember from the previous data preparation lab, we saved the CSV without headers and the features engineered." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we'll upload the file to S3 for testing." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store -r bucket\n", "%store -r prefix" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "test_dir = f\"{prefix}/data/test\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Upload test dataset to S3\n", "s3uri_test = sagemaker.s3.S3Uploader.upload(local_test_path, f\"s3://{bucket}/{test_dir}\")\n", "s3uri_test" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Moving the data to the main directory of this lab:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!cp test-dataset.csv ../" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Uploading the model trained in the previous 2-Modeling lab to S3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s3uri_model = sagemaker.s3.S3Uploader.upload(\"model.tar.gz\", f\"s3://{bucket}/{prefix}/model\")\n", "s3uri_model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Saving variables to use in the main notebook for this lab" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you want to see in the console, go to S3 and verify the 2 CSV files are there:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.core.display import display, HTML\n", "s3_url_placeholder = \"https://s3.console.aws.amazon.com/s3/buckets/{}?&prefix={}/\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "display(HTML(f\"S3 Test object\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Saving variables to use in the main notebook for this lab" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store test_dir" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store s3uri_test" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%store s3uri_model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[You can now go back to evaluation.ipynb](../evaluation.ipynb)" ] } ], "metadata": { "instance_type": "ml.t3.medium", "kernelspec": { "display_name": "Python 3 (Data Science)", "language": "python", "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.10" } }, "nbformat": 4, "nbformat_minor": 4 }