

 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/)

# Training Predictors


A predictor is an Amazon Forecast model that is trained using your target time series, related time series, item metadata, and any additional datasets you include. You can use predictors to generate forecasts based on your time-series data. 

By default, Amazon Forecast creates an AutoPredictor, where Forecast applies the optimal combination of algorithms to each time series in your datasets.

**Topics**
+ [

## Creating a Predictor
](#creating-predictors)
+ [

## Upgrading to AutoPredictor
](#upgrading-autopredictor)
+ [

# Data aggregation for different forecast frequencies
](data-aggregation.md)
+ [

## Using additional datasets
](#using-additional-datasets)
+ [

## Working with legacy predictors
](#legacy-predictors)
+ [

# Evaluating Predictor Accuracy
](metrics.md)
+ [

# Retraining Predictors
](retrain-predictors.md)
+ [

# Weather Index
](weather.md)
+ [

# Holidays Featurization
](holidays.md)
+ [

# Predictor Explainability
](predictor-explainability.md)
+ [

# Predictor Monitoring
](predictor-monitoring.md)
+ [

# Amazon Forecast Algorithms
](aws-forecast-choosing-recipes.md)

## Creating a Predictor


Amazon Forecast requires the following inputs to train a predictor:
+ **Dataset group** – A dataset group that must include a target time series dataset. The target time series dataset includes the target attribute (`item_id`) and timestamp attribute, as well as any dimensions. Related time series and Item metadata is optional. For more information, see [Importing Datasets](howitworks-datasets-groups.md).
+ **Forecast frequency** – The granularity of your forecasts (hourly, daily, weekly, etc). Amazon Forecast lets you determine the exact granularity of your forecasts when you provide the frequency unit and value. Only integer values are allowed    
[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/howitworks-predictor.html)

  For example, if you want every other week forecasts, your frequency unit is weekly and the value is 2. Or, if you want quarterly forecasts, your frequency unit is monthly and the value is 3.

  When your data is collected at a greater frequency than the forecast frequency, it is aggregated to the forecast frequency. This includes the trailing time series and related time series data. For more information on aggregation see [Data aggregation for different forecast frequencies](data-aggregation.md).
+ **Forecast horizon** – The number of time steps being forecasted.

You can also set values for the following optional inputs:
+  **Time alignment boundary** – The time boundary Forecast uses to aggregate your data and generate forecasts that align with the forecast frequency you specify. For more information on aggregation see [Data aggregation for different forecast frequencies](data-aggregation.md). For information on specifying a time boundary see [Time Boundaries](data-aggregation.md#time-boundaries). 
+ **Forecast dimensions** – Dimensions are optional attributes in your target time series dataset that can be used in combination with the target value (`item_id`) to create separate time series.
+ **Forecast types** – The quantiles used to evaluate your predictor.
+ **Optimization metric** – The accuracy metric used to optimize your predictor.
+ **Additional datasets** – Built-in Amazon Forecast datasets like the Weather Index and Holidays.

You can create a predictor using the Software Development Kit (SDK) or the Amazon Forecast console.

------
#### [ Console ]

**To create 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 following mandatory fields:
   +  **Name** - a unique predictor name.
   + **Forecast frequency** - the granularity of your forecasts.
   + **Forecast horizon** - The number of time steps to forecast.

1. Choose **Start**.

For information on additional datasets, see [Weather Index](weather.md) and [Holidays Featurization](holidays.md). To learn more about customizing forecast types and optimization metrics, see [Evaluating Predictor Accuracy](metrics.md).

------
#### [ AWS CLI ]

To create an auto predictor with the AWS CLI, use the `create-predictor` command. The following code creates an auto predictor that makes predictions for 14 days in the future. 

Provide a name for the predictor and the Amazon Resource Name (ARN) of the dataset group that includes your training data. Optionally modify the forecast horizon and forecast frequency. Optionally add any tags for the predictor. For more information see [Tagging Amazon Forecast Resources](tagging-forecast-resources.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 14 \
--forecast-frequency D \
--tags Key=key1,Value=value1 Key=key2,Value=value2
```

To learn more about customizing forecast types and optimization metrics, see [Evaluating Predictor Accuracy](metrics.md) The Weather Index and Holidays additional datasets are defined within the `DataConfig` datatype. For information on additional datasets, see [Weather Index](weather.md) and [Holidays Featurization](holidays.md).

------
#### [ Python ]

To create an auto predictor with the SDK for Python (Boto3), use the `create_auto_predictor` method. The following code creates an auto predictor that makes predictions for 14 days in the future. 

Provide a name for the predictor and the Amazon Resource Name (ARN) of the dataset group that includes your training data. Optionally modify the forecast horizon and forecast frequency. Optionally add any tags for the predictor. For more information see [Tagging Amazon Forecast Resources](tagging-forecast-resources.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 = 14,
    ForecastFrequency = 'D',
    DataConfig = {
      "DatasetGroupArn": "arn:aws:forecast:region:account:dataset-group/datasetGroupName"
    },
    Tags = [ 
      { 
         "Key": "key1",
         "Value": "value1"
      },
      { 
         "Key": "key2",
         "Value": "value2"
      }
    ]
)
print(create_predictor_response['PredictorArn'])
```

To learn more about customizing forecast types and optimization metrics, see [Evaluating Predictor Accuracy](metrics.md) The Weather Index and Holidays additional datasets are defined within the `DataConfig` datatype. For information on additional datasets, see [Weather Index](weather.md) and [Holidays Featurization](holidays.md).

------

## Upgrading to AutoPredictor


**Python notebooks**  
For a step-by-step guide on upgrading predictors to AutoPredictor, see [Upgrading a predictor to AutoPredictor](https://github.com/aws-samples/amazon-forecast-samples/blob/main/notebooks/basic/Upgrading_to_AutoPredictor/UpgradeToAutoPredictor.ipynb).

Predictors created with AutoML or manual selection (CreatePredictor) can be upgraded to an AutoPredictor. Upgrading an existing to AutoPredictor will transfer all the relevant predictor configuration settings.

After Upgrading to AutoPredictor, the original predictor will remain active and the upgraded predictor will have a separate Predictor ARN. This enables you to compare accuracy metrics between the two predictors, and you can still generate forecasts with the original predictor.

You can upgrade a predictor using the Software Development Kit (SDK) or the Amazon Forecast console.

------
#### [ Console ]

**To upgrade 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. In the navigation pane, choose **Predictors**.

1. Choose the predictor to upgrade, and choose **Upgrade**.

1. Set a unique name for the upgraded predictor.

1. Choose **Upgrade to AutoPredictor**.

------
#### [ CLI ]

To upgrade a predictor with the AWS CLI, use the `create-predictor` method, but specify *only* the predictor name and the value of `reference-predictor-arn` (the ARN of the predictor you want to upgrade). 

```
aws forecast create-predictor \
--predictor-name predictor_name \
--reference-predictor-arn arn:aws:forecast:region:account:predictor/predictorName
```

------
#### [ Python ]

To upgrade a predictor with the SDK for Python (Boto3), use the `create_auto_predictor` method, but specify *only* the predictor name and the value of `ReferencePredictorArn` (the ARN of the predictor you want to upgrade). 

```
import boto3
            
forecast = boto3.client('forecast')

create_predictor_response = forecast.create_auto_predictor(
    PredictorName = 'predictor_name',
    ReferencePredictorArn = 'arn:aws:forecast:region:account:predictor/predictorName'
)
print(create_predictor_response['PredictorArn'])
```

------

# Data aggregation for different forecast frequencies
Data Aggregation

 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


 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


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


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](#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


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.

## Using additional datasets


Amazon Forecast can include the Weather Index and Holidays when creating your predictor. The Weather Index incorporates meteorological information into your model and Holidays incorporates information regarding national holidays.

The Weather Index requires a ‘geolocation’ attribute in your target time series dataset and information regarding time zones for your timestamps. For more information, see [Weather Index](weather.md).

Holidays includes holiday information on over 250 countries. For more information, see [Holidays Featurization](holidays.md).

## Working with legacy predictors


**Note**  
To upgrade an existing predictor to AutoPredictor, see [Upgrading to AutoPredictor](#upgrading-autopredictor)

AutoPredictor is the default and preferred method to create a predictor with Amazon Forecast. AutoPredictor creates predictors by applying the optimal combination of algorithms for each time series in your dataset.

Predictors created with AutoPredictor are generally more accurate than predictors created with AutoML or manual selection. The Forecast Explainability and predictor retraining features are only available for predictors created with AutoPredictor.

Amazon Forecast can also create legacy predictors in the following ways:

1. **AutoML** - Forecast finds the best-performing algorithm and applies it to your entire dataset.

1. **Manual selection** - Manually choose a single algorithm that is applied to your entire dataset.

You might be able to create a legacy predictor using the Software Development Kit (SDK).

------
#### [ SDK ]

**To use AutoML**

Using the [`CreatePredictor`](API_CreatePredictor.md) operation, set the value of `PerformAutoML` to `"true"`.

```
{
    ...
    "PerformAutoML": "true",
}
```

If you use AutoML, you cannot set a value for the following CreatePredictor parameters: `AlgorithmArn`, `HPOConfig`, `TrainingParameters`.

------

# Evaluating Predictor Accuracy
Predictor Metrics

Amazon Forecast produces accuracy metrics to evaluate predictors and help you choose which to use to generate forecasts. Forecast evaluates predictors using Root Mean Square Error (RMSE), Weighted Quantile Loss (wQL), Mean Absolute Percentage Error (MAPE), Mean Absolute Scaled Error (MASE), and Weighted Absolute Percentage Error (WAPE) metrics.

Amazon Forecast uses backtesting to tune parameters and produce accuracy metrics. During backtesting, Forecast automatically splits your time-series data into two sets: a training set and a testing set. The training set is used to train a model and generate forecasts for data points within the testing set. Forecast evaluates the model's accuracy by comparing forecasted values with observed values in the testing set.

Forecast enables you to evaluate predictors using different forecast types, which can be a set of quantile forecasts and the mean forecast. The mean forecast provides a point estimate, whereas quantile forecasts typically provide a range of possible outcomes.

**Python notebooks**  
For a step-by-step guide on evaluating predictor metrics, see [Computing Metrics Using Item-level Backtests.](https://github.com/aws-samples/amazon-forecast-samples/blob/master/notebooks/advanced/Item_Level_Accuracy/Item_Level_Accuracy_Using_Bike_Example.ipynb).

**Topics**
+ [

## Interpreting Accuracy Metrics
](#predictor-metrics)
+ [

## Weighted Quantile Loss (wQL)
](#metrics-wQL)
+ [

## Weighted Absolute Percentage Error (WAPE)
](#metrics-WAPE)
+ [

## Root Mean Square Error (RMSE)
](#metrics-RMSE)
+ [

## Mean Absolute Percentage Error (MAPE)
](#metrics-mape)
+ [

## Mean Absolute Scaled Error (MASE)
](#metrics-mase)
+ [

## Exporting Accuracy Metrics
](#backtest-exports)
+ [

## Choosing Forecast Types
](#forecast-types)
+ [

## Working With Legacy Predictors
](#legacy-metrics)

## Interpreting Accuracy Metrics


 Amazon Forecast provides Root Mean Square Error (RMSE), Weighted Quantile Loss (wQL), Average Weighted Quantile Loss (Average wQL), Mean Absolute Scaled Error (MASE), Mean Absolute Percentage Error (MAPE), and Weighted Absolute Percentage Error (WAPE) metrics to evaluate your predictors. Along with metrics for the overall predictor, Forecast calculates metrics for each backtest window.

You can view accuracy metrics for your predictors using the Amazon Forecast Software Development Kit (SDK) and the Amazon Forecast console.

------
#### [ Forecast SDK ]

Using the [GetAccuracyMetrics](API_GetAccuracyMetrics.md) Operation, specif y your `PredictorArn` to view the RMSE, MASE, MAPE, WAPE, Average wQL, and wQL metrics for each backtest.

```
{
    "PredictorArn": "arn:aws:forecast:region:acct-id:predictor/example-id"
}
```

------
#### [ Forecast Console ]

Choose your predictor on the **Predictors** page. Accuracy metrics for the predictor are shown in the **Predictor metrics** section. 

------

**Note**  
 For Average wQL, wQL, RMSE, MASE, MAPE, and WAPE metrics, a lower value indicates a superior model. 

**Topics**
+ [

## Interpreting Accuracy Metrics
](#predictor-metrics)
+ [

## Weighted Quantile Loss (wQL)
](#metrics-wQL)
+ [

## Weighted Absolute Percentage Error (WAPE)
](#metrics-WAPE)
+ [

## Root Mean Square Error (RMSE)
](#metrics-RMSE)
+ [

## Mean Absolute Percentage Error (MAPE)
](#metrics-mape)
+ [

## Mean Absolute Scaled Error (MASE)
](#metrics-mase)
+ [

## Exporting Accuracy Metrics
](#backtest-exports)
+ [

## Choosing Forecast Types
](#forecast-types)
+ [

## Working With Legacy Predictors
](#legacy-metrics)

## Weighted Quantile Loss (wQL)


The Weighted Quantile Loss (wQL) metric measures the accuracy of a model at a specified quantile. It is particularly useful when there are different costs for underpredicting and overpredicting. By setting the weight (*τ*) of the wQL function, you can automatically incorporate differing penalties for underpredicting and overpredicting.

The loss function is calculated as follows.

![\[Mathematical equation for weighted quantile loss function with tau parameter.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/metrics-quantile-loss.png)


Where:  
*τ* - a quantile in the set \$10.01, 0.02, ..., 0.99\$1  
qi,t(τ) - the τ-quantile that the model predicts.  
yi,t - the observed value at point (i,t)

The quantiles (τ) for wQL can range from 0.01 (P1) to 0.99 (P99). The wQL metric cannot be calculated for the mean forecast.

By default, Forecast computes wQL at `0.1` (P10), `0.5` (P50), and `0.9` (P90).
+ **P10 (0.1)** - The true value is expected to be lower than the predicted value 10% of the time.
+ **P50 (0.5)** - The true value is expected to be lower than the predicted value 50% of the time. This is also known as the median forecast.
+ **P90 (0.9)** - The true value is expected to be lower than the predicted value 90% of the time.

In retail, the cost of being understocked is often higher than the cost of being overstocked, and so forecasting at P75 (*τ* = 0.75) can be more informative than forecasting at the median quantile (P50). In these cases, wQL[0.75] assigns a larger penalty weight to underforecasting (0.75) and a smaller penalty weight to overforecasting (0.25). 

![\[Two probability distribution curves showing demand forecasting at P50 and P75 quantiles.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/p50-p75-prediction.jpg)


The figure above shows the differing demand forecasts at wQL[0.50] and wQL[0.75]. The forecasted value at P75 is significantly higher than the forecasted value at P50 because the P75 forecast is expected to meet demand 75% of the time, whereas the P50 forecast is only expected to meet demand 50% of the time.

When the sum of observed values over all items and time points is approximately zero in a given backtest window, the weighted quantile loss expression is undefined. In these cases, Forecast outputs the unweighted quantile loss, which is the numerator in the wQL expression.

Forecast also calculates the average wQL, which is the mean value of weighted quantile losses over all specified quantiles. By default, this will be the average of wQL[0.10], wQL[0.50], and wQL[0.90].

## Weighted Absolute Percentage Error (WAPE)


The Weighted Absolute Percentage Error (WAPE) measures the overall deviation of forecasted values from observed values. WAPE is calculated by taking the sum of observed values and the sum of predicted values, and calculating the error between those two values. A lower value indicates a more accurate model.

 When the sum of observed values for all time points and all items is approximately zero in a given backtest window, the weighted absolute percentage error expression is undefined. In these cases, Forecast outputs the unweighted absolute error sum, which is the numerator in the WAPE expression. 

![\[Mathematical formula for WAPE showing summation of absolute differences divided by sum of absolute values.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/WAPE.png)


Where:  
yi,t - the observed value at point (i,t)  
ŷi,t - the predicted value at point (i,t)

 Forecast uses the mean forecast as the predicted value, ŷi,t. 

WAPE is more robust to outliers than Root Mean Square Error (RMSE) because it uses the absolute error instead of the squared error.

Amazon Forecast previously referred to the WAPE metric as the Mean Absolute Percentage Error (MAPE) and used the median forecast (P50) as the predicted value. Forecast now uses the mean forecast to calculate WAPE. The wQL[0.5] metric is equivalent to the WAPE[median] metric, as shown below:

![\[Mathematical equation showing the equivalence of wQL[0.5] and WAPE[median] metrics.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/wql-to-wape.PNG)


## Root Mean Square Error (RMSE)


Root Mean Square Error (RMSE) is the square root of the average of squared errors, and is therefore more sensitive to outliers than other accuracy metrics. A lower value indicates a more accurate model.

![\[Mathematical formula for Root Mean Square Error (RMSE) with summation and square root.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/metrics-rmse.png)


Where:  
yi,t - the observed value at point (i,t)  
ŷi,t - the predicted value at point (i,t)  
nT - the number of data points in a testing set

Forecast uses the mean forecast as the predicted value, ŷi,t. When calculating predictor metrics, nT is the number of data points in a backtest window. 

RMSE uses the squared value of the residuals, which amplifies the impact of outliers. In use cases where only a few large mispredictions can be very costly, the RMSE is the more relevant metric.

Predictors created before November 11, 2020 calculated RMSE using the 0.5 quantile (P50) by default. Forecast now uses the mean forecast.

## Mean Absolute Percentage Error (MAPE)


Mean Absolute Percentage Error (MAPE) takes the absolute value of the percentage error between observed and predicted values for each unit of time, then averages those values. A lower value indicates a more accurate model.

![\[Mathematical formula for Mean Absolute Percentage Error (MAPE) calculation.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/mape.png)


Where:  
At - the observed value at point *t*  
Ft - the predicted value at point *t*  
n - the number of data points in the time series

Forecast uses the mean forecast as the predicted value, Ft.

MAPE is useful for cases where values differ significantly between time points and outliers have a significant impact.

## Mean Absolute Scaled Error (MASE)


Mean Absolute Scaled Error (MASE) is calculated by dividing the average error by a scaling factor. This scaling factor is dependent on the seasonality value, *m*, which is selected based on the forecast frequency. A lower value indicates a more accurate model.

![\[Mathematical formula for Mean Absolute Scaled Error (MASE) with summation and absolute value notations.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/mase.png)


Where:  
Yt - the observed value at point *t*  
Yt-m - the observed value at point *t-m*  
ej - the error at point *j* (observed value - predicted value)  
m - the seasonality value

Forecast uses the mean forecast as the predicted value.

MASE is ideal for datasets that are cyclical in nature or have seasonal properties. For example, forecasting for items that are in high demand during summers and in low demand during winters can benefit from taking into account the seasonal impact.

## Exporting Accuracy Metrics


**Note**  
Export files can directly return information from the Dataset Import. This makes the files vulnerable to CSV injection if the imported data contains formulas or commands. For this reason, exported files can prompt security warnings. To avoid malicious activity, disable links and macros when reading exported files.

Forecast enables you to export forecasted values and accuracy metrics generated during backtesting.

You can use these exports to evaluate specific items at specific time points and quantiles, and better understand your predictor. The backtest exports are sent to a specified S3 location and contains two folders:
+ **forecasted-values**: Contains CSV or Parquet files with forecasted values at each forecast type for each backtest.
+ **accuracy-metrics-values**: Contains CSV or Parquet files with metrics for each backtest, along with the average across all backtests. These metrics include wQL for each quantile, Average wQL,RMSE, MASE, MAPE, and WAPE.

The `forecasted-values` folder contains forecasted values at each forecast type for each backtest window. It also includes information on item IDs, dimensions, timestamps, target values, and backtest window start and end times.

The `accuracy-metrics-values` folder contains accuracy metrics for each backtest window, as well as the average metrics across all backtest windows. It contains wQL metrics for each specified quantile, as well as Average wQL, RMSE, MASE, MAPE, and WAPE metrics.

Files within both folders follow the naming convention: `<ExportJobName>_<ExportTimestamp>_<PartNumber>.csv`. 

You can export accuracy metrics using the Amazon Forecast Software Development Kit (SDK) and the Amazon Forecast console.

------
#### [ Forecast SDK ]

Using the [`CreatePredictorBacktestExportJob`](API_CreatePredictorBacktestExportJob.md) operation, specify your S3 location and IAM role in the [`DataDestination`](API_DataDestination.md) object, along with the `PredictorArn` and `PredictorBacktestExportJobName`.

For example:

```
{
   "Destination": { 
      "S3Config": { 
         "Path": "s3://bucket/example-path/",
         "RoleArn": "arn:aws:iam::000000000000:role/ExampleRole"
      }
   },
   "Format": PARQUET;
   "PredictorArn": "arn:aws:forecast:region:predictor/example",
   "PredictorBacktestExportJobName": "backtest-export-name",
}
```

------
#### [ Forecast Console ]

Choose your predictor on the **Predictors** page. In the **Predictor metrics** section, choose **Export backtest results**.

During the **Create predictor backtest export** stage, set the **Export name**, **IAM Role**, and **S3 predictor backtest export location** fields.

![\[Form for exporting predictor backtest data to S3, with fields for name, IAM role, and location.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/console-export-screen.PNG)


------

## Choosing Forecast Types


Amazon Forecast uses forecast types to create predictions and evaluate predictors. Forecast types come in two forms:
+ **Mean forecast type** - A forecast using the mean as the expected value. Typically used as point forecasts for a given time point.
+ **Quantile forecast type** - A forecast at a specified quantile. Typically used to provide a prediction interval, which is a range of possible values to account for forecast uncertainty. For example, a forecast at the `0.65` quantile will estimate a value that is lower than the observed value 65% of the time.

By default, Forecast uses the following values for the predictor forecast types: `0.1` (P10), `0.5` (P50), and `0.9` (P90). You can choose up to five custom forecast types, including `mean` and quantiles ranging from `0.01` (P1) to `0.99` (P99).

Quantiles can provide an upper and lower bound for forecasts. For example, using the forecast types `0.1` (P10) and `0.9` (P90) provides a range of values known as an 80% confidence interval. The observed value is expected to be lower than the P10 value 10% of the time, and the P90 value is expected to be higher than the observed value 90% of the time. By generating forecasts at p10 and P90, you can expect the true value to fall between those bounds 80% of the time. This range of values is depicted by the shaded region between P10 and P90 in the figure below.

![\[Graph showing forecast quantiles with P99, P90, P50, P10, and P1 lines over time.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/quantiles-intervals.png)


You can also use a quantile forecast as a point forecast when the cost of underpredicting differs from the cost of overpredicting. For example, in some retail cases the cost of being understocked is higher than the cost of being overstocked. In these cases, the forecast at 0.65 (P65) is more informative than the median (P50) or mean forecast.

When training a predictor, you can choose custom forecast types using the Amazon Forecast Software Development Kit (SDK) and Amazon Forecast console. 

------
#### [ Forecast SDK ]

Using the [`CreateAutoPredictor`](API_CreateAutoPredictor.md) operation, specify the custom forecast types in the `ForecastTypes` parameter. Format the parameter as an array of strings.

For example, to create a predictor at the `0.01`, `mean`, `0.65`, and `0.99` forecast types, use the following code.

```
{
    "ForecastTypes": [ "0.01", "mean", "0.65", "0.99" ],
},
```

------
#### [ Forecast Console ]

During the **Train Predictor** stage, specify the custom forecast types in the **Forecast types** field. Choose **Add new forecast type** and enter a forecast type value.

 For example, to create a predictor using the `0.01`, `mean`, `0.65`, and `0.99` forecast types, enter the following values in the **Forecast types** fields shown below.

![\[Form for entering forecast types with fields for type names and quantile values between .01 and .99.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/predictor-custom-quantiles.png)


------

## Working With Legacy Predictors


### Setting Backtesting Parameters


Forecast uses backtesting to calculate accuracy metrics. If you run multiple backtests, Forecast averages each metric over all backtest windows. By default, Forecast computes one backtest, with the size of the backtest window (testing set) equal to the length of the forecast horizon (prediction window). You can set both the *backtest window length* and the *number of backtest scenarios* when training a predictor.

Forecast omits filled values from the backtesting process, and any item with filled values within a given backtest window will be excluded from that backtest. This is because Forecast only compares forecasted values with observed values during backtesting, and filled values are not observed values.

The backtest window must be at least as large as the forecast horizon, and smaller than half the length of the entire target time-series dataset. You can choose from between 1 and 5 backtests.

![\[Graph showing training and testing periods for four backtest scenarios over time.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/evaluation-backtests.png)


Generally, increasing the number of backtests produces more reliable accuracy metrics, since a larger portion of the time series is used during testing and Forecast is able to take an average of metrics across all backtests.

You can set the backtesting parameters using the Amazon Forecast Software Development Kit (SDK) and the Amazon Forecast console.

------
#### [ Forecast SDK ]

Using the [CreatePredictor](API_CreatePredictor.md) operation, set the backtest parameters in the [EvaluationParameters](API_EvaluationParameters.md) datatype. Specify the length of the testing set during backtesting with the `BackTestWindowOffset` parameter, and the number of backtest windows with the `NumberOfBacktestWindows` parameter.

For example, to run 2 backtests with a testing set of 10 time points, use the follow code.

```
"EvaluationParameters": {
    "BackTestWindowOffset": 10,
    "NumberOfBacktestWindows": 2
}
```

------
#### [ Forecast Console ]

During the **Train Predictor** stage, set the length of the testing set during backtesting with the **Backtest window offset** field, and the number of backtest windows with the **Number of backtest windows** field.

For example, to run 2 backtests with a testing set of 10 time points, set the following values.

![\[Input fields for number of backtest windows and backtest window offset with example values.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/predictor-backtest-windows.png)


------

### HPO and AutoML


By default, Amazon Forecast uses the `0.1` (P10), `0.5` (P50), and `0.9` (P90) quantiles for hyperparameter tuning during hyperparameter optimization (HPO) and for model selection during AutoML. If you specify custom forecast types when creating a predictor, Forecast uses those forecast types during HPO and AutoML. 

If custom forecast types are specified, Forecast uses those specified forecast types to determine the optimal outcomes during HPO and AutoML. During HPO, Forecast uses the first backtest window to find the optimal hyperparameter values. During AutoML, Forecast uses the averages across all backtest windows and the optimal hyperparameters values from HPO to find the optimal algorithm.

For both AutoML and HPO, Forecast chooses the option that minimizes the average losses over the forecast types. You can also optimize your predictor during AutoML and HPO with one of the following accuracy metrics: Average Weighted Quantile loss (Average wQL), Weighted Absolute Percentage Error (WAPE), Root Mean Squared Error (RMSE), Mean Absolute Percentage Error (MAPE), or Mean Absolute Scaled Error (MASE).

You can choose an optimization metric using the Amazon Forecast Software Development Kit (SDK) and Amazon Forecast console. 

------
#### [ Forecast SDK ]

Using the [`CreatePredictor`](API_CreatePredictor.md) operation, specify the custom forecast types in the `ObjectiveMetric` parameter.

The `ObjectiveMetric` parameter accepts the following values:
+ `AverageWeightedQuantileLoss` - Average Weighted Quantile loss
+ `WAPE` - Weighted Absolute Percentage Error
+ `RMSE` - Root Mean Squared Error
+ `MAPE` - Mean Absolute Percentage Error
+ `MASE` - Mean Absolute Scaled Error 

For example, to create a predictor with AutoML and optimize using the Mean Absolute Scaled Error (MASE) accuracy metric, use the following code.

```
{
    ...
    "PerformAutoML": "true",
    ...
    "ObjectiveMetric": "MASE",
},
```

------
#### [ Forecast Console ]

During the **Train Predictor** stage, choose **Automatic (AutoML)**. In the **Objective metric** section, choose the accuracy metric to use to optimize your predictor.

For example, the following image shows a predictor created with AutoML and optimized using the Mean Absolute Scaled Error (MASE) accuracy metric.

When using the console, you can only specify the Objective metric when you create a predictor using AutoML. If you manually select an algorithm, you cannot specify the Objective metric for HPO.

------

# Retraining Predictors


**Note**  
Retraining is only available for predictors created with AutoPredictor ([`CreateAutoPredictor`](API_CreateAutoPredictor.md)). You can upgrade existing legacy predictors to AutoPredictor. See [Upgrading to AutoPredictor](howitworks-predictor.md#upgrading-autopredictor).

Predictors can be retained with updated datasets to keep your predictors up to date. When retraining a predictor, Amazon Forecast maintains the same predictor configuration settings. After retraining, the original predictor will remain active and the retrained predictor will have a separate Predictor ARN.

Retraining a predictor can improve forecasting accuracy in two ways:

1. **More current data**: Your retrained predictor will incorporate more up-to-date data when training a model.

1. **Predictor improvements**: Your retrained predictor will incorporate any updates and improvements in the Amazon Forecast algorithms and additional datasets.

Retraining a predictor can be up to 50% faster than creating a new predictor from scratch. Predictor training times are faster and Forecast automatically uses your existing configuration settings.

**Python notebooks**  
For a step-by-step guide on retraining predictors, see [Retraining a predictor](https://github.com/aws-samples/amazon-forecast-samples/blob/main/notebooks/advanced/Retraining_AutoPredictor/Retraining.ipynb).

You can retrain a predictor using the Software Development Kit (SDK) or the Amazon Forecast console.

------
#### [ Console ]

**To retrain 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. In the navigation pane, choose **Predictors**.

1. Choose the predictor to retrain.

1. In the **Predictor actions** drop-down, choose **Retrain**.

1. Set a unique name for the upgraded predictor.

1. Choose **Retrain predictor**.

------
#### [ SDK ]

**To retrain a predictor**

Using the [`CreateAutoPredictor`](API_CreateAutoPredictor.md) operation, assign the predictor a unique name and set the value of `ReferencePredictorArn` to the predictor you wish to retrain.

```
{
  "PredictorName": "RetrainedPredictor",
  "ReferencePredictorArn": "arn:aws:forecast:us-west-2:938097332257:predictor/OriginalPredictor"
}
```

When retraining a predictor, assign values to only the `PredictorName` and `ReferencePredictorArn` parameters.

------

# Weather Index


The Amazon Forecast Weather Index is a built-in featurization that incorporates historical and projected weather information into your model. It is especially useful for retail use cases, where temperature and precipitation can significantly affect product demand.

When the Weather Index is enabled, Forecast applies the weather featurization only to time series where it finds improvements in accuracy during predictor training. If supplementing a time series with weather information does not improve its predictive accuracy during backtesting, Forecast does not apply the Weather Index to that particular time series.

To apply the Weather Index, you must include a [geolocation attribute](#adding-geolocation) in your target time series dataset and any related time series datasets. You also need to specify [time zones](#specifying-timezones) for your target time-series timestamps. For more information regarding dataset requirements, see [Conditions and Restrictions](#weather-conditions-restrictions).

**Python notebooks**  
For a step-by-step guide on using the Weather Index, see [NY Taxi: Amazon Forecast with Weather Index](https://github.com/aws-samples/amazon-forecast-samples/tree/master/notebooks/advanced/Weather_index).

**Topics**
+ [

## Enabling the Weather Index
](#enabling-weather)
+ [

## Adding Geolocation Information to Datasets
](#adding-geolocation)
+ [

## Specifying Time Zones
](#specifying-timezones)
+ [

## Conditions and Restrictions
](#weather-conditions-restrictions)

## Enabling the Weather Index


The Weather Index is enabled during the predictor training stage. When using the [`CreateAutoPredictor`](API_CreateAutoPredictor.md) operation, the Weather Index is included in the [AdditionalDataset](API_AdditionalDataset.md) data type.

Before enabling the Weather Index, you must include a geolocation attribute in your target time series and related timeseries datasets, and define the time zones for your timestamps. For more information, see [Adding Geolocation Information](#adding-geolocation) and [Specifying Time Zones](#specifying-timezones).

You can enable the Weather Index using the Forecast console or the Forecast Software Development Kit (SDK) .

------
#### [ Console ]

**To enable the Weather Index**

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. Choose **Enable Weather Index**.

------
#### [ SDK ]

**To enable the Weather Index**

Using the [`CreateAutoPredictor`](API_CreateAutoPredictor.md) operation, enable the Weather Index by adding `"Name": "weather"` and `"Value": "true"` in the [AdditionalDataset](API_AdditionalDataset.md) data type.

```
    "DataConfig": { 
        ...
        "AdditionalDatasets": [
            ...                      
            {             
                "Name": "weather",       
            }      
            ]   
        },
```

------

## Adding Geolocation Information to Datasets


To use the Weather Index, you must include a geolocation attribute for each item in your target time series and related time series datasets. The attribute is defined with the `geolocation` attribute type within the dataset schemas.

All geolocation values in a dataset must be exclusively within a single region. The regions are: US (excluding Hawaii and Alaska), Canada, South America, Central America, Asia Pacific, Europe, and Africa & Middle East.

Specify the geolocation attribute in one of two formats:
+ **Latitude & Longitude** (All regions) - Specify the latitude and longitude in decimal format (Example: 47.61\$1-122.33)
+ **Postal code** (US only) - Specify the country code (US), followed by the 5-digit ZIP code (Example: US\$198121)

The Latitude & Longitude format is supported for all regions. The Postal code format is only supported for the US region.

**Topics**
+ [

### Latitude & Longitude Bounds
](#geolocation-bounds)
+ [

### Including Geolocation in the Dataset Schema
](#geolocation-schema)
+ [

### Setting the Geolocation Format
](#geolocation-format)

### Latitude & Longitude Bounds


The following are the latitudinal and longitudinal bounds for the accepted regions:

------
#### [ US Region ]

**Bounds**: latitude (24.6, 50.0), longitude (-126.0, -66.4).

![\[Map of North America showing United States, parts of Canada and Mexico with major cities.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/weather-us-bounds.png)


------
#### [ Canada Region ]

**Bounds**: latitude (41.0, 75.0), longitude (-142.0, -52.0).

![\[Map showing northern Canada and parts of the US, highlighting territories and major cities.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/weather-can-bounds.PNG)


------
#### [ Europe Region ]

**Bounds**: latitude (34.8, 71.8), longitude (-12.6, 44.8).

![\[Map of Northern Europe and surrounding regions showing countries and major cities.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/weather-euro-bounds.png)


------
#### [ South America Region ]

**Bounds**: latitude (-56.6, 14.0), longitude (-82.4, -33.00).

![\[Map of South America showing countries, major cities, and Brazilian states.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/weather-sa-bounds.PNG)


------
#### [ Asia Pacific Region ]

**Bounds**: latitude (-47.8, 55.0), longitude (67.0, 180.60).

![\[Map showing East Asia, Southeast Asia, and Australia with country names and ocean labels.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/weather-apac-bounds.png)


------
#### [ Central America Region ]

**Bounds**: latitude (6.80, 33.20), longitude (-118.80, -58.20).

![\[Map showing southern US, Mexico, Central America, and Caribbean with major cities and bodies of water.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/weather-ca-bounds.png)


------
#### [ Africa & Middle East Region ]

**Bounds**: latitude (-35.60, 43.40), longitude (-18.80, -58.20).

![\[Map showing North Africa, Middle East, and parts of Europe with country names and borders.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/weather-africa-bounds.png)


------

### Including Geolocation in the Dataset Schema


Using the console or [CreateDataset](API_CreateDataset.md) operation, define the location attribute type as 'geolocation' within the JSON schema for the target time series and any related time series. The attributes in the schema must be ordered as they appear in the datasets.

```
 { 
  "Attributes":[
    {
       "AttributeName": "timestamp",
       "AttributeType": "timestamp"
    },
    {
       "AttributeName": "target_value",
       "AttributeType": "float"
    },
    {
       "AttributeName": "item_id",
       "AttributeType": "string"
    },
    {
       "AttributeName": "location",
       "AttributeType": "geolocation"
    }
  ]
}
```

### Setting the Geolocation Format


The format of the geolocation attribute can be in the **Postal Code** or **Latitude & Longitude** format. You can set the geolocation format using the Forecast console or the Forecast Software Development Kit (SDK).

------
#### [ Console ]

**To add a geolocation attribute to a time series dataset**

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. Choose **Create dataset group**.

1. In the **Schema builder**, set your geolocation **Attribute type** to `geolocation`.

1. In the **Geolocation format** drop-down, choose your location format.

![\[Dataset details form with name, frequency, and schema builder for attribute specification.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/schema-builder-geolocation.png)


You can also define your attributes in JSON format and select a location format from the **Geolocation format** drop-down.

------
#### [ SDK ]

**To add a geolocation attribute to a time series dataset**

Using the [ CreateDatasetImportJob](API_CreateDatasetImportJob.md) operation, set the value of `GeolocationFormat` to one of the following: 
+ **Latitude & longitude** (All regions): `"LAT_LONG"`
+ **Postal code** (US Only): `"CC_POSTALCODE"`

For example, to specify the latitude & longitude format, include the following in `CreateDatasetImportJob` request:

```
{
    ...
    "GeolocationFormat": "LAT_LONG"
}
```

------

## Specifying Time Zones


You can either let Amazon Forecast automatically synchronize your time zone information with your geolocation attribute, or you can manually assign a single time zone to your entire dataset. 

**Topics**
+ [

### Automatically Sync Time Zones with Geolocation
](#timezones-automatic)
+ [

### Manually Select a Single Time Zone
](#timezones-manual)

### Automatically Sync Time Zones with Geolocation


This option is ideal for datasets that contain timestamps in multiple time zones, and those timestamps are expressed in local time. Forecast assigns a time zone for every item in the target time series dataset based on the item’s geolocation attribute.

You can automatically sync your timestamps with your geolocation attribute using the Forecast console or Forecast SDK.

------
#### [ Console ]

**To sync time zones with the geolocation attribute**

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. In the navigation pane, choose **Create dataset group**.

1. In **Dataset import details**, choose **Sync time zone with location**.

![\[Dataset import form with fields for name, time zone, S3 data location, and IAM role.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/sync-timezone-with-geolocation.PNG)


------
#### [ SDK ]

**To sync time zones with the geolocation attribute**

Using the [ CreateDatasetImportJob](API_CreateDatasetImportJob.md) operation, set `"UseGeolocationForTimeZone"` to `"true"`.

```
{
    ...
    "UseGeolocationForTimeZone": "true"
}
```

------

### Manually Select a Single Time Zone


**Note**  
You can manually select a time zone outside of the *US region*, *Canada region*, *South America region*, *Central America region*, *Asia Pacific region*, *Europe region*, and *Africa & Middle East region*. However, all geolocation values must still be within one of those regions.

This option is ideal for datasets with all timestamps within a single time zone, or if all timestamps are normalized to a single time zone. Using this option applies the same time zone to every item in the dataset.

The Weather Index accepts the following time zones:

 **US region** 
+  America/Los\$1Angeles 
+  America/Phoenix 
+  America/Denver 
+  America/Chicago 
+  America/New\$1York 

 **Canada region** 
+ America/Vancouver
+ America/Edmonton
+ America/Regina 
+ America/Winnipeg 
+ America/Toronto
+ America/Halifax
+ America/St\$1Johns

 **Europe region** 
+ Europe/London 
+ Europe/Paris 
+ Europe/Helsinki 

 **South America region** 
+ America/Buenos\$1Aires
+ America/Noronha
+ America/Caracas 

 **Asia Pacific region** 
+ Asia/Kabul 
+ Asia/Karachi 
+ Asia/Kolkata 
+ Asia/Kathmandu 
+ Asia/Dhaka 
+ Asia/Rangoon 
+ Asia/Bangkok 
+ Asia/Singapore 
+ Asia/Seoul 
+ Australia/Adelaide 
+ Australia/Melbourne 
+ Australia/Lord\$1Howe 
+ Australia/Eucla 
+ Pacific/Norfolk 
+ Pacific/Auckland 

 **Central America** 
+ America/Puerto\$1Rico

 **Africa & Middle East** 
+ Africa/Nairobi 
+ Asia/Tehran 
+ Asia/Dubai

 **Other** 
+ Pacific/Midway 
+ Pacific/Honolulu 
+ Pacific/Marquesas 
+ America/Anchorage 
+ Atlantic/Cape\$1Verde 
+ Asia/Anadyr 
+ Pacific/Chatham 
+ Pacific/Enderbury 
+ Pacific/Kiritimati 

Select a time zone from the **Other** list if items in your dataset are located within one of the accepted region, but your timestamps are standardized to a time zone outside of that region. 

For a complete list of valid time zone names, see [Joda-Time library](http://joda-time.sourceforge.net/timezones.html).

You can manually set a time zone for your datasets using the Forecast console or Forecast SDK.

------
#### [ Console ]

**To select a single time zone for your dataset**

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. In the navigation pane, choose **Create dataset group**.

1. In **Dataset import details**, choose **Select time zone**.

For example, use the following to apply Los Angeles time (Pacific Standard Time) to your datasets.

![\[Dataset import form with fields for name, time zone, data location, and IAM role.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/select-timezone.PNG)


------
#### [ SDK ]

**To select a single time zone for your dataset**

Using the [ CreateDatasetImportJob](API_CreateDatasetImportJob.md) operation, set `"TimeZone"` to a valid time zone.

For example, use the following to apply Los Angeles time (Pacific Standard Time) to your datasets. 

```
{
    ...
    "TimeZone": "America/Los_Angeles"
}
```

------

## Conditions and Restrictions


The following conditions and restrictions apply when using the Weather Index:
+ **Available algorithms**: If using a legacy predictor, the Weather Index can be enabled when you train a predictor with the CNN-QR, DeepAR\$1, and Prophet algorithms. The Weather Index is not applied to ARIMA, ETS, and NPTS.
+ **Forecast frequency**: The valid forecast frequencies are `Minutely`, `Hourly`, and `Daily`.
+ **Forecast horizon**: The forecast horizon cannot span further than 14 days into the future. For forecast horizon limits for each forecast frequency, refer to the list below:
  + `1 minute` - 500
  + `5 minutes` - 500
  + `10 minutes` - 500
  + `15 minutes` - 500
  + `Hourly` - 330
  + `Daily` - 14
+ **Time series length**: When training a model with the Weather Index, Forecast truncates all time series datasets with timestamps before the start date of the Forecast weather dataset featurization. The Forecast weather dataset featurization contains the following start dates:
  + **US region**: July 2, 2018
  + **Europe region**: July 2, 2018
  + **Asia Pacific region**: July 2, 2018
  + **Canada region**: July 2, 2019
  + **South America region**: January 2, 2020
  + **Central America region**: September 2, 2020
  + **Africa & Middle East region**: March 25, 2021

  With the Weather Index enabled, data points with timestamps before the start date will not be used during predictor training.
+ **Number of locations**: The target time series dataset cannot exceed 2000 unique locations.
+ **Region bounds**: All items in your datasets must be located within a single region.
+ **Minimum time series length**: Due to additional data requirements when testing the Weather Index, the minimum length for a time series dataset is: 

  `3 × ForecastHorizon + (BacktestWindows + 1) × BacktestWindowOffset`

  If your time series datasets do not meet this requirement, consider decreasing the following:
  + `ForecastHorizon` - Shorten your forecast horizon.
  + `BacktestWindowOffset` - Shorten the length of the testing set during backtesting.
  + `BacktestWindows` - Reduce the number of backtests.

# Holidays Featurization


Holidays is a built-in featurization that incorporates a feature-engineered dataset of national holiday information into your model. It provides native support for the holiday calendars of over 250 countries. Amazon Forecast incorporates both the [Holiday API library](https://holidayapi.com/countries) and [Jollyday API](https://jollyday.sourceforge.net/data.html) to generate holiday calendars. 

The Holidays featurization is especially useful in the retail domain, where public holidays can significantly affect demand.

The Holiday featurization supports a minimum forecast frequency of 5 minutes and a maximum of 1 month.

**Topics**
+ [

## Enabling the Holidays Featurization
](#enabling-holidays)
+ [

## Country Codes
](#holidays-country-codes)
+ [

## Additional Holiday Calendars
](#holiday-calendars)

## Enabling the Holidays Featurization


The Holidays featurization is included in Amazon Forecast as an [Additional Dataset](API_AdditionalDataset.md), and is enabled before training a predictor. It is recommended that your historical data contains at least two years of data. This allows Forecast to identify demand patters that are associated with specific holidays. After you choose a country, Holidays applies that country’s holiday calendar to every item in your dataset during training.

 You can enable Holidays using the Amazon Forecast console or the Forecast Software Development Kit (SDK).

------
#### [ Forecast SDK ]

Using the [`CreateAutoPredictor`](API_CreateAutoPredictor.md) operation, enable Holidays by adding `"Name": "holiday`" and setting `"Configuration"` to map `"CountryCode"` a two-letter country code. See [Country Codes](#holidays-country-codes).

For example, to include the USA holiday calendar, use the following code.

```
      "DataConfig": {          
        "AdditionalDatasets": [          
            {             
                "Name": "holiday",            
                "Configuration": {
                    "CountryCode" : ["US"]
                }      
            },      
          ]   
        },
```

------
#### [ Forecast Console ]

Choose a country from the **Country for Holidays** drop-down during the **Train Predictor** stage.

![\[Toggle switch to activate holidays and dropdown menu to select a country for forecast accuracy.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/holidays-dropdown-2.png)


------

## Country Codes


 Amazon Forecast provides native support for the public holiday calendars of the following countries. Use the **Country Code** when specifying a country with the API.


**Supported Countries**  

| Country | Country Code | 
| --- | --- | 
|   Afghanistan   |   AF   | 
|   Åland Islands   |   AX   | 
|   Albania   |   AL   | 
|   Algeria   |   DZ   | 
|   American Samoa   |   AS   | 
|   Andorra   |   AD   | 
|   Angola   |   AO   | 
|   Anguilla   |   AI   | 
|   Antartica   |   AQ   | 
|   Antigua and Barbuda   |   AG   | 
|   Argentina   |   AR   | 
|   Armenia   |   AM   | 
|   Aruba   |   AW   | 
|   Australia   |   AU   | 
|   Austria   |   AT   | 
|   Azerbaijan   |   AZ   | 
|   Bahamas   |   BS   | 
|   Bahrain   |   BH   | 
|   Bangladesh   |   BD   | 
|   Barbados   |   BB   | 
|   Belarus   |   BY   | 
|   Belgium   |   BE   | 
|   Belize   |   BZ   | 
|   Benin   |   BJ   | 
|   Bermuda   |   BM   | 
|   Bhutan   |   BT   | 
|   Bolivia   |   BO   | 
|   Bosnia and Herzegovina   |   BA   | 
|   Botswana   |   BW   | 
|   Bouvet Island   |   BV   | 
|   Brazil   |   BR   | 
|   British Indian Ocean Territory   |   IO   | 
|   British Virgin Islands   |   VG   | 
|   Brunei Darussalam   |   BN   | 
|   Bulgaria   |   BG   | 
|   Burkina Faso   |   BF   | 
|   Burundi   |   BI   | 
|   Cambodia   |   KH   | 
|   Cameroon   |   CM   | 
|   Canada   |   CA   | 
|   Cape Verde   |   CV   | 
|   Caribbean Netherlands   |   BQ   | 
|   Cayman Islands   |   KY   | 
|   Central African Republic   |   CF   | 
|   Chad   |   TD   | 
|   Chile   |   CL   | 
|   China   |   CN   | 
|   Christmas Island   |   CX   | 
|   Cocos (Keeling) Islands   |   CC   | 
|   Colombia   |   CO   | 
|   Comoros   |   KM   | 
|   Cook Islands   |   CK   | 
|   Costa Rica   |   CR   | 
|   Croatia   |   HR   | 
|   Cuba   |   CU   | 
|   Curaçao   |   CW   | 
|   Cyprus   |   CY   | 
|   Czechia   |   CZ   | 
|   Democratic Republic of the Congo   |   CD   | 
|   Denmark   |   DK   | 
|   Djibouti   |   DJ   | 
|   Dominica   |   DM   | 
|   Dominican Republic   |   DO   | 
|   Ecuador   |   EC   | 
|   Egypt   |   EG   | 
|   El Salvador   |   SV   | 
|   Equatorial Guinea   |   GQ   | 
|   Eritrea   |   ER   | 
|   Estonia   |   EE   | 
|   Eswatini   |   SZ   | 
|   Ethiopia   |   ET   | 
|   Falkland Islands   |   FK   | 
|   Faroe Islands   |   FO   | 
|   Fiji   |   FJ   | 
|   Finland   |   FI   | 
|   France   |   FR   | 
|   French Guiana   |   GF   | 
|   French Polynesia   |   PF   | 
|   French Southern Territories   |   TF   | 
|   Gabon   |   GA   | 
|   Gambia   |   GM   | 
|   Georgia   |   GE   | 
|   Germany   |   DE   | 
|   Ghana   |   GH   | 
|   Gibraltar   |   GI   | 
|   Greece   |   GR   | 
|   Greenland   |   GL   | 
|   Grenada   |   GD   | 
|   Guadeloupe   |   GP   | 
|   Guam   |   GU   | 
|   Guatemala   |   GT   | 
|   Guernsey   |   GG   | 
|   Guinea   |   GN   | 
|   Guinea-Bissau   |   GW   | 
|   Guyana   |   GY   | 
|   Haiti   |   HT   | 
|   Heard Island and McDonald Islands   |   HM   | 
|   Honduras   |   HN   | 
|   Hong Kong   |   HK   | 
|   Hungary   |   HU   | 
|   Iceland   |   IS   | 
|   India   |   IN   | 
|   Indonesia   |   ID   | 
|   Iran   |   IR   | 
|   Iraq   |   IQ   | 
|   Ireland   |   IE   | 
|   Isle of Man   |   IM   | 
|   Israel   |   IL   | 
|   Italy   |   IT   | 
|   Ivory Coast   |   CI   | 
|   Jamaica   |   JM   | 
|   Japan   |   JP   | 
|   Jersey   |   JE   | 
|   Jordan   |   JO   | 
|   Kazakhstan   |   KZ   | 
|   Kenya   |   KE   | 
|   Kiribati   |   KI   | 
|   Kosovo   |   XK   | 
|   Kuwait   |   KW   | 
|   Kyrgyzstan   |   KG   | 
|   Laos   |   LA   | 
|   Latvia   |   LV   | 
|   Lebanon   |   LB   | 
|   Lesotho   |   LS   | 
|   Liberia   |   LR   | 
|   Libya   |   LY   | 
|   Liechtenstein   |   LI   | 
|   Lithuania   |   LT   | 
|   Luxembourg   |   LU   | 
|   Macao   |   MO   | 
|   Madagascar   |   MG   | 
|   Malawi   |   MW   | 
|   Malaysia   |   MY   | 
|   Maldives   |   MV   | 
|   Mali   |   ML   | 
|   Malta   |   MT   | 
|   Marshall Islands   |   MH   | 
|   Martinique   |   MQ   | 
|   Mauritania   |   MR   | 
|   Mauritius   |   MU   | 
|   Mayotte   |   YT   | 
|   Mexico   |   MX   | 
|   Micronesia   |   FM   | 
|   Moldova   |   MD   | 
|   Monaco   |   MC   | 
|   Mongolia   |   MN   | 
|   Montenegro   |   ME   | 
|   Montserrat   |   MS   | 
|   Morocco   |   MA   | 
|   Mozambique   |   MZ   | 
|   Myanmar   |   MM   | 
|   Namibia   |   NA   | 
|   Nauru   |   NR   | 
|   Nepal   |   NP   | 
|   Netherlands   |   NL   | 
|   New Caledonia   |   NC   | 
|   New Zealand   |   NZ   | 
|   Nicaragua   |   NI   | 
|   Niger   |   NE   | 
|   Nigeria   |   NG   | 
|   Niue   |   NU   | 
|   Norfolk Island   |   NF   | 
|   North Korea   |   KP   | 
|   North Macedonia   |   MK   | 
|   Northern Mariana Islands   |   MP   | 
|   Norway   |   NO   | 
|   Oman   |   OM   | 
|   Pakistan   |   PK   | 
|   Palau   |   PW   | 
|   Palestine   |   PS   | 
|   Panama   |   PA   | 
|   Papua New Guinea   |   PG   | 
|   Paraguay   |   PY   | 
|   Peru   |   PE   | 
|   Philippines   |   PH   | 
|   Pitcairn Islands   |   PN   | 
|   Poland   |   PL   | 
|   Portugal   |   PT   | 
|   Puerto Rico   |   PR   | 
|   Qatar   |   QA   | 
|   Republic of the Congo   |   CG   | 
|   Réunion   |   RE   | 
|   Romania   |   RO   | 
|   Russian Federation   |   RU   | 
|   Rwanda   |   RW   | 
|   Saint Barthélemy   |   BL   | 
|   "Saint Helena, Ascension and Tristan da Cunha "   |   SH   | 
|   Saint Kitts and Nevis   |   KN   | 
|   Saint Lucia   |   LC   | 
|   Saint Martin   |   MF   | 
|   Saint Pierre and Miquelon   |   PM   | 
|   Saint Vincent and the Grenadines   |   VC   | 
|   Samoa   |   WS   | 
|   San Marino   |   SM   | 
|   Sao Tome and Principe   |   ST   | 
|   Saudi Arabia   |   SA   | 
|   Senegal   |   SN   | 
|   Serbia   |   RS   | 
|   Seychelles   |   SC   | 
|   Sierra Leone   |   SL   | 
|   Singapore   |   SG   | 
|   Sint Maarten   |   SX   | 
|   Slovakia   |   SK   | 
|   Slovenia   |   SI   | 
|   Solomon Islands   |   SB   | 
|   Somalia   |   SO   | 
|   South Africa   |   ZA   | 
|   South Georgia and the South Sandwich Islands   |   GS   | 
|   South Korea   |   KR   | 
|   South Sudan   |   SS   | 
|   Spain   |   ES   | 
|   Sri Lanka   |   LK   | 
|   Sudan   |   SD   | 
|   Suriname   |   SR   | 
|   Svalbard and Jan Mayen   |   SJ   | 
|   Sweden   |   SE   | 
|   Switzerland   |   CH   | 
|   Syrian Arab Republic   |   SY   | 
|   Taiwan   |   TW   | 
|   Tajikistan   |   TJ   | 
|   Tanzania   |   TZ   | 
|   Thailand   |   TH   | 
|   Timor-Leste   |   TL   | 
|   Togo   |   TG   | 
|   Tokelau   |   TK   | 
|   Tonga   |   TO   | 
|   Trinidad and Tobago   |   TT   | 
|   Tunisia   |   TN   | 
|   Turkey   |   TR   | 
|   Turkmenistan   |   TM   | 
|   Turks and Caicos Islands   |   TC   | 
|   Tuvalu   |   TV   | 
|   Uganda   |   UG   | 
|   Ukraine   |   UA   | 
|   United Arab Emirates   |   AE   | 
|   United Kingdom   |   GB   | 
|   United Nations   |   UN   | 
|   United States   |   US   | 
|   United States Minor Outlying Islands   |   UM   | 
|   United States Virgin Islands   |   VI   | 
|   Uruguay   |   UY   | 
|   Uzbekistan   |   UZ   | 
|   Vanuatu   |   VU   | 
|   Vatican City   |   VA   | 
|   Venezuela   |   VE   | 
|   Vietnam   |   VN   | 
|   Wallis and Futuna   |   WF   | 
|   Western Sahara   |   EH   | 
|   Yemen   |   YE   | 
|   Zambia   |   ZM   | 
|   Zimbabwe   |   ZW   | 

## Additional Holiday Calendars


Amazon Forecast also supports holidays for India, Korea, and United Arab Emirates. Their holidays are listed below.

------
#### [ India - "IN" ]

January 26 - Republic Day 

August 15 - Independence Day

October 2 - Gandhi Jayanti

------
#### [ Korea - "KR" ]

January 1 - New Year 

March 1 - Independence Movement Day 

May 5 - Children's Day

June 6 - Memorial Day

August 15 - Liberation Day

October 3 - National Foundation Day

October 9 - Hangul Day

December 25 - Christmas Day

------
#### [ United Arab Emirates - "AE" ]

January 1 - New Year 

December 1 - Commemoration Day

December 2-3 - National Day

Ramadan\$1

Eid al-Fitr\$1

Eid al-Adha\$1

Islamic New Year\$1

\$1Islamic Holidays are determined by lunar cycles.

------

# Predictor Explainability


Predictor Explainability helps you better understand how the attributes in your datasets impact your target variable. Forecast uses a metric called Impact scores to quantify the relative impact of each attribute and determine whether they increase or decrease forecast values.

For example, consider a forecasting scenario where the target is `sales` and there are two related attributes: `price` and `color`. Forecast may find that an item’s price significantly impacts sales (high Impact score), while the item’s color has a negligible effect (low Impact score).

To enable Predictor Explainability, your predictor must include at least one of the following: related time series, item metadata, or additional datasets like Holidays and the Weather Index. See [Restrictions and best practices](#predictor-explainability-best-practices) for more information.

To create Impact scores for specific time series and time points, use Forecast Explainability instead of Predictor Explainability. See [Forecast Explainability](forecast-explainability.md).

**Topics**
+ [

## Interpreting Impact Scores
](#predictor-explainability-impact-scores)
+ [

## Creating Predictor Explainability
](#creating-predictor-explainability)
+ [

## Exporting Predictor Explainability
](#exporting-predictor-explainability)
+ [

## Restrictions and best practices
](#predictor-explainability-best-practices)

## Interpreting Impact Scores


Impact scores measure the relative impact attributes have on forecast values. For example, if the ‘price’ attribute has an impact score that is twice as large as the ‘store location’ attribute, you can conclude that the price of an item has twice the impact on forecast values than the store location.

 Impact scores also provide information on whether attributes increase or decrease forecast values. In the console, this is denoted by the two graphs. Attributes with blue bars increase forecast values, while attributes with red bars decrease forecast values. 

![\[Bar graphs showing Price and Promo increasing impact scores, StoreLocation decreasing impact score.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/quicksight-unfiltered.png)


In the console, Impact scores range from 0 to 1, where a score of 0 denotes no impact and a score close to 1 denotes a significant impact. In the SDKs, Impact scores range from -1 to 1, where the sign denotes the direction of the impact.

It is important to note that Impact scores measure the relative impact of attributes, not the absolute impact. Therefore, Impact scores cannot be used to determine whether particular attributes improve model accuracy. If an attribute has a low Impact score, that does not necessarily mean that it has a low impact on forecast values; it means that it has a lower impact on forecast values than other attributes used by the predictor.

## Creating Predictor Explainability


**Note**  
You can create a maximum of one Predictor Explainability per predictor

When you enable Predictor Explainability, Amazon Forecast calculates Impact scores for all attributes in your datasets. The Impact scores can be interpreted as the impact attributes have on overall forecast values. You can enable Predictor Explainability when you create a predictor, or you can enable the feature after creating the predictor.

### Enabling Predictor Explainability for a new predictor


Enabling Predictor Explainability when creating a new predictor will create both a Predictor resource and Explainability resource. You can enable Predictor Explainability for a new predictor using the Software Development Kit (SDK) or the Amazon Forecast console.

------
#### [ Console ]

**To enable Predictor Explainability**

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. In the **Predictor configuration** section, choose **Enable Explainability**.

1. Provide values for the following mandatory fields:
   + **Name** - a unique predictor name.
   + **Forecast frequency** - the granularity of your forecasts.
   + **Forecast horizon** - The number of time steps to forecast.

1. Choose **Start**

------
#### [ Python ]

To enable explainability for a new predictor with the SDK for Python (Boto3), use the `create_auto_predictor` method and set ExplainPredictor to true. 

The following code creates an auto predictor that makes predictions for 24 (`ForecastHorizon`) days (`ForecastFrequency`) in the future, and has `ExplainPredictor` set to true. 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 = 24,
    ForecastFrequency = 'D',
    DataConfig = {
        "DatasetGroupArn": "arn:aws:forecast:region:account:dataset-group/datasetGroupName"
    },
    ExplainPredictor = True
)
```

------

### Enabling Predictor Explainability for an existing predictor


Enabling Predictor Explainability for an existing predictor will create a Explainability resource for that resource. You can only create an Explainability resource for predictors that do not already contain an Explainability resource. To view Impact scores for an updated dataset, retrain or recreate the predictor with the updated data.

You can enable Predictor Explainability for a new predictor using the Software Development Kit (SDK) or the Amazon Forecast console.

------
#### [ Console ]

**To enable Predictor Explainability**

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 your predictor.

1. In the **Predictor Explainability** section, choose **Enable Explainability**.

1. Provide a unique name for the Predictor Explainability.

1. Choose **Start**

------
#### [ Python ]

To enable Predictor Explainability for an existing predictor with the SDK for Python (Boto3), use the `create_explainability` method. Specify a name for the explainability, the ARN for the predictor, and for `ExplainabilityConfig`, set both `TimePointGranularity` and `TimeSeriesGranularity` to **ALL**. To create an Explainability visualization that is viewable within the console, set `EnableVisualization` to **True**. 

For information on required and optional parameters see [CreateExplainability](API_CreateExplainability.md). 

```
import boto3
                            
forecast = boto3.client('forecast')

create_explainability_response = forecast.create_explainability(
    ExplainabilityName = 'explainability_name',
    ResourceArn = 'arn:aws:forecast:region:accountNumber:predictor/predictorName',
    ExplainabilityConfig = { 
      "TimePointGranularity": "ALL",
      "TimeSeriesGranularity": "ALL"
    },
    EnableVisualization = True
)
```

------

## Exporting Predictor Explainability


**Note**  
Export files can directly return information from the Dataset Import. This makes the files vulnerable to CSV injection if the imported data contains formulas or commands. For this reason, exported files can prompt security warnings. To avoid malicious activity, disable links and macros when reading exported files.

Forecast enables you to export a CSV or Parquet file of Impact scores to an S3 location. The Impact scores range from -1 to 1, where the sign denotes the direction of the impact. You can export Impact scores using the Amazon Forecast Software Development Kit (SDK) and the Amazon Forecast console.

![\[Table showing normalized impact scores for price, promotion, weather index, and US holidays.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/explainability-global.png)


------
#### [ Console ]

**To export Predictor Explainability**

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 your predictor.

1. In the **Predictor Explainability** section, choose **Export**.

1. For the **Export name** field, provide a unique name for the export.

1. For the **S3 explainability export location** field, provide an S3 location to export the CSV file.

1. For the **IAM Role** field, provide a role with access to the specified S3 location.

1. Choose **Create export.**

------
#### [ Python ]

To export a Predictor Explainability with the SDK for Python (Boto3), use the `create_explainability_export` method. Give the job a name, specify the ARN of the explainability, and, in the `Destination` object, specify your Amazon S3 destination location, and IAM service role.

For information on required and optional parameters see [CreateExplainabilityExport](API_CreateExplainabilityExport.md). 

```
import boto3
                        
forecast = boto3.client('forecast')

export_response = forecast.create_explainability_export(
    Destination = {
        "S3Config": {
            "Path": "s3://bucketName/filename.csv",
            "RoleArn": "arn:aws:iam::accountNumber:role/roleName"
        }
    },
    ExplainabilityArn = 'arn:aws:forecast:region:accountNumber:explainability/explainabilityName',
    ExplainabilityExportName = 'job_name'
)
```

------

## Restrictions and best practices


Consider the following restrictions and best practices when working with Predictor Explainability.
+ **Predictor Explainability is only available for some predictors created with AutoPredictor** - You cannot enable Explainability for legacy predictors that were created with AutoML or through manual selection. See [Upgrading to AutoPredictor](howitworks-predictor.md#upgrading-autopredictor).
+ **Predictor Explainability is not available for all models** - The ARIMA (AutoRegressive Integrated Moving Average), ETS (Exponential Smoothing State Space Model), and NPTS (Non-Parametric Time Series) models do not incorporate external time series data. Therefore, these models do not create an explainability report, even if you include the additional datasets.
+ **Explainability requires attributes** - Your predictor must include at least one of the following: related time series, item metadata, Holidays, or the Weather Index.
+ **Predictors are limited to one Explainability resource** - You cannot create multiple Explainability resources for a predictor. If you are interested in Impact scores for an updated dataset, retrain your predictor.
+ **Impact scores of zero denote no impact**- If an attribute has an impact score of 0, then that attribute has no significant impact on forecast values.
+ **Retrying failed Predictor Explainability jobs **- If Forecast successfully creates a Predictor but the Predictor Explainability job fails, you can retry creating Predictor Explainability in the console or with the CreateExplainability operation.
+ **You cannot create Impact scores for specific time points and time series **- To view Impact scores for specific time points and time series, see [Forecast Explainability](forecast-explainability.md).
+ **Predictor Explainability visualizations are available for 90 days after creation** - To view the visualization after 90 days, retrain the predictor.

# Predictor Monitoring


**Note**  
 If you enable predictor monitoring, Amazon Forecast will store data from each of your forecasts for predictor performance analysis, even after deleting forecast data. To delete this data, delete the monitoring resource. 

 Predictor monitoring allows you to see how your predictor's performance changes over time. A variety of factors can cause performance changes, such as economic developments or changes in your customer's behavior. 

 For example, consider a forecasting scenario where the target is `sales` and there are two related attributes: `price` and `color`. In the months after creating your first predictor, certain colors might unexpectedly become more popular with your customers. This might drive up sales for items with this attribute. This new data could impact your predictor's performance and the accuracy of the forecasts it generates. 

 With predictor monitoring enabled, Forecast analyzes your predictor's performance as you generate forecasts and import more data. Forecast compares the new data to the earlier forecasts to detect any changes in performance. You can view graphs of how different accuracy metrics have changed over time in the Forecast console. Or you can get monitoring results with the [ListMonitorEvaluations](API_ListMonitorEvaluations.md) operation. 

 Predictor monitoring can help decide if it is time to retrain your predictor. If performance is degrading, you might want to retrain the predictor on more recent data. If you choose to retrain your predictor, the new predictor will include the monitoring data from the previous one. You might also use predictor monitoring to gather contextual data about your production environment, or to perform comparisons for different experiments. 

Predictor monitoring is only available for AutoPredictors. You can upgrade existing legacy predictors to AutoPredictor. See [Upgrading to AutoPredictor](howitworks-predictor.md#upgrading-autopredictor). 

**Topics**
+ [

## Predictor Monitoring Workflow
](#predictor-monitoring-workflow)
+ [

# Enabling Predictor Monitoring
](enabling-predictor-monitoring.md)
+ [

# Viewing Monitoring Results
](predictor-monitoring-results.md)
+ [

## Restrictions and Best Practices
](#predictor-monitoring-best-practices)

## Predictor Monitoring Workflow


To get predictor monitoring results, you must first use your predictor to generate a forecast and then import more data. The monitoring workflow is as follows. 

1. Enable predictor monitoring for an auto predictor:
   + Create a new predictor with monitoring enabled. See [Enabling Predictor Monitoring for a New Predictor](enabling-predictor-monitoring.md#enabling-predictor-monitoring-new).
   + Or enable monitoring for an existing predictor. See [Enabling Predictor Monitoring for an Existing Predictor](enabling-predictor-monitoring.md#enabling-predictor-monitoring-existing).

1. Use the predictor to generate one or more forecasts.

1. Import more data. For information about importing data into Forecast, see [Importing Datasets](howitworks-datasets-groups.md).

1. View predictor monitoring results:
   + You can view results on the **Monitoring** tab for your predictor.
   + Or you can get monitoring results with the [ListMonitorEvaluations](API_ListMonitorEvaluations.md) operation.

   For more information, see [Viewing Monitoring Results](predictor-monitoring-results.md).

# Enabling Predictor Monitoring


You can enable predictor monitoring when you create the predictor, or you can enable it for an existing predictor. 

**Note**  
Predictor monitoring is only available for AutoPredictors. You can upgrade existing legacy predictors to AutoPredictor. See [Upgrading to AutoPredictor](howitworks-predictor.md#upgrading-autopredictor). 

**Topics**
+ [

## Enabling Predictor Monitoring for a New Predictor
](#enabling-predictor-monitoring-new)
+ [

## Enabling Predictor Monitoring for an Existing Predictor
](#enabling-predictor-monitoring-existing)

## Enabling Predictor Monitoring for a New Predictor


You can enable predictor monitoring for a new predictor with the console, AWS CLI, AWS SDKs, and the [CreateAutoPredictor](API_CreateAutoPredictor.md) operation.

------
#### [ Console ]

**To enable Predictor monitoring**

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. In the **Predictor configuration** section, choose **Enable monitoring**.

1. Provide values for the following mandatory fields:
   + **Name** - a unique predictor name.
   + **Forecast frequency** - the granularity of your forecasts.
   + **Forecast horizon** - The number of time steps to forecast.

1. Choose **Start** to create an auto predictor with monitoring enabled. You’ll see monitoring results as you use the predictor to generate forecasts and then import more data.

------
#### [ Python ]

To enable predictor monitoring for a new predictor with the SDK for Python (Boto3), use the `create_auto_predictor` method and provide a monitor name in the `MonitoringConfig`. 

The following code creates an auto predictor that makes predictions for 24 (`ForecastHorizon`) days (`ForecastFrequency`) in the future, and specifies `MyPredictorMonitor` as the `MonitorName`. After you generate a forecast and then import more data, you can view the results of predictor monitoring. For more information about retrieving results, see [Viewing Monitoring Results](predictor-monitoring-results.md). 

 For information on required and optional parameters for creating a predictor see [CreateAutoPredictor](API_CreateAutoPredictor.md).

```
import boto3
                            
forecast = boto3.client('forecast')

create_predictor_response = forecast.create_auto_predictor(
    PredictorName = 'predictor_name',
    ForecastHorizon = 24,
    ForecastFrequency = 'D',
    DataConfig = {
        "DatasetGroupArn": "arn:aws:forecast:region:account:dataset-group/datasetGroupName"
    },
    MonitorConifg = {
        "MonitorName": "MyMonitorName"
    }
)
```

------

## Enabling Predictor Monitoring for an Existing Predictor


You can enable predictor monitoring for an existing predictor with the console, AWS CLI, and AWS SDKs.

------
#### [ Console ]

**To enable predictor monitoring**

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 your predictor.

1. Navigate to the **Monitoring** tab.

1. In the **Monitoring details** section, choose **Start monitoring** 

   When the **Monitoring status** is Active, predictor monitoring is enabled. After you generate a forecast and then import more data, you can view the results of predictor monitoring. For more information see [Viewing Monitoring Results](predictor-monitoring-results.md)

------
#### [ Python ]

To enable predictor monitoring for an existing predictor with the SDK for Python (Boto3), use the `create_monitor` method. Specify a name for the monitoring, and for `ResourceArn` specify the Amazon Resource Name (ARN) for the predictor to monitor. Use the `describe_monitor` method and provide the monitor ARN to get the status of the monitor. After you generate a forecast and then import more data, you can view the results of predictor monitoring. For more information see [Viewing Monitoring Results](predictor-monitoring-results.md). 

For information on required and optional parameters, see the [CreateMonitor](API_CreateMonitor.md) and [DescribeMonitor](API_DescribeMonitor.md). 

```
import boto3
                            
forecast = boto3.client('forecast')

create_monitor_response = forecast.create_monitor(
    MonitorName = 'monitor_name',
    ResourceArn = 'arn:aws:forecast:region:accountNumber:predictor/predictorName'
)

monitor_arn = create_monitor_response['MonitorArn']

describe_monitor_response = forecast.describe_monitor(
    MonitorArn = monitor_arn
)
print("Monitor status: " + describe_monitor_response['Status'])
```

------

# Viewing Monitoring Results


After you generate a forecast and then import more data, you can view the results of predictor monitoring. You can see a visualization of results with the Forecast console or you can programmatically retrieve results with the [ListMonitorEvaluations](API_ListMonitorEvaluations.md) operation. 

 The Forecast console displays graphs of results for each [predictor metric](metrics.md). Graphs include how each metric has changed over the lifetime of your predictor and predictor events, such as retraining. 

 The [ListMonitorEvaluations](API_ListMonitorEvaluations.md) operation returns metric results and predictor events for different windows of time. 

------
#### [ Console ]

**To view predictor monitoring results**

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 the predictor and choose the **Monitoring** tab. 
   +  The **Monitoring results** section shows how different accuracy metrics have changed over time. Use the dropdown list to change which metric the graph tracks.
   + The **Monitoring history** section lists the details for the different events tracked in the results.

    The following is an example of a graph of how the `Avg wQL` score for a predictor has changed over time. In this graph, notice that the `Avg wQL` value is increasing over time. This increase indicates that the predictor accuracy is decreasing. Use this information to determine whether you need to revalidate the model and take action.  
![\[Graph showing increasing Avg wQL score over time, indicating decreasing predictor accuracy.\]](http://docs.aws.amazon.com/forecast/latest/dg/images/predictor-drift.png)

------
#### [ SDK for Python (Boto3) ]

 To get monitoring results with the SDK for Python (Boto3), use the `list_monitor_evaluations` method. Provide the Amazon Resource Name (ARN) of the monitor, and optionally specify the maximum number of results to retrieve with the `MaxResults` parameter. Optionally specify a `Filter` to filter results. You can filter evaluations by a `EvaluationState` of either `SUCCESS` or `FAILURE`. The following code gets at maximum 20 successful monitoring evaluations. 

```
import boto3
                            
forecast = boto3.client('forecast')

monitor_results = forecast.list_monitor_evaluations(
    MonitorArn = 'monitor_arn',
    MaxResults = 20,
    Filters = [ 
      { 
         "Condition": "IS",
         "Key": "EvaluationState",
         "Value": "SUCCESS"
      }
   ]
)
print(monitor_results)
```

 The following is an example JSON response. 

```
{
  "NextToken": "string",
  "PredictorMonitorEvaluations": [
    {
      "MonitorArn": "MonitorARN",
      "ResourceArn": "PredictorARN",
      "EvaluationTime": "2020-01-02T00:00:00Z",
      "EvaluationState": "SUCCESS",
      "WindowStartDatetime": "2019-01-01T00:00:00Z",
      "WindowEndDatetime": "2019-01-03T00:00:00Z",
      "PredictorEvent": {
        "Detail": "Retrain",
        "Datetime": "2020-01-01T00:00:00Z"
      },
      "MonitorDataSource": {
        "DatasetImportJobArn": "arn:aws:forecast:region:accountNumber:dataset-import-job/*",
        "ForecastArn": "arn:aws:forecast:region:accountNumber:forecast/*",
        "PredictorArn": "arn:aws:forecast:region:accountNumber:predictor/*",
      
      },
      "MetricResults": [
        {
          "MetricName": "AverageWeightedQuantileLoss",
          "MetricValue": 0.17009070456599376
        },
        {
          "MetricName": "MAPE",
          "MetricValue": 0.250711322309796
        },
        {
          "MetricName": "MASE",
          "MetricValue": 1.6275608734888485
        },
        {
          "MetricName": "RMSE",
          "MetricValue": 3100.7125081405547
        },
        {
          "MetricName": "WAPE",
          "MetricValue": 0.17101159704738722}
      ]
    }
  ]
}
```

------

## Restrictions and Best Practices


Consider the following restrictions and best practices when working with predictor monitoring.
+ **Predictor monitoring is only available for auto predictors** – You cannot enable monitoring for legacy predictors that were created with AutoML or through manual selection. See [Upgrading to AutoPredictor](howitworks-predictor.md#upgrading-autopredictor).
+ **Predictor monitoring is unique per auto predictor** – You can only create one monitor per auto predictor.
+ **Predictor monitoring requires new data and generating forecasts** – As you import new data that is used to generate new forecasts, predictor monitoring results become available. If you are not importing new data or the newly imported data does not cover a full forecast horizon, you will not see monitoring results.
+ **Predictor monitoring requires new forecasts** – You must continuously generate new forecasts to generate monitoring results. If you are not generating new forecasts, you will not see monitoring results.
+  **Amazon Forecast will store data from each of your forecasts for predictor performance analysis** – Forecast stores these data even if you delete forecasts. To delete these data, delete the associated monitor.
+ The [StopResource](API_StopResource.md) operation will stop all current evaluations and all future evaluations.
+ The avgWQL metric is available only when you generate forecasts for quantiles other than the mean. 
+ In-progress monitor evaluations are not shown in the [ListMonitorEvaluations](API_ListMonitorEvaluations.md) operation. 

# Amazon Forecast Algorithms
Forecast Algorithms

An Amazon Forecast predictor uses an algorithm to train a model with your time series datasets. The trained model is then used to generate metrics and predictions. 

 If you are unsure of which algorithm to use to train your model, choose AutoML when creating a predictor and let Forecast train the optimal model for your datasets. Otherwise, you can manually select one of the Amazon Forecast algorithms. 

**Python notebooks**  
For a step-by-step guide on using AutoML, see [Getting Started with AutoML](https://github.com/aws-samples/amazon-forecast-samples/blob/master/notebooks/advanced/Getting_started_with_AutoML/Getting_started_with_AutoML.ipynb).

## Built-in Forecast Algorithms


 Amazon Forecast provides six built-in algorithms for you to choose from. These range from commonly used statistical algorithms like Autoregressive Integrated Moving Average (ARIMA), to complex neural network algorithms like CNN-QR and DeepAR\$1. 

### [CNN-QR](aws-forecast-algo-cnnqr.md)


 `arn:aws:forecast:::algorithm/CNN-QR` 

 Amazon Forecast CNN-QR, Convolutional Neural Network - Quantile Regression, is a proprietary machine learning algorithm for forecasting time series using causal convolutional neural networks (CNNs). CNN-QR works best with large datasets containing hundreds of time series. It accepts item metadata, and is the only Forecast algorithm that accepts related time series data without future values. 

### [DeepAR\$1](aws-forecast-recipe-deeparplus.md)


`arn:aws:forecast:::algorithm/Deep_AR_Plus`

 Amazon Forecast DeepAR\$1 is a proprietary machine learning algorithm for forecasting time series using recurrent neural networks (RNNs). DeepAR\$1 works best with large datasets containing hundreds of feature time series. The algorithm accepts forward-looking related time series and item metadata. 

### [Prophet](aws-forecast-recipe-prophet.md)


`arn:aws:forecast:::algorithm/Prophet`

 Prophet is a time series forecasting algorithm based on an additive model where non-linear trends are fit with yearly, weekly, and daily seasonality. It works best with time series with strong seasonal effects and several seasons of historical data. 

### [NPTS](aws-forecast-recipe-npts.md)


`arn:aws:forecast:::algorithm/NPTS`

 The Amazon Forecast Non-Parametric Time Series (NPTS) proprietary algorithm is a scalable, probabilistic baseline forecaster. NPTS is especially useful when working with sparse or intermittent time series. Forecast provides four algorithm variants: Standard NPTS, Seasonal NPTS, Climatological Forecaster, and Seasonal Climatological Forecaster. 

### [ARIMA](aws-forecast-recipe-arima.md)


`arn:aws:forecast:::algorithm/ARIMA`

 Autoregressive Integrated Moving Average (ARIMA) is a commonly used statistical algorithm for time-series forecasting. The algorithm is especially useful for simple datasets with under 100 time series. 

### [ETS](aws-forecast-recipe-ets.md)


`arn:aws:forecast:::algorithm/ETS`

 Exponential Smoothing (ETS) is a commonly used statistical algorithm for time-series forecasting. The algorithm is especially useful for simple datasets with under 100 time series, and datasets with seasonality patterns. ETS computes a weighted average over all observations in the time series dataset as its prediction, with exponentially decreasing weights over time. 

## Comparing Forecast Algorithms


 Use the following table to find the best option for your time series datasets. 


|  | Neural Networks | Flexible Local Algorithms | Baseline Algorithms |  | CNN-QR | DeepAR\$1 | Prophet | NPTS | ARIMA | ETS | 
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | 
| Computationally intensive training process | High | High | Medium | Low | Low | Low | 
| Accepts historical related time series\$1 | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | 
| Accepts forward-looking related time series\$1 | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | 
| Accepts item metadata (product color, brand, etc) | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | 
| Accepts the Weather Index built-in featurization | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | 
| Suitable for sparse datasets | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | 
| Performs Hyperparameter Optimization (HPO) | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | 
| Allows overriding default hyperparameter values  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[Yes\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-yes.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | ![\[No\]](http://docs.aws.amazon.com/forecast/latest/dg/images/icon-no.png)  | 

\$1For more information on related time series, see [Related Time Series](related-time-series-datasets.md). 

# Autoregressive Integrated Moving Average (ARIMA) Algorithm
ARIMA

Autoregressive Integrated Moving Average ([ARIMA](https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average)) is a commonly-used local statistical algorithm for time-series forecasting. ARIMA captures standard temporal structures (patterned organizations of time) in the input dataset. The Amazon Forecast ARIMA algorithm calls the [Arima function](https://cran.r-project.org/web/packages/forecast/forecast.pdf#Rfn.Arima.1) in the `Package 'forecast'` of the Comprehensive R Archive Network (CRAN).

## How ARIMA Works
How It Works

The ARIMA algorithm is especially useful for datasets that can be mapped to stationary time series. The statistical properties of stationary time series, such as autocorrelations, are independent of time. Datasets with stationary time series usually contain a combination of signal and noise. The signal may exhibit a pattern of sinusoidal oscillation or have a seasonal component. ARIMA acts like a filter to separate the signal from the noise, and then extrapolates the signal in the future to make predictions.

## ARIMA Hyperparameters and Tuning
Hyperparameters and Tuning

For information about ARIMA hyperparameters and tuning, see the `Arima` function documentation in the [Package 'forecast'](https://cran.r-project.org/web/packages/forecast/forecast.pdf) of [CRAN](https://cran.r-project.org).

Amazon Forecast converts the `DataFrequency` parameter specified in the [CreateDataset](API_CreateDataset.md) operation to the `frequency` parameter of the R [ts](https://www.rdocumentation.org/packages/stats/versions/3.6.1/topics/ts) function using the following table:


| DataFrequency (string) | R ts frequency (integer) | 
| --- | --- | 
| Y | 1 | 
| M | 12 | 
| W | 52 | 
| D | 7 | 
| H | 24 | 
| 30min | 2 | 
| 15min | 4 | 
| 10min | 6 | 
| 5min | 12 | 
| 1min | 60 | 

For frequencies less than 24 or short time series, the hyperparameters are set using the `auto.arima` function of the `Package 'forecast'` of [CRAN](https://cran.r-project.org). For frequencies greater than or equal to 24 and long time series, we use a Fourier series with K = 4, as described here, [Forecasting with long seasonal periods](https://robjhyndman.com/hyndsight/longseasonality/).

Supported data frequencies that aren't in the table default to a `ts` frequency of 1.

# CNN-QR Algorithm
CNN-QR

 Amazon Forecast CNN-QR, Convolutional Neural Network - Quantile Regression, is a proprietary machine learning algorithm for forecasting scalar (one-dimensional) time series using causal convolutional neural networks (CNNs). This supervised learning algorithm trains one global model from a large collection of time series and uses a quantile decoder to make probabilistic predictions.

**Topics**
+ [

## Getting Started with CNN-QR
](#aws-forecast-algo-cnnqr-getting-started)
+ [

## How CNN-QR Works
](#aws-forecast-algo-cnnqr-how-it-works)
+ [

## Using Related Data with CNN-QR
](#aws-forecast-algo-cnnqr-using-rts)
+ [

## CNN-QR Hyperparameters
](#aws-forecast-algo-cnnqr-hyperparameters)
+ [

## Tips and Best Practices
](#aws-forecast-algo-cnnqr-tips)

## Getting Started with CNN-QR
Getting Started

 You can train a predictor with CNN-QR in two ways: 

1. Manually selecting the CNN-QR algorithm.

1. Choosing AutoML (CNN-QR is part of AutoML).

 If you are unsure of which algorithm to use, we recommend selecting AutoML, and Forecast will select CNN-QR if it is the most accurate algorithm for your data. To see if CNN-QR was selected as the most accurate model, either use the [DescribePredictor](https://docs.aws.amazon.com/forecast/latest/dg/API_DescribePredictor.html) API or choose the predictor name in the console. 

Here are some key use cases for CNN-QR: 
+  **Forecast with large and complex datasets** - CNN-QR works best when trained with large and complex datasets. The neural network can learn across many datasets, which is useful when you have related time series and item metadata.
+  **Forecast with historical related time series** - CNN-QR does not require related time series to contain data points within the forecast horizon. This added flexibility allows you to include a broader range of related time series and item meta data, such as item price, events, web metrics, and product categories. 

## How CNN-QR Works
How It Works

CNN-QR is a sequence-to-sequence (Seq2Seq) model for probabilistic forecasting that tests how well a prediction reconstructs the decoding sequence, conditioned on the encoding sequence. 

The algorithm allows for different features in the encoding and the decoding sequences, so you can use a related time series in the encoder, and omit it from the decoder (and vice versa). By default, related time series with data points in the forecast horizon will be included in both the encoder and decoder. Related time series without data points in the forecast horizon will only be included in the encoder. 

CNN-QR performs quantile regression with a hierarchical causal CNN serving as a learnable feature extractor. 

To facilitate learning time-dependent patterns, such as spikes during weekends, CNN-QR automatically creates feature time series based on time-series granularity. For example, CNN-QR creates two feature time series (day-of-month and day-of-year) at a weekly time-series frequency. The algorithm uses these derived feature time series along with the custom feature time series provided during training and inference. The following example shows a target time series, `zi,t`, and two derived time-series features: `ui,1,t` represents the hour of the day, and `ui,2,t` represents the day of the week. 

![\[\]](http://docs.aws.amazon.com/forecast/latest/dg/images/cnnqr-time-frequencies.PNG)


CNN-QR automatically includes these feature time series based on the data frequency and the size of training data. The following table lists the features that can be derived for each supported basic time frequency. 


****  

| Frequency of the Time Series | Derived Features | 
| --- | --- | 
| Minute | minute-of-hour, hour-of-day, day-of-week, day-of-month, day-of-year | 
| Hour | hour-of-day, day-of-week, day-of-month, day-of-year | 
| Day | day-of-week, day-of-month, day-of-year | 
| Week | week-of-month, week-of-year | 
| Month | month-of-year | 

During training, each time series in the training dataset consists of a pair of adjacent context and forecast windows with fixed predefined lengths. This is shown in the figure below, where the context window is represented in green, and the forecast window is represented in blue. 

You can use a model trained on a given training set to generate predictions for time series in the training set, and for other time series. The training dataset consists of a target time series, which may be associated with a list of related time series and item metadata. 

The figure below shows how this works for an element of a training dataset indexed by `i`. The training dataset consists of a target time series, `zi,t`, and two associated related time series, `xi,1,t` and `xi,2,t`. The first related time series, `xi,1,t`, is a forward-looking time series, and the second, `xi,2,t`, is a historical time series. 

![\[\]](http://docs.aws.amazon.com/forecast/latest/dg/images/cnnqr-short-long-rts.png)


CNN-QR learns across the target time series, `zi,t`, and the related time series, `xi,1,t` and `xi,2,t`, to generate predictions in the forecast window, represented by the orange line. 

## Using Related Data with CNN-QR
Related Data

 CNNQR supports both historical and forward looking related time series datasets. If you provide a forward looking related time series dataset, any missing value will be filled using the [future filling method](howitworks-missing-values.md). For more information on historical and forward-looking related time series, see [Using Related Time Series Datasets](related-time-series-datasets.md). 

You can also use item metadata datasets with CNN-QR. These are datasets with static information on the items in your target time series. Item metadata is especially useful for coldstart forecasting scenarios where there is little to no historical data. For more information on item metadata, see [Item Metadata.](item-metadata-datasets.md)

## CNN-QR Hyperparameters
Hyperparameters

 Amazon Forecast optimizes CNN-QR models on selected hyperparameters. When manually selecting CNN-QR, you have the option to pass in training parameters for these hyperparameters. The following table lists the tunable hyperparameters of the CNN-QR algorithm. 


| Parameter Name | Values | Description | 
| --- | --- | --- | 
| context\$1length |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-algo-cnnqr.html)  |  The number of time points that the model reads before making predictions. Typically, CNN-QR has larger values for `context_length` than DeepAR\$1 because CNN-QR does not use lags to look at further historical data. If the value for `context_length` is outside of a predefined range, CNN-QR will automatically set the default `context_length` to an appropriate value.  | 
| use\$1related\$1data |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-algo-cnnqr.html)  |  Determines which kinds of related time series data to include in the model. Choose one of four options: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-algo-cnnqr.html) `HISTORICAL` includes all historical related time series, and `FORWARD_LOOKING` includes all forward-looking related time series. You cannot choose a subset of `HISTORICAL` or `FORWARD_LOOKING` related time series.   | 
| use\$1item\$1metadata |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-algo-cnnqr.html)  |  Determines whether the model includes item metadata.  Choose one of two options: [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-algo-cnnqr.html) `use_item_metadata` includes either all provided item metadata or none. You cannot choose a subset of item metadata.   | 
| epochs |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-algo-cnnqr.html)  |  The maximum number of complete passes through the training data. Smaller datasets require more epochs.  For large values of `ForecastHorizon` and `context_length`, consider decreasing epochs to improve the training time.   | 

### Hyperparameter Optimization (HPO)
Hyperparameter Optimization

Hyperparameter optimization (HPO) is the task of selecting the optimal hyperparameter values for a specific learning objective. With Forecast, you can automate this process in two ways: 

1. Choosing AutoML, and HPO will automatically run for CNN-QR.

1. Manually selecting CNN-QR and setting `PerformHPO = TRUE`.

Additional related time series and item metadata does not always improve the accuracy of your CNN-QR model. When you run AutoML or enable HPO, CNN-QR tests the accuracy of your model with and without the provided related time series and item metadata, and selects the model with the highest accuracy.

Amazon Forecast automatically optimizes the following three hyperparameters during HPO and provides you with the final trained values:
+ **context\$1length** - determines how far into the past the network can see. The HPO process automatically sets a value for `context_length` that maximizes model accuracy, while taking training time into account.
+ **use\$1related\$1data** - determines which forms of related time series data to include in your model. The HPO process automatically checks whether your related time series data improves the model, and selects the optimal setting.
+ **use\$1item\$1metadata** - determines whether to include item metadata in your model. The HPO process automatically checks whether your item metadata improves the model, and chooses the optimal setting.

**Note**  
If `use_related_data` is set to `NONE` or `HISTORICAL` when the `Holiday` supplementary feature is selected, this means that including holiday data does not improve model accuracy.

You can set the HPO configuration for the `context_length` hyperparameter if you set `PerformHPO = TRUE` during manual selection. However, you cannot alter any aspect of the HPO configuration if you choose AutoML. For more information on HPO configuration, refer to the [IntergerParameterRange](https://docs.aws.amazon.com/forecast/latest/dg/API_IntegerParameterRange.html) API. 

## Tips and Best Practices
Tips and Best Practices

 **Avoid large values for ForecastHorizon** - Using values over 100 for the `ForecastHorizon` will increase training time and can reduce model accuracy. If you want to forecast further into the future, consider aggregating to a higher frequency. For example, use `5min` instead of `1min`. 

 **CNNs allow for a higher context length** - With CNN-QR, you can set the `context_length` slightly higher than that for DeepAR\$1, as CNNs are generally more efficient than RNNs. 

 **Feature engineering of related data** - Experiment with different combinations of related time series and item metadata when training your model, and assess whether the additional information improves accuracy. Different combinations and transformations of related time series and item metadata will deliver different results.

 **CNN-QR does not forecast at the mean quantile ** – When you set `ForecastTypes` to `mean` with the [ CreateForecast](https://docs.aws.amazon.com/forecast/latest/dg/API_CreateForecast.html) API, forecasts will instead be generated at the median quantile (`0.5` or `P50`). 

# DeepAR\$1 Algorithm
DeepAR\$1

Amazon Forecast DeepAR\$1 is a supervised learning algorithm for forecasting scalar (one-dimensional) time series using recurrent neural networks (RNNs). Classical forecasting methods, such as autoregressive integrated moving average (ARIMA) or exponential smoothing (ETS), fit a single model to each individual time series, and then use that model to extrapolate the time series into the future. In many applications, however, you have many similar time series across a set of cross-sectional units. These time-series groupings demand different products, server loads, and requests for web pages. In this case, it can be beneficial to train a single model jointly over all of the time series. DeepAR\$1 takes this approach. When your dataset contains hundreds of feature time series, the DeepAR\$1 algorithm outperforms the standard ARIMA and ETS methods. You can also use the trained model for generating forecasts for new time series that are similar to the ones it has been trained on.

**Python notebooks**  
For a step-by-step guide on using the DeepAR\$1 algorithm, see [Getting Started with DeepAR\$1](https://github.com/aws-samples/amazon-forecast-samples/blob/master/notebooks/advanced/Getting_started_with_DeepAR%2B/Getting_started_with_DeepAR%2B.ipynb).

**Topics**
+ [

## How DeepAR\$1 Works
](#aws-forecast-recipe-deeparplus-how-it-works)
+ [

## DeepAR\$1 Hyperparameters
](#aws-forecast-recipe-deeparplus-hyperparameters)
+ [

## Tune DeepAR\$1 Models
](#aws-forecast-recipe-deeparplus-tune-model)

## How DeepAR\$1 Works
How It Works

During training, DeepAR\$1 uses a training dataset and an optional testing dataset. It uses the testing dataset to evaluate the trained model. In general, the training and testing datasets don't have to contain the same set of time series. You can use a model trained on a given training set to generate forecasts for the future of the time series in the training set, and for other time series. Both the training and the testing datasets consist of (preferably more than one) target time series. Optionally, they can be associated with a vector of feature time series and a vector of categorical features (for details, see [DeepAR Input/Output Interface](https://docs.aws.amazon.com/sagemaker/latest/dg/deepar.html#deepar-inputoutput) in the *SageMaker AI Developer Guide*). The following example shows how this works for an element of a training dataset indexed by `i`. The training dataset consists of a target time series, `zi,t`, and two associated feature time series, `xi,1,t` and `xi,2,t`.

![\[\]](http://docs.aws.amazon.com/forecast/latest/dg/images/forecast-recipe-deeparplus-ts-full-159.base.png)


The target time series might contain missing values (denoted in the graphs by breaks in the time series). DeepAR\$1 supports only feature time series that are known in the future. This allows you to run counterfactual "what-if" scenarios. For example, "What happens if I change the price of a product in some way?" 

Each target time series can also be associated with a number of categorical features. You can use these to encode that a time series belongs to certain groupings. Using categorical features allows the model to learn typical behavior for those groupings, which can increase accuracy. A model implements this by learning an embedding vector for each group that captures the common properties of all time series in the group. 

To facilitate learning time-dependent patterns, such as spikes during weekends, DeepAR\$1 automatically creates feature time series based on time-series granularity. For example, DeepAR\$1 creates two feature time series (day of the month and day of the year) at a weekly time-series frequency. It uses these derived feature time series along with the custom feature time series that you provide during training and inference. The following example shows two derived time-series features: `ui,1,t` represents the hour of the day, and `ui,2,t` the day of the week. 

![\[\]](http://docs.aws.amazon.com/forecast/latest/dg/images/forecast-recipe-deeparplus-ts-full-159.derived.png)


DeepAR\$1 automatically includes these feature time series based on the data frequency and the size of training data. The following table lists the features that can be derived for each supported basic time frequency. 


****  

| Frequency of the Time Series | Derived Features | 
| --- | --- | 
| Minute | minute-of-hour, hour-of-day, day-of-week, day-of-month, day-of-year | 
| Hour | hour-of-day, day-of-week, day-of-month, day-of-year | 
| Day | day-of-week, day-of-month, day-of-year | 
| Week | week-of-month, week-of-year | 
| Month | month-of-year | 

A DeepAR\$1 model is trained by randomly sampling several training examples from each of the time series in the training dataset. Each training example consists of a pair of adjacent context and prediction windows with fixed predefined lengths. The `context_length` hyperparameter controls how far in the past the network can see, and the `ForecastHorizon` parameter controls how far in the future predictions can be made. During training, Amazon Forecast ignores elements in the training dataset with time series shorter than the specified prediction length. The following example shows five samples, with a context length (highlighted in green) of 12 hours and a prediction length (highlighted in blue) of 6 hours, drawn from element `i`. For the sake of brevity, we've excluded the feature time series `xi,1,t` and `ui,2,t`.

![\[\]](http://docs.aws.amazon.com/forecast/latest/dg/images/forecast-recipe-deeparplus-ts-full-159.sampled.png)


To capture seasonality patterns, DeepAR\$1 also automatically feeds lagged (past period) values from the target time series. In our example with samples taken at an hourly frequency, for each time index `t = T`, the model exposes the `zi,t` values which occurred approximately one, two, and three days in the past (highlighted in pink).

![\[\]](http://docs.aws.amazon.com/forecast/latest/dg/images/forecast-recipe-deeparplus-ts-full-159.lags.png)


For inference, the trained model takes as input the target time series, which might or might not have been used during training, and forecasts a probability distribution for the next `ForecastHorizon` values. Because DeepAR\$1 is trained on the entire dataset, the forecast takes into account learned patterns from similar time series.

For information on the mathematics behind DeepAR\$1, see [DeepAR: Probabilistic Forecasting with Autoregressive Recurrent Networks](https://arxiv.org/abs/1704.04110) on the Cornell University Library website. 

## DeepAR\$1 Hyperparameters
Hyperparameters

The following table lists the hyperparameters that you can use in the DeepAR\$1 algorithm. Parameters in bold participate in hyperparameter optimization (HPO).


| Parameter Name | Description | 
| --- | --- | 
| context\$1length |  The number of time points that the model reads in before making the prediction. The value for this parameter should be about the same as the `ForecastHorizon`. The model also receives lagged inputs from the target, so `context_length` can be much smaller than typical seasonalities. For example, a daily time series can have yearly seasonality. The model automatically includes a lag of one year, so the context length can be shorter than a year. The lag values that the model picks depend on the frequency of the time series. For example, lag values for daily frequency are: previous week, 2 weeks, 3 weeks, 4 weeks, and year. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 
| epochs |  The maximum number of passes to go over the training data. The optimal value depends on your data size and learning rate. Smaller datasets and lower learning rates both require more epochs, to achieve good results. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 
| learning\$1rate |  The learning rate used in training. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 
| learning\$1rate\$1decay |  The rate at which the learning rate decreases. At most, the learning rate is reduced `max_learning_rate_decays` times, then training stops. This parameter will be used only if `max_learning_rate_decays` is greater than 0. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 
| likelihood |  The model generates a probabilistic forecast, and can provide quantiles of the distribution and return samples. Depending on your data, choose an appropriate likelihood (noise model) that is used for uncertainty estimates. Valid values [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html) [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 
| max\$1learning\$1rate\$1decays |  The maximum number of learning rate reductions that should occur. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html) | 
| num\$1averaged\$1models |  In DeepAR\$1, a training trajectory can encounter multiple models. Each model might have different forecasting strengths and weaknesses. DeepAR\$1 can average the model behaviors to take advantage of the strengths of all models. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 
| num\$1cells |  The number of cells to use in each hidden layer of the RNN. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 
| num\$1layers |  The number of hidden layers in the RNN. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-deeparplus.html)  | 

## Tune DeepAR\$1 Models
Model Tuning

To tune Amazon Forecast DeepAR\$1 models, follow these recommendations for optimizing the training process and hardware configuration. 

### Best Practices for Process Optimization
Best Practices

 To achieve the best results, follow these recommendations: 
+ Except when splitting the training and testing datasets, always provide entire time series for training and testing, and when calling the model for inference. Regardless of how you set `context_length`, don't divide the time series or provide only a part of it. The model will use data points further back than `context_length` for the lagged values feature.
+ For model tuning, you can split the dataset into training and testing datasets. In a typical evaluation scenario, you should test the model on the same time series used in training, but on the future `ForecastHorizon` time points immediately after the last time point visible during training. To create training and testing datasets that satisfy these criteria, use the entire dataset (all of the time series) as a testing dataset and remove the last `ForecastHorizon` points from each time series for training. This way, during training, the model doesn't see the target values for time points on which it is evaluated during testing. In the test phase, the last `ForecastHorizon` points of each time series in the testing dataset are withheld and a prediction is generated. The forecast is then compared with the actual values for the last `ForecastHorizon` points. You can create more complex evaluations by repeating time series multiple times in the testing dataset, but cutting them off at different end points. This produces accuracy metrics that are averaged over multiple forecasts from different time points.
+ Avoid using very large values (> 400) for the `ForecastHorizon` because this slows down the model and makes it less accurate. If you want to forecast further into the future, consider aggregating to a higher frequency. For example, use `5min` instead of `1min`.
+ Because of lags, the model can look further back than `context_length`. Therefore, you don't have to set this parameter to a large value. A good starting point for this parameter is the same value as the `ForecastHorizon`.
+ Train DeepAR\$1 models with as many time series as are available. Although a DeepAR\$1 model trained on a single time series might already work well, standard forecasting methods such as ARIMA or ETS might be more accurate and are more tailored to this use case. DeepAR\$1 starts to outperform the standard methods when your dataset contains hundreds of feature time series. Currently, DeepAR\$1 requires that the total number of observations available, across all training time series, is at least 300.

# Exponential Smoothing (ETS) Algorithm
ETS

Exponential Smoothing [(ETS)](https://en.wikipedia.org/wiki/Exponential_smoothing) is a commonly-used local statistical algorithm for time-series forecasting. The Amazon Forecast ETS algorithm calls the [ets function](https://cran.r-project.org/web/packages/forecast/forecast.pdf#Rfn.ets.1) in the `Package 'forecast'` of the Comprehensive R Archive Network (CRAN).

## How ETS Works
How It Works

The ETS algorithm is especially useful for datasets with seasonality and other prior assumptions about the data. ETS computes a weighted average over all observations in the input time series dataset as its prediction. The weights are exponentially decreasing over time, rather than the constant weights in simple moving average methods. The weights are dependent on a constant parameter, which is known as the smoothing parameter.

## ETS Hyperparameters and Tuning
Hyperparameters and Tuning

For information about ETS hyperparameters and tuning, see the `ets` function documentation in the [Package 'forecast'](https://cran.r-project.org/web/packages/forecast/forecast.pdf) of [CRAN](https://cran.r-project.org).

Amazon Forecast converts the `DataFrequency` parameter specified in the [CreateDataset](API_CreateDataset.md) operation to the `frequency` parameter of the R [ts](https://www.rdocumentation.org/packages/stats/versions/3.6.1/topics/ts) function using the following table:


| DataFrequency (string) | R ts frequency (integer) | 
| --- | --- | 
| Y | 1 | 
| M | 12 | 
| W | 52 | 
| D | 7 | 
| H | 24 | 
| 30min | 2 | 
| 15min | 4 | 
| 10min | 6 | 
| 5min | 12 | 
| 1min | 60 | 

Supported data frequencies that aren't in the table default to a `ts` frequency of 1.

# Non-Parametric Time Series (NPTS) Algorithm
NPTS

The Amazon Forecast Non-Parametric Time Series (NPTS) algorithm is a scalable, probabilistic baseline forecaster. It predicts the future value distribution of a given time series by sampling from past observations. The predictions are bounded by the observed values. NPTS is especially useful when the time series is intermittent (or sparse, containing many 0s) and bursty. For example, forecasting demand for individual items where the time series has many low counts. Amazon Forecast provides variants of NPTS that differ in which of the past observations are sampled and how they are sampled. To use an NPTS variant, you choose a hyperparameter setting.

## How NPTS Works
How It Works

Similar to classical forecasting methods, such as exponential smoothing (ETS) and autoregressive integrated moving average (ARIMA), NPTS generates predictions for each time series individually. The time series in the dataset can have different lengths. The time points where the observations are available are called the training range and the time points where the prediction is desired are called the prediction range.

Amazon Forecast NPTS forecasters have the following variants: NPTS, seasonal NPTS, climatological forecaster, and seasonal climatological forecaster.

**Topics**
+ [

### NPTS
](#aws-forecast-recipe-npts-variants-npts)
+ [

### Seasonal NPTS
](#aws-forecast-recipe-npts-variants-seasonal)
+ [

### Climatological Forecaster
](#aws-forecast-recipe-npts-variants-climatological)
+ [

### Seasonal Climatological Forecaster
](#aws-forecast-recipe-npts-variants-seasonal-climatological)
+ [

### Seasonal Features
](#aws-forecast-recipe-npts-seasonal-features)
+ [

### Best Practices
](#aws-forecast-recipe-npts-recommended-practices)

### NPTS


In this variant, predictions are generated by sampling from all observations in the training range of the time series. However, instead of uniformly sampling from all of the observations, this variant assigns weight to each of the past observations according to how far it is from the current time step where the prediction is needed. In particular, it uses weights that decay exponentially according to the distance of the past observations. In this way, the observations from the recent past are sampled with much higher probability than the observations from the distant past. This assumes that the near past is more indicative for the future than the distant past. You can control the amount of decay in the weights with the `exp_kernel_weights` hyperparameter.

To use this NPTS variant in Amazon Forecast, set the `use_seasonal_model` hyperparameter to `False` and accept all other default settings.

### Seasonal NPTS


The seasonal NPTS variant is similar to NPTS except that instead of sampling from all of the observations, it uses only the observations from the past *seasons *. By default, the season is determined by the granularity of the time series. For example, for an hourly time series, to predict for hour *t*, this variant samples from the observations corresponding to the hour *t* on the previous days. Similar to NPTS, observation at hour *t* on the previous day is given more weight than the observations at hour *t* on earlier days. For more information about how to determine seasonality based on the granularity of the time series, see [Seasonal Features](#aws-forecast-recipe-npts-seasonal-features).

### Climatological Forecaster


The climatological forecaster variant samples all of the past observations with uniform probability. 

To use the climatological forecaster, set the `kernel_type` hyperparameter to `uniform` and the `use_seasonal_model` hyperparameter to `False`. Accept the default settings for all other hyperparameters.

### Seasonal Climatological Forecaster


Similar to seasonal NPTS, the seasonal climatological forecaster samples the observations from past seasons, but samples them with uniform probability. 

To use the seasonal climatological forecaster, set the `kernel_type` hyperparameter to `uniform`. Accept all other default settings for all of the other hyperparameters.

### Seasonal Features


To determine what corresponds to a season for the seasonal NPTS and seasonal climatological forecaster, use the features listed in the following table. The table lists the derived features for the supported basic time frequencies, based on granularity. Amazon Forecast includes these feature time series, so you don't have to provide them.


****  

| Frequency of the Time Series | Feature to Determine Seasonality | 
| --- | --- | 
| Minute | minute-of-hour | 
| Hour | hour-of-day | 
| Day | day-of-week | 
| Week | day-of-month | 
| Month | month-of-year | 

### Best Practices


When using the Amazon Forecast NPTS algorithms, consider the following best practices for preparing the data and achieving optimal results:
+ Because NPTS generates predictions for each time series individually, provide the entire time series when calling the model for prediction. Also, accept the default value of the `context_length` hyperparameter. This causes the algorithm to use the entire time series. 
+  If you change the `context_length` (because the training data is too long), make sure it is large enough and covers multiple past seasons. For example, for a daily time series, this value must be at least 365 days (provided that you have that amount of data). 

## NPTS Hyperparameters
Hyperparameters

The following table lists the hyperparameters that you can use in the NPTS algorithm.


| Parameter Name | Description | 
| --- | --- | 
| context\$1length | The number of time-points in the past that the model uses for making the prediction. By default, it uses all of the time points in the training range. Typically, the value for this hyperparameter should be large and should cover multiple past seasons. For example, for the daily time series this value must be at least 365 days. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-npts.html)  | 
| kernel\$1type | The kernel to use to define the weights used for sampling past observations. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-npts.html)  | 
| exp\$1kernel\$1weights |  Valid only when `kernel_type` is `exponential`. The scaling parameter of the kernel. For faster (exponential) decay in the weights given to the observations in the distant past, use a large value. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-npts.html)  | 
| use\$1seasonal\$1model | Whether to use a seasonal variant. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-npts.html)  | 
| use\$1default\$1time\$1features |  Valid only for the *seasonal NPTS* and *seasonal climatological forecaster* variants. Whether to use seasonal features based on the granularity of the time series to determine seasonality. [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/forecast/latest/dg/aws-forecast-recipe-npts.html)  | 

# Prophet Algorithm
Prophet

[Prophet](https://facebook.github.io/prophet/) is a popular local Bayesian structural time series model. The Amazon Forecast Prophet algorithm uses the [Prophet class](https://facebook.github.io/prophet/docs/quick_start.html#python-ap) of the Python implementation of Prophet.

## How Prophet Works
How It Works

Prophet is especially useful for datasets that:
+ Contain an extended time period (months or years) of detailed historical observations (hourly, daily, or weekly)
+ Have multiple strong seasonalities
+ Include previously known important, but irregular, events
+ Have missing data points or large outliers
+ Have non-linear growth trends that are approaching a limit

Prophet is an additive regression model with a piecewise linear or logistic growth curve trend. It includes a yearly seasonal component modeled using Fourier series and a weekly seasonal component modeled using dummy variables.

For more information, see [Prophet: forecasting at scale](https://research.facebook.com/blog/2017/2/prophet-forecasting-at-scale/).

## Prophet Hyperparameters and Related Time Series
Hyperparameters and Related Time Series

Amazon Forecast uses the default Prophet [hyperparameters](https://facebook.github.io/prophet/docs/quick_start.html#python-ap). Prophet also supports related time-series as features, provided to Amazon Forecast in the related time-series CSV file.