{"cells":[{"cell_type":"markdown","metadata":{"_cell_guid":"abadbc5b-bedd-3b74-cca0-c0c267cca6ce"},"source":"**Objective**: Demand forecasting for a bakery manufacturer with over 1M stores and 45,000 routes across Mexico, over 100 products. Minimize empty shelves and refunds due to returns.\n\n**Notes**:\n\n- Forecast the demand for a given product in a given week. Each week we have sales and returns and the demand is defined as sales - next week's returns.\n- There are new products in the test set. This is just the nature of this business.\n- One Client_id may have more than one NombreCliente\n- Adjusted demand (Demanda_uni_equil) is always >= 0. Venta_uni_hoy - Dev_uni_proxima is sometimes negative b/c carrying over returns for few weeks.\n\n**Files**:\n\n - train\n - test\n - sample_submission\n - cliente_tabla: Client table (can be joined on Cliente_ID)\n - producto_tabla: Product table (can be joined on Producto_ID)\n - town_state: Can be joined on Agencia_ID\n\n**Data Fields**:\n\n- Semana — Week number (From Thursday to Wednesday)\n- Agencia_ID — Sales Depot ID\n- Canal_ID — Sales Channel ID\n- Ruta_SAK — Route ID (Several routes = Sales Depot)\n- Cliente_ID — Client ID\n- NombreCliente — Client name\n- Producto_ID — Product ID\n- NombreProducto — Product Name\n- Venta_uni_hoy — Sales unit this week (integer)\n- Venta_hoy — Sales this week (unit: pesos)\n- Dev_uni_proxima — Returns unit next week (integer)\n- Dev_proxima — Returns next week (unit: pesos)\n- Demanda_uni_equil — Adjusted Demand (integer) (This is the target you will predict)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0f4a01d1-2154-b11c-c746-31993aaaa035"},"outputs":[],"source":"# This R environment comes with all of CRAN preinstalled, as well as many other helpful packages\n# The environment is defined by the kaggle/rstats docker image: https://github.com/kaggle/docker-rstats\n# For example, here's several helpful packages to load in \n\nlibrary(ggplot2) # Data visualization\nlibrary(readr) # CSV file I/O, e.g. the read_csv function\n# readr introduction: \n# https://cran.r-project.org/web/packages/readr/vignettes/readr.html\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nsystem(\"ls ../input\")\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3c1a32bf-3e61-4421-d208-dc21fdffaae5"},"outputs":[],"source":"train_spec <- spec_csv(\"../input/train.csv\")\ntrain <- read_csv(\"../input/train.csv\",\n                 col_types= cols(\n                 .default = col_integer(),\n                 Venta_hoy = col_double(),\n                 Dev_proxima = col_double()))\n#client <- read_csv(\"../input/cliente_tabla.csv\")\n#product <- read_csv(\"../input/producto_tabla.csv\")\n#town <- read_csv(\"../input/town_state.csv\")\n#train_spec"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"a9aa852b-0ecb-ce6b-413b-d154388e7d76"},"outputs":[],"source":"head(train)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"29166226-b211-05a9-7583-1ef5867b4786"},"outputs":[],"source":"ggplot(train %>% sample_frac(0.005))+\n  geom_histogram(aes(x=Semana), color=\"black\", fill=\"red\", alpha=0.5)+\n  scale_x_continuous(breaks=1:10)+\n  scale_y_continuous(name=\"Client / Product deliveries\")+\n  theme_bw()\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"16f1b7f4-df33-0535-b176-a806f297ae2f"},"outputs":[],"source":""},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f5e1ad9c-202e-0a08-0eb2-d7eeab6660b5"},"outputs":[],"source":""},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"afd999e8-bd46-1237-be50-5957535a1db2"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"codemirror_mode":"r","file_extension":".r","mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"3.4.0"}},"nbformat":4,"nbformat_minor":0}