facebook / facebook/prophet

Prophet reordering forecasts when predicting for a data frame that is not ordered by date (Bug)

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

Description

When running `pred = prophet.predict(future_df)`, the rows of `pred` are not guaranteed to correspond to the rows of `future_df`.

Here is a MWE:

```
import pandas as pd
from prophet import Prophet
import numpy as np

df = pd.DataFrame(
dict(
ds=pd.date_range(start="2022-01-01", periods=100),
t=list(range(100)), # time trend variable
x=np.random.uniform(100), # covariate
)
)
df["y"] = df.t + 10 * df.x + np.random.normal(100) # DGP is function of x and the time trend, plus light noise

m = Prophet()
m.add_regressor("x")
m.fit(df)

pred_df = pd.concat(
[
pd.DataFrame(
dict(
ds=pd.date_range(start="2022-04-11", periods=7),
x=100, # covariate = 1
)
),
pd.DataFrame(
dict(
ds=pd.date_range(start="2022-04-11", periods=7),
x=-100, # covariate = -1
)
),
]
)
```
the input `pred_df` has the following date ordering:
```
pred_df.ds.head()
Out[19]:
0 2022-04-11
1 2022-04-12
2 2022-04-13
3 2022-04-14
4 2022-04-15
```

however the output of the predict method has the following date ordering:
```
m.predict(pred_df).ds.head()
Out[20]:
0 2022-04-11
1 2022-04-11
2 2022-04-12
3 2022-04-12
4 2022-04-13
```
I think that this is a bug. However, if it's not considered a bug then at minimum it's deeply confusing. Perhaps it could throw a warning and ideally return the index of the input in the output of the `predict` method, so that it could be sorted.

I'm using prophet 1.1.1

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.