Hi R com.
i am trying to call an rest API, the model is running a forecast. Seems to be running fine, but i would like the call to include more then one value. lets say i want a forecast from a period of 1 month and
install.packages("RCurl")
install.packages("rjson")
library("RCurl")
library("rjson")
# Accept SSL certificates issued by public Certificate Authorities
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"), ssl.verifypeer = FALSE))
h = basicTextGatherer()
hdr = basicHeaderGatherer()
# Request data goes here
# The example below assumes JSON formatting which may be updated
# depending on the format your endpoint expects.
# More information can be found here:
# https://docs.microsoft.com/azure/machine-learning/how-to-deploy-advanced-entry-script
req = fromJSON('{
"data": [
{
"WeekStarting": "1992-10-15",
"Store": 2,
"Brand": "dominicks",
"Advert": 1,
"Price": 10,
"Age60": 0.3,
"COLLEGE": 0.0,
"INCOME": 0.0,
"Hincome150": 0.0,
"Large HH": 0.0,
"Minorities": 0.0,
"WorkingWoman": 0.0,
"SSTRDIST": 0.0,
"SSTRVOL": 0.0,
"CPDIST5": 0.0,
"CPWVOL5": 0.0
}
],
"quantiles": [
0.025,
0.975
]
}')
body = enc2utf8(toJSON(req))
api_key = "xxx" # Replace this with the API key for the web service
authz_hdr = paste('Bearer', api_key, sep=' ')
h$reset()
# The azureml-model-deployment header will force the request to go to a specific deployment.
# Remove this header to have the request observe the endpoint traffic rules
curlPerform(
url = "http://3f0a0dcf-2098-4b16-8782-0be174eaf138.westeurope.azurecontainer.io/score",
httpheader=c('Content-Type' = "application/json", 'Authorization' = authz_hdr),
postfields=body,
writefunction = h$update,
headerfunction = hdr$update,
verbose = TRUE
)
headers = hdr$value()
httpStatus = headers["status"]
if (httpStatus >= 400)
{
print(paste("The request failed with status code:", httpStatus, sep=" "))
# Print the headers - they include the request ID and the timestamp, which are useful for debugging the failure
print(headers)
}
print("Result:")
result = h$value()
print(result)
}```
Result:
[1] "\"{\\\"forecast\\\": [19428.415097965728], \\\"prediction_interval\\\": [\\\"[-18099.20901976846, 56956.03921569991]\\\"], \\\"index\\\": [{\\\"WeekStarting\\\": 719107200000, \\\"Store\\\": 2, \\\"Brand\\\": \\\"dominicks\\\"}]}\""
The above is forecast for 1 week (freq = 1 week). How do i get a list or iterate this so i get 1 month + ?