facebook / facebook/prophet

Sawtooth pattern forecast

Open
#1,960 0 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
20.4k
Forks
4.6k
Avg merge
19h 52m
Merged PRs (30d)
1

Description

I am using Facebook Prophet to forecast data that follow a set of particular patterns and one of them is a sawtooth pattern. I'm getting some peculiar results when using Prophet with default parameters. It doesn't seem to track the original data at all and generates a sinusoidal time series around the overall mean of the training data. You can find a simple reproducible Python script in the following section. I was wondering if someone would be able to shed some light as to why Prophet behaves that way and what I can do to help it track the training data better and produce better forecasts.

## To Reproduce
```python
import matplotlib.pyplot as plt
from scipy import signal
from fbprophet import Prophet
import pandas as pd
import numpy as np

def main(num_points: int, interval_seconds: int):
t = np.linspace(0, num_points * interval_seconds, num_points, False, dtype=int)
x = pd.to_datetime(t, unit='s')
y = signal.sawtooth(0.000005 * np.pi * t, 0.6)
plt.plot(x, y)
plt.show()
df = pd.DataFrame({'ds': pd.to_datetime(x, unit='s'), 'y': y})
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(periods=7 * 24, freq='H')
forecast = m.predict(future)
m.plot(forecast).show()
m.plot_components(forecast).show()

if __name__ == '__main__':
main(2880, 15 * 60)
```
## Training Data
![prophet_sawtooth_training](https://user-images.githubusercontent.com/29710502/124942680-c041e600-e003-11eb-8170-7f33ff26f2d7.png)

## Forecast Result
![prophet_sawtooth_result](https://user-images.githubusercontent.com/29710502/124941033-62f96500-e002-11eb-8e46-3086b0c6188b.png)

## Components
![prophet_sawtooth_components](https://user-images.githubusercontent.com/29710502/124941005-5d038400-e002-11eb-8a44-5aa6dbfebb6f.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.