quick_start.Rmd 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. This document provides a very brief introduction to the Prophet API. For a detailed guide on using Prophet, please visit the main site at [https://facebook.github.io/prophet/](https://facebook.github.io/prophet/).
  18. 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.
  19. First we read in the data and create the outcome variable.
  20. ```{r, results= "hide"}
  21. library(readr)
  22. df <- read_csv('../tests/testthat/data.csv')
  23. ```
  24. We call the `prophet` function to fit the model. The first argument is the historical dataframe. Additional arguments control how Prophet fits the data.
  25. ```{r}
  26. m <- prophet(df)
  27. ```
  28. We need to construct a dataframe for prediction. The `make_future_dataframe` function takes the model object and a number of periods to forecast:
  29. ```{r}
  30. future <- make_future_dataframe(m, periods = 365)
  31. head(future)
  32. ```
  33. As with most modeling procedures in R, we use the generic `predict` function to get our forecast:
  34. ```{r}
  35. forecast <- predict(m, future)
  36. head(forecast)
  37. ```
  38. You can use the generic `plot` function to plot the forecast, but you must also pass the model in to be plotted:
  39. ```{r}
  40. plot(m, forecast)
  41. ```
  42. You can plot the components of the forecast using the `prophet_plot_components` function:
  43. ```{r}
  44. prophet_plot_components(m, forecast)
  45. ```