Retail Sales

Problem description

Forecasting sales of a product or service plays an important role in the lifecycle of almost every retail company. There are multiple reasons why it is essential to know the future sales. It can drive plenty of management decisions such as efficient inventory management, preventing or early detection of potential issues, price setting, marketing and other.

Data recommendation template

The dataset can contain various factors that company tracks or estimates which could help forecasting future sales. These could be internal factors such as number of stores, number of employees, level of product/service, product portfolio size or external factors such as economic and industry conditions, rate of inflation and other. Of course, only those should be selected that are relevant for company’s business case and affect sales of the product. The second condition is not so strict – TIM engine can deal with irrelevant predictors, simply they won’t be included in model building. Some of these metrics can also be estimated into the future. For example, company probably knows price of the product or number of stores in a near future.

TIM setup

TIM requires no setup of TIM’s mathematical internals and works well in business user mode. All that is required from a user is to let TIM know forecasting routine and desired prediction horizon. It is often the case that there are some seasonal patterns in product sales time series, usually daily weekly or yearly. These will be detected by TIM engine automatically if the WeekRest, PeriodicComponents and TimeOffsets dictionaries are turned on (by default they are).

Demo example

Data description

Dataset used in this example has daily sampling rate and contains data from 2014-01-01 to 2016-07-31. Prepared dataset can be downloaded here.

Pic27.png

Target

Target variable represents daily sales of a product.

Predictor candidates

There are two predictor candidates – stock price and product price.

Forecasting scenario

We simulate week ahead scenario – each day at 20:00 we want to forecast target one week into the future. In other words, the forecasting horizon is one week. We assume that last known value of stock price predictor is from last day and last value of target is from current day (although we want to forecast at 20:00 and the value of target for current day is not available until end of the day, we can estimate this value with information about sales until 20:00). The value of product price predictor is known for the entire forecasting horizon.

Model building and validation

Model is built using a range of 2014-01-01 00:00:00 – 2015-12-31 00:00:00. Out of sample forecasts are made on range 2016-01-01 00:00:00 – 2016-07-31 00:00:00.


Demonstration

TIM Studio

This section covers the use of TIM Studio to solve the challenge described above. Additional information regarding TIM Studio can be found here.

Select workspace

In the Workspaces screen, select the workspace in which the dataset should be added. If there is no available workspace, create one by clicking "Add Workspace". In this solution template, the workspace called "TIM Solution Templates" is used.

obr1.PNG

Upload data

In the Datasets screen click on Add New Dataset. Stay in the tab CSV-File and insert name of the dataset. In this example, the dataset is called Retail_sales. Click "Browse" and select the dataset from the computer. Click "Add Dataset" to confirm.

image.png image.png

Model building definition

Go to the Model Building Definition screen in the panel on the left. Click "Add New Definition" and fill in the desired definition name. In this demo, the MBD is called Retail_sales_def. In the next screen, select the dataset that was previously uploaded (Retail_sales).

image.png

In step 2, define the desired forecasting scenario. In this example, the model is used each day at 20:00. Therefore, leave all Weekdays ranges checked on. Then, set Hour ranges to 20 and leave Minutes ranges and Seconds ranges at 00. Look into the section about the Cron notation for more details. Since forecasts are to be made starting one day ahead until seven days ahead, set "Forecast from" to Day with offset 1 and set "Forecast to" to Day with offset 7. Look into the section about the relative time notation to learn more about this.

image.png

Click "Next" to advance to the next step. It is also possible to already finalize all settings at this point, in which case everything else would be set up automatically. In this example, some more changes will be made to the data updates in the third step. The target variable, product_sales, is updated each day at 19:00. Click on the small arrow next to product_sales and change the settings of this variable. Leave all Weekdays ranges checked on. Set Hour ranges to 19 and leave Minutes ranges and Seconds ranges at 00. Then, set "Update until" to Day with offset 0, since the target variable is updated until the end of current day.

image.png

Similar setting of data updates is needed also for both predictors. Both predictors are updated at the same time as target (each day at 19:00), therefore, set the "Update when" same as for target variable. Then, set the "Update until" to Day with offset -1 for stock_price predictor and to Day with offset 7 for product_price since they are updated until the end of last day and until the end of forecasting horizon respectively.

image.png image.png

Click "Next" to advance to step 4. Here, training regions can be selected. Since the goal is to move on to back-testing, this screen will be left in its default settings (i.e. Use All Data). Click "Next" to advance to the next screen.

image.png

In this fifth step, the mathematical settings can be changed. We can leave it in default configuration and click "Finalize" to complete the model building definition.

image.png

Experiments

Click "Experiments" in the panel on the left to move on to back-testing. Then, click "Make experiment" next to the correct model building definition (Retail_sales_def).

image.png

Click "Build Model" and select the appropriate training range, i.e. 2014-01-01 00:00:00 - 2015-12-31 00:00:00.

image.png

The in-sample prediction as well as the Model Tree Map become visible.

image.png

Click "Validate model" and select the correct Out-of-sample period for back-testing, i.e. 2016-01-01 00:00:00 - 2016-07-31 00:00:00.

image.png

This generates the aggregated forecasts from D+0 to D+7.

image.png

TIM Connector

This section covers the use of TIM Connector to solve the challenge described above. Additional information regarding TIM Connector can be found in the respective section.

1. Download TIM Connector

You can find download links in TIM Connector's section.

2. Create folder with dataset

Create folder e.g. TIM_Datasets which contains dataset folder (Retail_sales) with the dataset file [data.csv] and the configuration file [conf.yaml].

TIM_Datasets/Retail_sales/ data.csv conf.yaml

The YAML configuration file defines the forecasting scenario described above.

Model building: Model building considers the range 2014-01-01 00:00:00 - 2015-12-31 00:00:00. Target and both predictors are updated every day at 19:00. Target is updated until the end of current day, predictor stock_price is updated until the end of last day and predictor product_price is updated until the end of forecasting horizon.

Configuration: Model is used repeatedly each day at 20:00. Forecasts are made from one to seven days ahead (week ahead).

Forecasting: Out-of-sample forecasts are made for the range 2016-01-01 00:00:00 - 2016-07-31 00:00:00.

The content of the exemplary YAML configuration file is shown below:

version: "1.0"
type: Forecasting

modelBuilding:
  data:
    rows:
    - from: 2014-01-01 00:00:00
      to:   2015-12-31 00:00:00
    updates:
    - uniqueName: product_sales
      updateUntil:
        baseUnit: Day
        offset: 0
      updateTime:
      - type: Day
        value: "*"
      - type: Hour
        value: "19"
    - uniqueName: stock_price
      updateUntil:
        baseUnit: Day
        offset: -1
      updateTime:
      - type: Day
        value: "*"
      - type: Hour
        value: "19"
    - uniqueName: product_price
      updateUntil:
        baseUnit: Day
        offset: 7
      updateTime:
      - type: Day
        value: "*"
      - type: Hour
        value: "19"
  configuration:
    usage:
      usageType: Repeating
      usageTime:
      - type: Day
        value: "*"
      - type: Hour
        value: "20"
      predictionFrom:
        baseUnit: Day
        offset: 1
      predictionTo:
        baseUnit: Day
        offset: 7
forecasting:
  configuration:
    predictionScope:
      type: Ranges
      ranges:
      - from: 2016-01-01 00:00:00
        to:   2016-07-31 00:00:00
3. Call connector from the command line

Using a terminal, change the current directory to TIM Connector's builddir with the command: > cd pathToConnector\builddir. Then, call the connector with the following command: > pathToConnector\timconnect.exe path\to\TIM_Datasets.

4. Fill in user credentials

Following the previous command, the user will be prompted to fill in their user credentials. Fill in the correct information and click "OK" to continue.

login.png

Output in console:

Pic28.png

Output in folder: Predictions Report/timeStamp/conf/prediction.csv Errors Report/timeStamp/conf/accuracy.txt The following accuracies were reported by TIM: Model building stage: RMSE = 51.72, MAE = 36.15 Validation stage: RMSE = 58.31, MAE = 43.44