quick_start.Rmd 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ---
  2. title: "Quick Start Guide to Using Prophet"
  3. author: "Sean J. Taylor and Ben Letham"
  4. date: "`r Sys.Date()`"
  5. output: rmarkdown::html_vignette
  6. vignette: >
  7. %\VignetteIndexEntry{Quick Start Guide to Using Prophet}
  8. %\VignetteEngine{knitr::rmarkdown}
  9. \usepackage[utf8]{inputenc}
  10. ---
  11. ```{r, echo = FALSE, message = FALSE}
  12. knitr::opts_chunk$set(collapse = T, comment = "#>")
  13. options(tibble.print_min = 4L, tibble.print_max = 4L)
  14. library(prophet)
  15. library(dplyr)
  16. ```
  17. Prophet uses the normal model fitting API. We provide a `prophet` function that performs fitting and returns a model object. You can then call `predict` and `plot` on this model object.
  18. First we read in the data and create the outcome variable.
  19. ```{r, results= "hide"}
  20. library(readr)
  21. df <- read_csv('../tests/testthat/data.csv')
  22. ```
  23. We call the `prophet` function to fit the model. The first argument is the historical dataframe. Additional arguments control how Prophet fits the data.
  24. ```{r}
  25. m <- prophet(df)
  26. ```
  27. We need to construct a dataframe for prediction. The `make_future_dataframe` function takes the model object and a number of periods to forecast:
  28. ```{r}
  29. future <- make_future_dataframe(m, periods = 365)
  30. head(future)
  31. ```
  32. As with most modeling procedures in R, we use the generic `predict` function to get our forecast:
  33. ```{r}
  34. forecast <- predict(m, future)
  35. head(forecast)
  36. ```
  37. You can use the generic `plot` function to plot the forecast, but you must also pass the model in to be plotted:
  38. ```{r}
  39. plot(m, forecast)
  40. ```
  41. Just as in Python, you can plot the components of the forecast. In R, you use the `prophet_plot_components` function instead of an instance method:
  42. ```{r}
  43. prophet_plot_components(m, forecast)
  44. ```