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