Skip to content

Instantly share code, notes, and snippets.

@jroberayalas
Last active April 16, 2017 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jroberayalas/519af80a1486ed66d224483ac98ab69d to your computer and use it in GitHub Desktop.
Save jroberayalas/519af80a1486ed66d224483ac98ab69d to your computer and use it in GitHub Desktop.
results <- vector(mode = 'numeric', length = nrow(prophetGrid))
# Search best parameters
for (i in seq_len(nrow(prophetGrid))) {
parameters <- prophetGrid[i, ]
if (parameters$growth == 'logistic') {train$cap <- parameters$capacity}
m <- prophet(train, growth = parameters$growth, holidays = holidays,
seasonality.prior.scale = parameters$seasonality_prior_scale,
changepoint.prior.scale = parameters$changepoint_prior_scale,
holidays.prior.scale = parameters$holidays_prior_scale)
future <- make_future_dataframe(m, periods = 184)
if (parameters$growth == 'logistic') {future$cap <- parameters$capacity}
# NOTE: There's a problem in function names with library(caret)
forecast <- predict(m, future)
results[i] <- forecast::accuracy(forecast[forecast$ds %in% valid$ds, 'yhat'], valid$y)[ , 'MAE']
}
prophetGrid <- cbind(prophetGrid, results)
best_params <- prophetGrid[prophetGrid$results == min(results), ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment