Demand Forecasting

Demand Forecasting

A how-to guide for specifying the input and output schemas in demand forecasting.

The demand forecasting app is available in one modeling language as a Mixed Integer Problem (MIP) formulation of Least Absolute Deviation (LAD) regression. You can also choose to make customizations to the model by instantiating the app first.

nextmv community clone -a python-ortools-demandforecasting
Copy

Once you have the code locally, you can customize the model, run it locally and deploy it to Nextmv Platform.

Input

The format for timestamps should look like the following: "2023-01-01T00:00:00".

The input schema is a JSON payload defining the timestamp and the historical demand to use for training the LAD regression model. Nextmv's tools are designed to operate directly on business data (in JSON) to produce decisions that are actionable by software systems. This makes decisions more interpretable and easier to test. It also makes integration with data warehouses and business intelligence platforms significantly easier. An input contains the following components:

Field nameRequiredData typeSI UnitDescriptionExample
timezoneYesstringNATimezone{"timezone": "America/New_York"}
demandsYesarray of demandNAAn array of historical demand.See demand

Here you can find a sample .json with the input schema:

Demand

Demand is used in the input schema.

Field nameRequiredData typeDescriptionExample
whenYestimestampThe start time of the demand block.{"when": "2019-11-15T09:00:00"}
dateYesstringThe date of the demand.{"date": "2023-01-01"}
blockYesstringThe time of day of the demand (see below).{"block": "morning"}
demandYesintegerThe amount of demand.{"demand": "1"}

The marketplace app defines the block start and end as follows:

BlockStartEnd
morning09:0012:59
midday13:0016:59
evening17:0020:59
night21:0008:59

Output

The output schema defines the solution to the demand forecasting problem in JSON format. The output schema contains the following components.

Field nameAlways presentData typeSI UnitDescriptionExample
solutionsYesarray of solutionNASolutions to the demand forecasting problem.{"solutions": []}
statisticsYesstatisticsNASummary statistics of the solution.{"statistics": {"schema": 123}}

Solution

Field nameAlways presentData typeSI UnitDescriptionExample
forecasted_demandYesarray of forecasted demandNASolution to the demand forecasting problem.{"forecasted_demand": []}

Forecasted demand

Field nameAlways presentData typeSI UnitDescriptionExample
whenYestimestampNAThe start time of the demand block.{"when": "2019-11-15T09:00:00"}
dateYesstringNAThe date of the demand.{"date": "2023-01-01"}
blockYesstringNAThe time of day of the demand.{"block": "morning"}
demandYesintegerNAThe amount of demand historically (if include-past option set to true).{"demand": "1"}
start_timeYestimestampNAThe start time of the demand block.{"start_time": "2019-11-15T09:00:00"}
end_timeYestimestampNAThe end time of the demand block.{"end_time": "2019-11-15T09:00:00"}
forecastYesfloatNAThe forecasted demand.{"forecast": "1.2"}
countYesintegerNAThe ceiling of forecasted demand.{"count": "2"}

Statistics

Field nameAlways presentData typeSI UnitDescriptionExample
resultNoresultNAFinal result of the solutions.See result
runYesrunNAInformation about the run.See run
schemaYesstringNASchema of the statistics.{"schema": "v1"}

Here you can find additional definitions used in the statistics schema:

  • result

    Field nameAlways presentData typeSI UnitDescriptionExample
    durationYesfloatsecondsTime duration to get to the final result.{"duration": 0.123}
    valueYesfloatNAValue of the final result.{"value": 0.123}
    customYesanyNACustom solver metrics.See custom
  • run

    Field nameAlways presentData typeSI UnitDescriptionExample
    durationYesfloatsecondsTime duration of the run.{"duration": 0.123}
  • custom

    Field nameAlways presentData typeSI UnitDescriptionExample
    constraintsYesintNANumber of constraints.{"constraints": 123}
    providerYesstringNASolver provider.{"provider": "highs"}
    statusYesstringNASolver status.{"status": "optimal"}
    variablesYesintNANumber of variables.{"variables": 123}

Run options

These are the default options that are available with demand forecasting.

usage: main.py [options]

Options for main.py. Use command-line arguments (highest precedence) or
environment variables.

options:
  -h, --help            show this help message and exit
  -input INPUT, --input INPUT
                        [env var: INPUT] (default: ) (type: str): Path to
                        input file. Default is stdin.
  -output OUTPUT, --output OUTPUT
                        [env var: OUTPUT] (default: ) (type: str): Path to
                        output file. Default is stdout.
  -duration DURATION, --duration DURATION
                        [env var: DURATION] (default: 30) (type: int): Max
                        runtime duration (in seconds).
  -provider PROVIDER, --provider PROVIDER
                        [env var: PROVIDER] (default: SCIP) (type: str):
                        Solver provider.
  -include_past INCLUDE_PAST, --include_past INCLUDE_PAST
                        [env var: INCLUDE_PAST] (default: False) (type: bool):
                        Include past data in forecast.
Copy

Page last updated

Go to on-page nav menu