

 Amazon Forecast is no longer available to new customers. Existing customers of Amazon Forecast can continue to use the service as normal. [Learn more"](https://aws.amazon.com/blogs/machine-learning/transition-your-amazon-forecast-usage-to-amazon-sagemaker-canvas/)

# Data aggregation for different forecast frequencies
<a name="data-aggregation"></a>

 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.

**Topics**
+ [How Aggregation Works](how-aggregation-works.md)
+ [Time Boundaries](#time-boundaries)
+ [Data Aggregation Assumptions](aggregation-guidelines.md)

# How Aggregation Works
<a name="how-aggregation-works"></a>

 During training, Amazon Forecast aggregates any data that does not align with the forecast frequency you specify. For example, you might have some daily data but specify a weekly forecast frequency. Forecast aligns the daily data based on the week that it belongs in. Forecast then combines it into single record for each week. Forecast determines what week (or month or day and so on) data belongs in based on its relation to a time boundary. Time boundaries specify the beginning of a unit of time, such as what hour a day begins or what day a week begins. 

 For hourly and minutely forecasts, or unspecified time boundaries, Forecast uses a default time boundary based on your frequency's unit of time. For auto predictors with daily, weekly, monthly, or yearly forecast frequencies, you can specify a custom time boundary. For more information about time boundaries, see [Time Boundaries](data-aggregation.md#time-boundaries). 

 During aggregation, the default transformation method is to sum the data. You can configure the transformation when you create your predictor. You do this in the **Input data configuration** section on the **Create predictor** page in the Forecast console. Or you can set the transformation method in the `Transformations` parameter in the [AttributeConfig](API_AttributeConfig.md) of the CreateAutoPredictor operation.

The following tables show an example aggregation for an hourly forecast frequency using the default time boundary: Each hour begins at the top of the hour.

**Pre-transformation**


| Time | Data | At Top of the Hour | 
| --- | --- | --- | 
| 2018-03-03 01:00:00 | 100 | Yes | 
| 2018-03-03 02:20:00 | 50 | No | 
| 2018-03-03 02:45:00 | 20 | No | 
| 2018-03-03 04:00:00 | 120 | Yes | 

**Post-transformation**


| Time | Data | Notes | 
| --- | --- | --- | 
| 2018-03-03 01:00:00 | 100 |  | 
| 2018-03-03 02:00:00 | 70 | Sum of the values between 02:00:00-02:59:59 (50 \$1 20) | 
| 2018-03-03 03:00:00 | Empty | No values between 03:00:00-03:59:59 | 
| 2018-03-03 04:00:00 | 120 |  | 

The following figure shows how Forecast transforms data to fit the default weekly time boundary.

![\[Raw sales data points transformed into a smooth demand time series curve over weekly intervals.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/data-alignment.png)


## Time Boundaries
<a name="time-boundaries"></a>

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.

If you specify both a custom time boundary and a custom forecast frequency, Forecast aggregates your data within the forecast frequency and aligns it to the custom time boundary. The forecast frequency determines how often the data is aggregated while the custom time boundary determines where the alignment is located. For example, assume your data is collected daily and you want Amazon Forecast to generate quarterly forecasts on the 15th of the month for one year. To do so, set the forecast frequency to every 3 months and the custom time boundary to 15. See the following AWS Command Line Interface example.

```
aws forecast create-predictor \
--predictor-name predictor_name \
--data-config DatasetGroupArn="arn:aws:forecast:region:account:dataset-group/datasetGroupName" \
--forecast-horizon 4 \
--forecast-frequency 3M \
--time-alignment-boundary DayOfMonth=15
```

In this example, all of the daily data is summed (the default aggregation) to the 15th of every third month. 

Note that this aggregation does not require daily data, just that the data is collected monthly or more frequently. 

**Topics**
+ [Default Time Boundaries](#default-time-boundaries)
+ [Specifying a Time Boundary](#specifying-time-boundary)

### Default Time Boundaries
<a name="default-time-boundaries"></a>

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
<a name="specifying-time-boundary"></a>

**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](#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 with 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](API_TimeAlignmentBoundary.md). 

------
#### [ 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/](https://console.aws.amazon.com/forecast/).

1. From **Dataset groups**, choose your dataset group.

1. In the navigation pane, choose **Predictors**.

1. Choose **Train new predictor**.

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

1.  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. 

1. 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-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](API_TimeAlignmentBoundary.md). For information on required and optional parameters, see [CreateAutoPredictor](API_CreateAutoPredictor.md).

```
aws forecast create-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](API_TimeAlignmentBoundary.md). For information on required and optional parameters, see [CreateAutoPredictor](API_CreateAutoPredictor.md).

```
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'])
```

------

# Data Aggregation Assumptions
<a name="aggregation-guidelines"></a>

Forecast doesn't assume that your data is from any specific time zone. However, it makes the following assumptions when aggregating time series data:
+ All data is from the same time zone.
+ All forecasts are in the same time zone as the data in the dataset.
+ If you specify the [SupplementaryFeature](API_SupplementaryFeature.md) holiday feature in the [InputDataConfig](API_InputDataConfig.md) parameter for the [CreatePredictor](API_CreatePredictor.md) operation, the input data is from the same country.