Created
June 26, 2018 20:14
-
-
Save thomasnield/4abba1a5472c6df1df4f0827807555ed to your computer and use it in GitHub Desktop.
Facebook Prophet Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(prophet) | |
| library(dplyr) | |
| df <- read.csv('http://bit.ly/2po0xPJ') %>% mutate(y=log(y)) | |
| #floor and cap | |
| lower = quantile(df$y, .05) | |
| upper = quantile(df$y, .95) | |
| df <- df %>% mutate(floor = lower, cap = upper) | |
| # modeling | |
| m <- prophet(df, | |
| changepoint.prior.scale=0.01, | |
| growth = 'logistic') | |
| future <- make_future_dataframe(m, periods = (24*12*365), | |
| freq = 60 * 5, | |
| include_history = FALSE) %>% mutate(floor = lower, cap = upper) | |
| # forecast every 5 minutes | |
| forecast <- predict(m,future) | |
| #prophet_plot_components(m, forecast) | |
| write.csv(forecast %>% | |
| select(ds, yhat_lower, yhat_upper, yhat) %>% | |
| mutate(floor = exp(lower), | |
| cap = exp(upper), | |
| ln_yhat_lower = yhat_lower, | |
| ln_yhat_upper = yhat_upper, | |
| ln_yhat = yhat, | |
| ln_floor = lower, | |
| ln_cap = upper, | |
| yhat_lower = exp(yhat_lower), | |
| yhat_upper = exp(yhat_upper), | |
| yhat = exp(yhat) | |
| ), 'problem_output.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment