Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

issues setting up a simple forecast model #121

Open
martinbel opened this issue Dec 24, 2016 · 1 comment
Open

issues setting up a simple forecast model #121

martinbel opened this issue Dec 24, 2016 · 1 comment
Labels

Comments

@martinbel
Copy link

martinbel commented Dec 24, 2016

Hi,

I wanted to implement a simple forecast model (mostly to try the platform) but I couldn't get it working. It's a bit different from the examples, so perhaps if it ends up working it could help improve the docs. It should be easily reproducible with the data below.

ws <- workspace() # I assume you have this
# AzureML Workspace
# Workspace ID : bla 
# API endpoint : bla

#### The time series data. It's actually the monthly ARS/USD pair.
y = structure(c(4.136, 4.1481, 4.15094736842105, 4.208, 4.30252380952381, 
                4.28642857142857, 4.29709523809524, 4.36522727272727, 4.4385, 
                4.4407, 4.78166666666667, 4.70657894736842, 4.80904761904762, 
                4.74694444444444, 4.79659090909091, 4.98911764705882, 5.49942857142857, 
                5.9485, 6.31, 6.31590909090909, 6.31789473684211, 6.27772727272727, 
                6.374, 6.53944444444444, 7.37619047619048, 7.745625, 8.07277777777778, 
                8.681, 9.28, 8.44, 8.35647058823529, 9.01533333333333, 9.355, 
                9.80714285714286, 9.85363636363636, 9.59875, 11.5059090909091, 
                11.9263157894737, 10.9033333333333, 10.502, 11.1985, 11.8368421052632, 
                12.2636363636364, 13.3863157894737, 14.85, 14.8147619047619, 
                13.3583333333333, 13.136, 13.7163636363636, 13.1283333333333, 
                12.75, 12.596, 12.64625, 13.015, 14.3776470588235, 15.2385, 15.7378947368421, 
                15.9309090909091, 15.18625, 13.8333333333333, 13.9156666666667, 
                15.2083333333333, 15.1555555555556, 14.64, 14.45, 15.09, 15.242, 
                15.1256, 15.3643333333333, 15.416, 15.7596666666667, 16.145), .Tsp = c(2011, 
                                                                                       2016.91666666667, 12), class = "ts")

# Fit a baseline model
fit = Arima(y, order = c(2, 1, 2))

# the "predict" function for the endpoint
predict_arima <- function(h){
  require(forecast)
  yhat = forecast(fit, h=h)
  x = as.data.frame(yhat)
  data.frame(yearmon = rownames(x), forecast = x[,1], stringsAsFactors = FALSE)
}

out_schema = predict_arima(h = 10)
str(out_schema)
# 'data.frame':	10 obs. of  2 variables:
# $ yearmon : chr  "Jan 2017" "Feb 2017" "Mar 2017" "Apr 2017" ...
# $ forecast: num  16.2 16 16.1 16.1 16.1 ...

### Here is the web service definition:
ep <- publishWebService(ws = ws, fun = predict_arima, name = "forecast_arima_h", 
                        inputSchema = list(h = "numeric"), 
                        outputSchema = out_schema,
                        data.frame = FALSE, 
                        packages = 'forecast')

After the packages are downloaded (I'll leave it out) This is the result:

consume(ep, list(h = 10))
Request failed with status 401. Waiting 3.0 seconds before retry
.
Error: AzureML returns error code:
HTTP status code : 400
AzureML error code  : LibraryExecutionError

Module execution encountered an internal library error.
The following error occurred during evaluation of R script: 
R_tryEval: return error: Error in do.call(..fun, inputDF[i, ]) : second argument must be a list
@andrie
Copy link
Contributor

andrie commented Mar 28, 2017

Your outputSchema doesn't look like a valid output schema. If you don't specify this argument, the function will guess the result type.

Please remove this argument and try again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants