|
@@ -4,7 +4,47 @@ docid: "non-daily_data"
|
|
|
title: "Non-Daily Data"
|
|
|
permalink: /docs/non-daily_data.html
|
|
|
---
|
|
|
-Prophet doesn't strictly require daily data, but you can get strange results if you ask for daily forecasts from non-daily data and fit seasonalities. Here we forecast US retail sales volume for the next 10 years:
|
|
|
+## Sub-daily data
|
|
|
+
|
|
|
+Prophet can make forecasts for time series with sub-daily observations by passing in a dataframe with timestamps in the `ds` column. When sub-daily data are used, daily seasonality will automatically be fit. Here we fit Prophet to data with 5-minute resolution (daily temperatures at Yosemite):
|
|
|
+
|
|
|
+```R
|
|
|
+# R
|
|
|
+df <- read.csv('../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')
|
|
|
+m = Prophet(changepoint_prior_scale=0.01).fit(df)
|
|
|
+future = m.make_future_dataframe(periods=300, freq='H')
|
|
|
+fcst = m.predict(future)
|
|
|
+m.plot(fcst);
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+The daily seasonality will show up in the components plot:
|
|
|
+
|
|
|
+```R
|
|
|
+# R
|
|
|
+prophet_plot_components(m, fcst)
|
|
|
+```
|
|
|
+```python
|
|
|
+# Python
|
|
|
+m.plot_components(fcst);
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+## Monthly data
|
|
|
+
|
|
|
+You can use Prophet to fit monthly data. However, the underlying model is continuous-time, which means that you can get strange results if you fit the model to monthly data and then ask for daily forecasts. Here we forecast US retail sales volume for the next 10 years:
|
|
|
|
|
|
```R
|
|
|
# R
|
|
@@ -23,14 +63,14 @@ fcst = m.predict(future)
|
|
|
m.plot(fcst);
|
|
|
```
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
The forecast here seems very noisy. What's happening is that this particular data set only provides monthly data. When we fit the yearly seasonality, it only has data for the first of each month and the seasonality components for the remaining days are unidentifiable and overfit. When you are fitting Prophet to monthly data, only make monthly forecasts, which can be done by passing the frequency into make_future_dataframe:
|
|
|
|
|
|
```R
|
|
|
# R
|
|
|
-future <- make_future_dataframe(m, periods = 120, freq = 'm')
|
|
|
+future <- make_future_dataframe(m, periods = 120, freq = 'month')
|
|
|
fcst <- predict(m, future)
|
|
|
plot(m, fcst)
|
|
|
```
|
|
@@ -41,5 +81,5 @@ fcst = m.predict(future)
|
|
|
m.plot(fcst);
|
|
|
```
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|