Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OO approach instead of string approach for API #11

Closed
paulhendricks opened this issue Mar 14, 2016 · 2 comments
Closed

OO approach instead of string approach for API #11

paulhendricks opened this issue Mar 14, 2016 · 2 comments

Comments

@paulhendricks
Copy link

How do you feel about an OO to the API instead of using strings and if statements to specify the model? It might provide greater flexibility and cleaner code.

library(forecast)
library(forecastHybrid)

some_ts <- ts(1:144, frequency = 12)
model_1 <- forecast::stlf(some_ts)
model_2 <- forecast::ets(some_ts)
model_3 <- forecast::auto.arima(some_ts)
model_4 <- forecast::nnetar(some_ts)

ensembled_model <- forecastHybrid::hybridModel(model_1, model_2, model_3, model_4, ...) # other args
class(ensembled_model) # "forecast" "ensemble"

# other API calls consistent with forecast, e.g.
plot(forecast(ensembled_model, h = 14))

hybridModel <- function(models, ...) {
  for (model in models) {
    # code that fits and finds weights and ensembles
  }
  return(ensembled_model)
}

forecastHybrid::hybridModel auto-magically finds weights and returns an object of class c("forecast", "ensemble") that is consistent with all the other functions in the forecast package.

@dashaub
Copy link
Collaborator

dashaub commented Mar 14, 2016

I like this approach. So long as the individual models have a forecast method this would allow users to specify custom individual models as well.

The existing approach has one advantage in that it allows users to build ensembles quickly, e.g. hm <- hybridModel(some_ts)

Perhaps we should overload the method or create a wrapper similar to glm() and glm.fit() so that users can use either function, according to taste.

@dashaub
Copy link
Collaborator

dashaub commented Mar 15, 2016

This might cause some additional headaches when it comes time to implement parallelization. I'm planning to implement parallelization both between and within models (e.g. on a 6-core machine auto.arima runs with two cores, tbats with 2 cores, and ets with one, and nnetar with one. They are all called using foreach). This would involve lots of testing and tweaks to compare the average runtime of auto.arima/nnetar/ets/tbats/stlm models so that a relatively optimal parallelization strategy can be selected and the overall ensemble takes about as long as the slowest individual model. Custom models make this difficult. We'll also need to consider whether the custom models need a forecast() or also would work with a predict() method. Lots to consider, but I like the idea.

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

No branches or pull requests

2 participants