{"nbformat": 4, "cells": [{"cell_type": "markdown", "metadata": {"_uuid": "73ca473d47c4271690a6a7b5b9cbb7bc8c5f478d", "_cell_guid": "6c36849b-d915-495e-816f-43e842d771ae"}, "source": ["This looks like fun! There's a lot of interesting data to look through:\n", "\n", "https://www.kaggle.com/c/favorita-grocery-sales-forecasting/data\n", "\n", "Here's a start. More to come..."]}, {"source": ["import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "from subprocess import check_output\n", "print(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "2afbefca27aa8a428283ee5201d69f1bf558d8a3", "_cell_guid": "03310d0d-f20a-4431-a90b-c329dba03b27"}, "execution_count": 1}, {"source": ["train = pd.read_csv('../input/train.csv')\n", "test = pd.read_csv('../input/test.csv')"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "cd1c54796bbbd38e8f22995774850787f14ae294", "_cell_guid": "3e87df5d-ea23-41ba-88d2-e081f04ed420"}, "execution_count": 2}, {"cell_type": "markdown", "metadata": {"_uuid": "69ad471ed21d65426b3fd4ce61a40e47b829b53e", "_cell_guid": "2820ea3d-af3d-4898-9801-a45d02826d55"}, "source": ["## A quick look"]}, {"cell_type": "markdown", "metadata": {"_uuid": "c97a3b979b49aecc1f34ce5c77b0b4d77e6a4892", "_cell_guid": "b6b5c3e1-ca63-4b03-8874-75f153ceec8a"}, "source": ["**train.csv**\n", "\n", "* Training data, which includes the target unit_sales by date, store_nbr, and item_nbr and a unique id to label rows.\n", "* The target unit_sales can be integer (e.g., a bag of chips) or float (e.g., 1.5 kg of cheese).\n", "* Negative values of unit_sales represent returns of that particular item.\n", "* The onpromotion column tells whether that item_nbr was on promotion for a specified date and store_nbr.\n", "* Approximately 16% of the onpromotion values in this file are NaN.\n", "\n", "NOTE: The training data does not include rows for items that had zero unit_sales for a store/date combination. There is no information as to whether or not the item was in stock for the store on the date, and teams will need to decide the best way to handle that situation. Also, there are a small number of items seen in the training data that aren't seen in the test data.\n"]}, {"source": ["print(train.shape)\n", "train.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "dfdab5c67fe5f067359f6e0ff00dbe53765a317c", "_cell_guid": "1d296a7a-6862-46c4-ba84-50aace304a20"}, "execution_count": 3}, {"cell_type": "markdown", "metadata": {"_uuid": "597148ba6f0c6b8dbfe556fc88e5816214b8fd97", "_cell_guid": "497e9f43-cb3c-49f0-85d2-c4cc3b5b3c0f"}, "source": ["**test.csv**\n", "\n", "Test data, with the date, store_nbr, item_nbr combinations that are to be predicted, along with the onpromotion information.\n", "\n", "NOTE: The test data has a small number of items that are not contained in the training data. Part of the exercise will be to predict a new item sales based on similar products..\n", "The public / private leaderboard split is based on time. All items in the public split are also included in the private split."]}, {"source": ["print(test.shape)\n", "test.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "c0668f507cef668d2d94f6140941bd9116fb3bcf", "_cell_guid": "9c0ec14e-5c8b-49dc-9136-8ce9750eec3f"}, "execution_count": 4}, {"source": ["test.tail()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "1503651ff61ec84768018f4405c4ce52285892cb", "_cell_guid": "a884f8ad-cad4-4dba-9e91-53461421245d"}, "execution_count": 5}, {"source": ["test.date.unique()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "d12f2fc80a45399c8e4b30e457be4bbfee562eca", "_cell_guid": "984ac218-030e-4214-99ed-b7bd3667f7ed"}, "execution_count": 6}, {"source": [], "cell_type": "code", "outputs": [], "metadata": {"collapsed": true, "_uuid": "93476539c52027e65174327f8fbb83028b81a9a3", "_cell_guid": "7bbd0875-7e0e-424a-bf45-7c59e54e37d6"}, "execution_count": null}, {"source": ["sub = pd.read_csv('../input/sample_submission.csv')\n", "print(sub.shape)\n", "sub.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "380c792d51e49eec78d24cefcb0bd84e1cda1f2d", "_cell_guid": "8de66219-6ac3-4159-8a1b-2f89cdad0b14"}, "execution_count": 7}, {"source": [], "cell_type": "code", "outputs": [], "metadata": {"collapsed": true, "_uuid": "f9c148cf7a51f7ad470726aafa5a22bd06b920b3", "_cell_guid": "a7aa9df3-3efe-4dec-96db-5cf060fae043"}, "execution_count": null}, {"source": ["stores = pd.read_csv('./../input/stores.csv')\n", "print(stores.shape)\n", "stores.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "8e3827a110dfe66f1232db9e0e7cba1015c3ab8f", "_cell_guid": "01bd50b2-914e-44f5-87f3-e028109ca4e8"}, "execution_count": 8}, {"cell_type": "markdown", "metadata": {"_uuid": "c16b2c2db0a755c93fdd72c0d97e3ab7a52280a6", "_cell_guid": "da3c2d17-1c2f-4bd8-9913-dd3698721ce2"}, "source": [" **Note**: type and cluster?"]}, {"source": ["items = pd.read_csv('./../input/items.csv')\n", "print(items.shape)\n", "items.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "5ff260c28531849c8780d3e96fb28251bb95ace0", "_cell_guid": "e26af83a-00b0-4fcf-a80d-83f640e92cb0"}, "execution_count": 9}, {"cell_type": "markdown", "metadata": {"_uuid": "5bcf7e76dae64b7484cfe4952fea99b066a73dec", "_cell_guid": "724a1761-b9b7-4ede-b907-92c59879a86c"}, "source": ["**Note**: class?"]}, {"source": ["oil = pd.read_csv('./../input/oil.csv')\n", "print(oil.shape)\n", "oil.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "8242f2c64ca84ed8e2b95c5816ee2ea6bcf04e6a", "_cell_guid": "35eaead9-2d00-405d-9a8a-fbf4c807be87"}, "execution_count": 10}, {"cell_type": "markdown", "metadata": {"_uuid": "60422f52ba2ea3fd573edc5e5db4ec03e211b87e", "_cell_guid": "080f6aca-91a9-4094-8d1d-b1633fad1f76"}, "source": ["Wut?"]}, {"source": ["transactions = pd.read_csv('./../input/transactions.csv')\n", "print(transactions.shape)\n", "transactions.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "2c899881bde91ec2469aca54c392e2745f684d80", "_cell_guid": "21b349b8-42b4-4e1c-b55a-46ed7e0cfffd"}, "execution_count": 11}, {"cell_type": "markdown", "metadata": {"_uuid": "e700dec734b431487cfa035e6b6b864425548edc", "_cell_guid": "3c45e4cc-1e65-4f88-94e8-c4cd26b86284"}, "source": ["Do we need this? Seems superfluous.\n", "\n", "## Exploring Individual Stores\n", "\n", "### store_nbr == 1"]}, {"source": ["store = train[train.store_nbr == 1]"], "cell_type": "code", "outputs": [], "metadata": {"collapsed": true, "_uuid": "4ac199e2db6371817fa45bcf94c3526855697657", "_cell_guid": "4401092a-81ba-4134-83ae-2fdbcb0295e1"}, "execution_count": 12}, {"source": ["store.head()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "62d3a01eb43c3769bf480b34d9aeb526bf23ca19", "_cell_guid": "4c8a3cf9-42cd-4370-808b-988f70aea135"}, "execution_count": 13}, {"source": ["store.item_nbr.unique()"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "58404f74ead7bb1e7011092d29b28ea4b8aba1b1", "_cell_guid": "2bcd3079-dda8-492e-9580-fd4183ca4bce"}, "execution_count": 14}, {"cell_type": "markdown", "metadata": {"_uuid": "e19ffd869aaad94bc7e2d02c1c89102136b0e3e5", "_cell_guid": "b9243374-e01a-469a-9ff4-75a13464e78b"}, "source": ["#### item_nbr == 103665"]}, {"source": ["example = store[store.item_nbr == 103665][['date', 'unit_sales']]\n", "\n", "example.plot( figsize=(13, 8))"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "68dd18355d1fc3e08f1fc433c0bdf8ac20ee75e3", "_cell_guid": "17b9b5b0-5112-4aa5-af5c-2b9e7bdd5e16"}, "execution_count": 15}, {"source": ["example['cum_sales'] = example.unit_sales.cumsum()\n", "\n", "example.plot( figsize=(13, 8))"], "cell_type": "code", "outputs": [], "metadata": {"_uuid": "304734df35fa7b9c70782e852928a0f39cbe5681", "_cell_guid": "b521523f-947a-49aa-b63c-1b2880b9c5d4"}, "execution_count": 16}, {"cell_type": "markdown", "metadata": {}, "source": ["# Baseline Model\n", " \n", " Coming Soon!"]}, {"source": ["def get_store(store):\n", "    df_store = train[train.store_nbr == store][['date', 'item_nbr', 'unit_sales']]\n", "    return df_store\n", "\n", "\n", "def store_itemize(df_store, item):\n", "    df_item = df_store[df_store.item_nbr == item][['date', 'unit_sales']]\n", "    df_item.index = pd.DatetimeIndex(df_item.date)\n", "    idx = pd.date_range('2013-01-09', '2017-08-31')\n", "    df_item = df_item.reindex(idx, fill_value=df_item.unit_sales.mean())\n", "    del df_item['date']\n", "    df_item['cum_sum'] = df_item.unit_sales.cumsum()\n", "    return df_item\n", "\n", "\n", "df_store = get_store(1)\n", "df_item = store_itemize(df_store, 103665)\n", "df_item.head()\n", "\n", "# for store in train.store_nbr.unique():\n", "#     df_store = get_store(store)\n", "#     for item in df_store.item_nbr.unique():\n", "#         df_item = store_itemize(df_store, item)"], "cell_type": "code", "outputs": [], "metadata": {}, "execution_count": 40}, {"source": ["df_item.tail()"], "cell_type": "code", "outputs": [], "metadata": {}, "execution_count": 42}, {"source": [], "cell_type": "code", "outputs": [], "metadata": {"collapsed": true}, "execution_count": null}], "metadata": {"language_info": {"codemirror_mode": {"version": 3, "name": "ipython"}, "nbconvert_exporter": "python", "version": "3.6.3", "pygments_lexer": "ipython3", "file_extension": ".py", "mimetype": "text/x-python", "name": "python"}, "kernelspec": {"name": "python3", "language": "python", "display_name": "Python 3"}}, "nbformat_minor": 1}