{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting the dataset prepared in Lab `1-DataPrep`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's load the dataset with the features we engineered in 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_train_path = 'train.csv'\n",
"train_df = pd.read_csv(local_train_path, header=None)\n",
"train_df.head()\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",
"train_df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Let's check the validation dataset\n",
"local_validation_path = 'validation.csv'\n",
"validation_df = pd.read_csv(local_validation_path, header=None)\n",
"validation_df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you remember from previous lab, we saved the CSV without headers. CSV with headers are stored in `config/training-dataset-with-header.csv`.\n",
"\n",
"To see our train set with headers:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pd.read_csv(\"training-dataset-with-header.csv\").head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we'll upload the files to S3 for training."
]
},
{
"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": [
"train_dir = f\"{prefix}/data/train\"\n",
"val_dir = f\"{prefix}/data/validation\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Return the URLs of the uploaded file, so they can be reviewed or used elsewhere\n",
"s3uri_train = sagemaker.s3.S3Uploader.upload(local_train_path, 's3://{}/{}'.format(bucket, train_dir))\n",
"s3uri_validation = sagemaker.s3.S3Uploader.upload(local_validation_path, 's3://{}/{}'.format(bucket, val_dir))"
]
},
{
"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 Train object\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(HTML(f\"S3 Validation 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 train_dir\n",
"%store val_dir\n",
"%store s3uri_train\n",
"%store s3uri_validation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[You can now go back to modeling.ipynb](../modeling.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-2:429704687514: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
}