Data aggregation for different forecast frequencies - Amazon Forecast

Data aggregation for different forecast frequencies

When you create a predictor, you must specify a forecast frequency. The forecast frequency determines the frequency of predictions in your forecasts. For example, monthly sales forecasts. Amazon Forecast predictors can generate forecasts for data frequencies that are higher than the forecast frequency you specify. For example, you can generate weekly forecasts even if your data is recorded daily. During training, Forecast aggregates the daily data to generate forecasts at the weekly forecast frequency.

Time Boundaries

Time boundaries specify the beginning of a unit of time, such what day a week begins. Before aggregating your data, Amazon Forecast aligns the data the based on the unit of time of your forecast frequency. It does this based on the data's relation to a time boundary.

For example, if you specify a daily forecast frequency but not your own time boundary, Forecast aligns each hourly record based on the day it belongs in. Each day starts at 0 hours. The definition of when the day starts, 0 hours, is the time boundary. Then Forecast aggregates the hourly records to a single record for that day.

Forecast uses a default time boundary based on your forecast frequency's unit of time. If you create an auto predictor, you can specify a custom time boundary.

Default Time Boundaries

The following table lists the default time alignment boundaries that Forecast uses when aggregating data.

Frequency Boundary
Minute Last top of the minute (45:00, 06:00)
Hour Last top of the hour (09:00:00, 13:00:00)
Day First hour of the day (hour 0)
Week Most recent Monday
Month First day of the month
Year First day of the year (January 1)

Specifying a Time Boundary

Note

You can only specify a time boundary for an auto predictor.

When you create an auto predictor with a daily, weekly, monthly, or yearly forecast frequency, you can specify the time boundary that Forecast uses to aggregate data. You might specify a time boundary if your business calendar doesn't align with the default time boundaries. For example, you might want to generate monthly forecasts where each month begins on the third day of the month. If you don't specify a time boundary, Forecast uses a set of default time boundaries.

The time boundary unit that you specify must be one unit finer than your forecast frequency. The following table lists the time boundary unit and values that you can specify, organized by forecast frequency.

You can only specify a Monthly time boundary and a boundary value of 28 or less.

Forecast frequency unit Boundary unit Boundary values
Daily Hour 0–23
Weekly Day of week Monday through Sunday
Monthly Day of month 1 through 28
Yearly Month January through December

You specify a time alignment boundary when you create a predictor as follows. For information on the different time boundary units and boundary values you can specify programmatically, see TimeAlignmentBoundary.

Console

To specify a time alignment boundary for a predictor

  1. Sign in to the AWS Management Console and open the Amazon Forecast console at https://console.aws.amazon.com/forecast/.

  2. From Dataset groups, choose your dataset group.

  3. In the navigation pane, choose Predictors.

  4. Choose Train new predictor.

  5. Provide values for the mandatory Name, Forecast frequency, and Forecast horizon fields.

  6. For Time alignment boundary, specify the time boundary the predictor will use when aggregating your data. The values in this list depend on the Forecast frequency you choose.

  7. Choose Start. Forecast will aggregate data using the time alignment boundary you specify as it creates your predictor.

AWS CLI

To specify a time alignment boundary for a predictor with the AWS CLI, use the create-auto-predictor command. For the time-alignment-boundary parameter, provide the unit of time and boundary value. The following code creates an auto predictor that makes predictions for 5 weeks in the future, where each week starts on a Tuesday.

DayOfWeek and DayOfMonth values must be in all uppercase. For information on the different time boundary units and boundary values you can specify, see TimeAlignmentBoundary. For information on required and optional parameters, see CreateAutoPredictor.

aws forecast create-auto-predictor \ --predictor-name predictor_name \ --data-config DatasetGroupArn="arn:aws:forecast:region:account:dataset-group/datasetGroupName" \ --forecast-horizon 5 \ --forecast-frequency W \ --time-alignment-boundary DayOfWeek=TUESDAY
Python

To specify a time alignment boundary for a predictor with the SDK for Python (Boto3), use the create_auto_predictor method. For the TimeAlignmentBoundary parameter, provide a dictionary with the unit of time as the key and boundary value as the value. The following code creates an auto predictor that makes predictions for 5 weeks in the future, where each week starts on a Tuesday.

DayOfWeek and DayOfMonth values must be in all uppercase. For information on the different time boundary units and boundary values you can specify, see TimeAlignmentBoundary. For information on required and optional parameters, see CreateAutoPredictor.

import boto3 forecast = boto3.client('forecast') create_predictor_response = forecast.create_auto_predictor( PredictorName = 'predictor_name', ForecastHorizon = 5, ForecastFrequency = 'W', DataConfig = { "DatasetGroupArn": "arn:aws:forecast:region:account:dataset-group/datasetGroupName" }, TimeAlignmentBoundary = { "DayOfWeek": "TUESDAY" } ) print(create_predictor_response['PredictorArn'])