<jupyter_start><jupyter_text>Create DeepAR+ predcitors with HPO* **About 90 mins may be elapsed**<jupyter_code>import boto3
from time import sleep
import pandas as pd
import json
import time
import pprint
import numpy as np
# 다른 노트북에서 저장된 변수들을 불러옴
%store -r
session = boto3.Session(region_name=region)
forecast = session.client(service_name='forecast')
forecast_query = session.client(service_name='forecastquery')<jupyter_output><empty_output><jupyter_text>Hyperparameters<jupyter_code>forecastHorizon = 31 # the number of forecasts
NumberOfBacktestWindows = 2 # the number of backtests
BackTestWindowOffset = 31 
ForecastFrequency = "D"<jupyter_output><empty_output><jupyter_text>The detailed parameter info is [here](https://docs.aws.amazon.com/forecast/latest/dg/metrics.html) 를 보세요.  Predictor algorithms<jupyter_code>deepAR_Plus_algorithmArn = 'arn:aws:forecast:::algorithm/Deep_AR_Plus'<jupyter_output><empty_output><jupyter_text>DeepAR+<jupyter_code># DeepAR+ Specifics
deeparp_predictorName= project+'_deeparp_algo_HPO' + suffix
# Build DeepAR+:
deeparp_create_predictor_response=forecast.create_predictor(
      PredictorName=deeparp_predictorName, 
      AlgorithmArn=deepAR_Plus_algorithmArn,
      ForecastHorizon=forecastHorizon,
      PerformAutoML= False,
      PerformHPO=True,
      EvaluationParameters= {"NumberOfBacktestWindows": NumberOfBacktestWindows, 
                             "BackTestWindowOffset": BackTestWindowOffset}, 
      InputDataConfig= {"DatasetGroupArn": target_datasetGroupArn, "SupplementaryFeatures": [ 
                         { 
                            "Name": "holiday",
                            "Value": "US"
                         }
                      ]},
      FeaturizationConfig= {"ForecastFrequency": ForecastFrequency, 
                            "ForecastDimensions":
                            ["store"],
                            
                            "Featurizations": 
                            [
                              {"AttributeName": "target_value", 
                               "FeaturizationPipeline": 
                                [
                                  {"FeaturizationMethodName": "filling", 
                                   "FeaturizationMethodParameters": 
                                    {"frontfill": "none", 
                                     "middlefill": "zero", 
                                     "backfill": "zero"}
                                  }
                                ]
                              }
                            ]
                           }
                                                 )<jupyter_output><empty_output><jupyter_text>Check if the predictors are active<jupyter_code># forecast.list_predictors(Filters=[
#     {"Condition": "IS",
#      "Key": "DatasetGroupArn", 
#      "Value": datasetGroupArn}
# ])
target_deepar_hpo_predictorArn = deeparp_create_predictor_response["PredictorArn"]
%%time
# Check the Prophet status

while True:
    createDeeparpPredictorStatus = forecast.describe_predictor(PredictorArn= target_deepar_hpo_predictorArn)['Status']    
    print("DeepARP: ", createDeeparpPredictorStatus)          
    if createDeeparpPredictorStatus != 'ACTIVE' and createDeeparpPredictorStatus != 'CREATE_FAILED':
        sleep(60)
    else:
        break
# 90 mins elapsed
forecast.describe_predictor(PredictorArn= target_deepar_hpo_predictorArn)<jupyter_output><empty_output><jupyter_text>Predictor evaluation  DeepAR+Same as Prophet and ARIMA, now you should look at the metrics from it.<jupyter_code># DeepAR+ Metrics
# deepar_predictor_arn = deeparp_create_predictor_response['PredictorArn']
deeparp_metrics = forecast.get_accuracy_metrics(PredictorArn=target_deepar_hpo_predictorArn)
pp = pprint.PrettyPrinter()
pp.pprint(deeparp_metrics)
%store target_deepar_hpo_predictorArn<jupyter_output>Stored 'target_prophet_predictorArn' (str)
Stored 'target_deepar_predictorArn' (str)
{'fraction_non_alphanumeric': 0.08414971112785732, 'fraction_numerical': 0.003265511178095956, 'mean_word_length': 2.477729257641921, 'pattern_counts': {'":': 19, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '154318', 'license': 'MIT', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1131, 'n_words': 185, 'path': 'StoreItemDemand/7.Option_Create_Target_Predictors_HPO.ipynb', 'repo_name': 'gonsoomoon-ml/ForecastTrafficVolume', 'size': '3981'}