Skip to content

Commit

Permalink
Minor documentation changes (facebook#2207)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cuong Duong authored Jun 25, 2022
1 parent 55ced96 commit f52fddf
Show file tree
Hide file tree
Showing 17 changed files with 48,077 additions and 166 deletions.
11 changes: 5 additions & 6 deletions docs/_docs/additional_topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ A common setting for forecasting is fitting models that need to be updated as ad
# Python
def stan_init(m):
"""Retrieve parameters from a trained model.
Retrieve parameters from a trained model in the format
used to initialize a new Stan model.
Parameters
----------
m: A trained model of the Prophet class.
Returns
-------
A Dictionary containing retrieved parameters of m.
"""
res = {}
for pname in ['k', 'm', 'sigma_obs']:
Expand All @@ -104,7 +104,7 @@ def stan_init(m):
res[pname] = m.params[pname][0]
return res

df = pd.read_csv('../examples/example_wp_log_peyton_manning.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')
df1 = df.loc[df['ds'] < '2016-01-19', :] # All data except the last day
m1 = Prophet().fit(df1) # A model fit to all data except the last day

Expand Down Expand Up @@ -132,4 +132,3 @@ These github repositories provide examples of building on top of Prophet in ways
* [forecastr](https://github.com/garethcull/forecastr): A web app that provides a UI for Prophet.

* [NeuralProphet](https://github.com/ourownstory/neural_prophet): A Prophet-style model implemented in pytorch, to be more adaptable and extensible.

17 changes: 8 additions & 9 deletions docs/_docs/multiplicative_seasonality.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ By default Prophet fits additive seasonalities, meaning the effect of the season

```R
# R
df <- read.csv('../examples/example_air_passengers.csv')
df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_air_passengers.csv')
m <- prophet(df)
future <- make_future_dataframe(m, 50, freq = 'm')
forecast <- predict(m, future)
plot(m, forecast)
```
```python
# Python
df = pd.read_csv('../examples/example_air_passengers.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_air_passengers.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(50, freq='MS')
forecast = m.predict(future)
fig = m.plot(forecast)
```
![png](/prophet/static/multiplicative_seasonality_files/multiplicative_seasonality_4_0.png)

![png](/prophet/static/multiplicative_seasonality_files/multiplicative_seasonality_4_0.png)


This time series has a clear yearly cycle, but the seasonality in the forecast is too large at the start of the time series and too small at the end. In this time series, the seasonality is not a constant additive factor as assumed by Prophet, rather it grows with the trend. This is multiplicative seasonality.
Expand All @@ -49,8 +49,8 @@ m.fit(df)
forecast = m.predict(future)
fig = m.plot(forecast)
```
![png](/prophet/static/multiplicative_seasonality_files/multiplicative_seasonality_7_0.png)

![png](/prophet/static/multiplicative_seasonality_files/multiplicative_seasonality_7_0.png)


The components figure will now show the seasonality as a percent of the trend:
Expand All @@ -64,8 +64,8 @@ prophet_plot_components(m, forecast)
# Python
fig = m.plot_components(forecast)
```
![png](/prophet/static/multiplicative_seasonality_files/multiplicative_seasonality_10_0.png)

![png](/prophet/static/multiplicative_seasonality_files/multiplicative_seasonality_10_0.png)


With `seasonality_mode='multiplicative'`, holiday effects will also be modeled as multiplicative. Any added seasonalities or extra regressors will by default use whatever `seasonality_mode` is set to, but can be overridden by specifying `mode='additive'` or `mode='multiplicative'` as an argument when adding the seasonality or regressor.
Expand All @@ -88,4 +88,3 @@ m.add_seasonality('quarterly', period=91.25, fourier_order=8, mode='additive')
m.add_regressor('regressor', mode='additive')
```
Additive and multiplicative extra regressors will show up in separate panels on the components plot. Note, however, that it is pretty unlikely to have a mix of additive and multiplicative seasonalities, so this will generally only be used if there is a reason to expect that to be the case.

10 changes: 5 additions & 5 deletions docs/_docs/non-daily_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ Prophet can make forecasts for time series with sub-daily observations by passin

```R
# R
df <- read.csv('../examples/example_yosemite_temps.csv')
df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_yosemite_temps.csv')
m <- prophet(df, changepoint.prior.scale=0.01)
future <- make_future_dataframe(m, periods = 300, freq = 60 * 60)
fcst <- predict(m, future)
plot(m, fcst)
```
```python
# Python
df = pd.read_csv('../examples/example_yosemite_temps.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_yosemite_temps.csv')
m = Prophet(changepoint_prior_scale=0.01).fit(df)
future = m.make_future_dataframe(periods=300, freq='H')
fcst = m.predict(future)
Expand Down Expand Up @@ -126,15 +126,15 @@ You can use Prophet to fit monthly data. However, the underlying model is contin

```R
# R
df <- read.csv('../examples/example_retail_sales.csv')
df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_retail_sales.csv')
m <- prophet(df, seasonality.mode = 'multiplicative')
future <- make_future_dataframe(m, periods = 3652)
fcst <- predict(m, future)
plot(m, fcst)
```
```python
# Python
df = pd.read_csv('../examples/example_retail_sales.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_retail_sales.csv')
m = Prophet(seasonality_mode='multiplicative').fit(df)
future = m.make_future_dataframe(periods=3652)
fcst = m.predict(future)
Expand All @@ -155,7 +155,7 @@ prophet_plot_components(m, fcst)
```
```python
# Python
m = Prophet(seasonality_mode='multiplicative', mcmc_samples=300).fit(df)
m = Prophet(seasonality_mode='multiplicative', mcmc_samples=300).fit(df, show_progress=False)
fcst = m.predict(future)
fig = m.plot_components(fcst)
```
Expand Down
23 changes: 11 additions & 12 deletions docs/_docs/outliers.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ There are two main ways that outliers can affect Prophet forecasts. Here we make

```R
# R
df <- read.csv('../examples/example_wp_log_R_outliers1.csv')
df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R_outliers1.csv')
m <- prophet(df)
future <- make_future_dataframe(m, periods = 1096)
forecast <- predict(m, future)
plot(m, forecast)
```
```python
# Python
df = pd.read_csv('../examples/example_wp_log_R_outliers1.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R_outliers1.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=1096)
forecast = m.predict(future)
fig = m.plot(forecast)
```
![png](/prophet/static/outliers_files/outliers_4_0.png)

![png](/prophet/static/outliers_files/outliers_4_0.png)


The trend forecast seems reasonable, but the uncertainty intervals seem way too wide. Prophet is able to handle the outliers in the history, but only by fitting them with trend changes. The uncertainty model then expects future trend changes of similar magnitude.
Expand All @@ -51,32 +51,32 @@ df.loc[(df['ds'] > '2010-01-01') & (df['ds'] < '2011-01-01'), 'y'] = None
model = Prophet().fit(df)
fig = model.plot(model.predict(future))
```
![png](/prophet/static/outliers_files/outliers_7_0.png)

![png](/prophet/static/outliers_files/outliers_7_0.png)


In the above example the outliers messed up the uncertainty estimation but did not impact the main forecast `yhat`. This isn't always the case, as in this example with added outliers:


```R
# R
df <- read.csv('../examples/example_wp_log_R_outliers2.csv')
df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R_outliers2.csv')
m <- prophet(df)
future <- make_future_dataframe(m, periods = 1096)
forecast <- predict(m, future)
plot(m, forecast)
```
```python
# Python
df = pd.read_csv('../examples/example_wp_log_R_outliers2.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R_outliers2.csv')
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=1096)
forecast = m.predict(future)
fig = m.plot(forecast)
```
![png](/prophet/static/outliers_files/outliers_10_0.png)

![png](/prophet/static/outliers_files/outliers_10_0.png)


Here a group of extreme outliers in June 2015 mess up the seasonality estimate, so their effect reverberates into the future forever. Again the right approach is to remove them:
Expand All @@ -97,6 +97,5 @@ df.loc[(df['ds'] > '2015-06-01') & (df['ds'] < '2015-06-30'), 'y'] = None
m = Prophet().fit(df)
fig = m.plot(m.predict(future))
```

![png](/prophet/static/outliers_files/outliers_13_0.png)

![png](/prophet/static/outliers_files/outliers_13_0.png)
4 changes: 2 additions & 2 deletions docs/_docs/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ from prophet import Prophet
```
```python
# Python
df = pd.read_csv('../examples/example_wp_log_peyton_manning.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')
df.head()
```

Expand Down Expand Up @@ -301,7 +301,7 @@ First we read in the data and create the outcome variable. As in the Python API,

```R
# R
df <- read.csv('../examples/example_wp_log_peyton_manning.csv')
df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.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 and are described in later pages of this documentation.

Expand Down
13 changes: 6 additions & 7 deletions docs/_docs/saturating_forecasts.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Prophet allows you to make forecasts using a [logistic growth](https://en.wikipe

```R
# R
df <- read.csv('../examples/example_wp_log_R.csv')
df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R.csv')
```
```python
# Python
df = pd.read_csv('../examples/example_wp_log_R.csv')
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_R.csv')
```
We must specify the carrying capacity in a column `cap`. Here we will assume a particular value, but this would usually be set using data or expertise about the market size.

Expand Down Expand Up @@ -74,8 +74,8 @@ future['cap'] = 8.5
fcst = m.predict(future)
fig = m.plot(fcst)
```
![png](/prophet/static/saturating_forecasts_files/saturating_forecasts_13_0.png)

![png](/prophet/static/saturating_forecasts_files/saturating_forecasts_13_0.png)


The logistic function has an implicit minimum of 0, and will saturate at 0 the same way that it saturates at the capacity. It is possible to also specify a different saturating minimum.
Expand Down Expand Up @@ -114,9 +114,8 @@ m.fit(df)
fcst = m.predict(future)
fig = m.plot(fcst)
```

![png](/prophet/static/saturating_forecasts_files/saturating_forecasts_16_0.png)

![png](/prophet/static/saturating_forecasts_files/saturating_forecasts_16_0.png)

To use a logistic growth trend with a saturating minimum, a maximum capacity must also be specified.

To use a logistic growth trend with a saturating minimum, a maximum capacity must also be specified.
2 changes: 1 addition & 1 deletion docs/_docs/uncertainty_intervals.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ forecast <- predict(m, future)
```python
# Python
m = Prophet(mcmc_samples=300)
forecast = m.fit(df).predict(future)
forecast = m.fit(df, show_progress=False).predict(future)
```
This replaces the typical MAP estimation with MCMC sampling, and can take much longer depending on how many observations there are - expect several minutes instead of several seconds. If you do full sampling, then you will see the uncertainty in seasonal components when you plot them:

Expand Down
12 changes: 7 additions & 5 deletions notebooks/additional_topics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
"source": [
"%load_ext rpy2.ipython\n",
"%matplotlib inline\n",
"\n",
"from prophet import Prophet\n",
"import pandas as pd\n",
"import numpy as np\n",
"from prophet import Prophet\n",
"import logging\n",
"logging.getLogger('prophet').setLevel(logging.ERROR)\n",
"import warnings\n",
"\n",
"logging.getLogger('prophet').setLevel(logging.ERROR)\n",
"warnings.filterwarnings(\"ignore\")"
]
},
Expand Down Expand Up @@ -268,7 +270,7 @@
"metadata": {
"celltoolbar": "Edit Metadata",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -282,9 +284,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
16 changes: 9 additions & 7 deletions notebooks/diagnostics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
"%load_ext rpy2.ipython\n",
"%matplotlib inline\n",
"from prophet import Prophet\n",
"import pandas as pd\n",
"from matplotlib import pyplot as plt\n",
"\n",
"import pandas as pd\n",
"import logging\n",
"logging.getLogger('prophet').setLevel(logging.ERROR)\n",
"import warnings\n",
"\n",
"logging.getLogger('prophet').setLevel(logging.ERROR)\n",
"warnings.filterwarnings(\"ignore\")"
]
},
Expand Down Expand Up @@ -56,7 +58,7 @@
}
],
"source": [
"df = pd.read_csv('../examples/example_wp_log_peyton_manning.csv')\n",
"df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')\n",
"m = Prophet()\n",
"m.fit(df)\n",
"future = m.make_future_dataframe(periods=366)\n",
Expand Down Expand Up @@ -91,7 +93,7 @@
"source": [
"%%R\n",
"library(prophet)\n",
"df <- read.csv('../examples/example_wp_log_peyton_manning.csv')\n",
"df <- read.csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')\n",
"m <- prophet(df)\n",
"future <- make_future_dataframe(m, periods=366)"
]
Expand Down Expand Up @@ -755,7 +757,7 @@
"metadata": {
"celltoolbar": "Edit Metadata",
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -769,9 +771,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
Loading

0 comments on commit f52fddf

Please sign in to comment.