{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualize forecast\n", "In this notebook, you will visualize the results predicted by Amazon Forecast." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Get your exported forecast filename in S3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "sts = boto3.client('sts')\n", "id_info = sts.get_caller_identity()\n", "print(id_info['Account'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bucket_name = 'workshop-timeseries-retail-' + id_info['Account'] + '-source'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "bucket_name" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import re\n", "s3 = boto3.resource('s3')\n", "bucket = s3.Bucket(bucket_name)\n", "for obj in bucket.objects.filter(Prefix='output/'):\n", " if re.search('part0.csv$', obj.key):\n", " file = re.sub('^output/', '', obj.key)\n", "print(file)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download forecast result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import boto3\n", "\n", "s3 = boto3.resource('s3') \n", "bucket = s3.Bucket(bucket_name)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!mkdir -p ./exported_forecast\n", "bucket.download_file(f'output/{file}', './exported_forecast/result.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualization" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forecast = pd.read_csv('./exported_forecast/result.csv')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forecast.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "forecast.plot(x=forecast.columns[1],figsize=(20, 10),title='EC Sales Forecast of United Kingdom',grid=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the end of the workshop. I hope you've seen how easy it is to build a pipeline through simple code. This notebook allowed us to visualize the results of our predictions in a simple way, and with the integration of Amazon QuickSight, we can also visualize them in a dashboard." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Next\n", "Finally, For cleaning up the environment by running 4_clean.ipynb." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "conda_python3", "language": "python", "name": "conda_python3" }, "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.6.10" } }, "nbformat": 4, "nbformat_minor": 4 }