facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.53k stars 4.54k forks source link

BUG - Cannot predict on using logistic -> All-NaN slice encountered #2575

Open frbelotto opened 7 months ago

frbelotto commented 7 months ago

Hello guys, I am trying to create some predictions over a historical sales data. Lets take this sample as dataframe:

import numpy as np
import pandas as pd
from datetime import date
from prophet import Prophet
from prophet.plot import plot_plotly, plot_components_plotly

dates = pd.date_range(date(2023,1,1),date(2023,12,31))
rng = np.random.default_rng()

df = pd.DataFrame({
    'ds' : dates,
    'y' : rng.random(len(dates)) * 100})

Now lets fit and predict

m = Prophet(growth='linear',daily_seasonality=True, weekly_seasonality=True, yearly_seasonality=True)
m.add_country_holidays(country_name='BR')
df['floor'] = 0
df['cap'] = 100
m.fit(df)
future = m.make_future_dataframe(periods=365,include_history=True,freq='D')
future['floor'] = df['floor']
future['cap'] = df['cap']
forecast = m.predict(future,vectorized=True)

And we got results! Capturar

Now, lets make the code just changing to logistic

m = Prophet(growth='logistic',daily_seasonality=True, weekly_seasonality=True, yearly_seasonality=True)
m.add_country_holidays(country_name='BR')
df['floor'] = 0
df['cap'] = 100
m.fit(df)
future = m.make_future_dataframe(periods=365,include_history=True,freq='D')
future['floor'] = df['floor']
future['cap'] = df['cap']
forecast = m.predict(future,vectorized=True)

(I start to get this error!)

/projeto/libs/lib/python3.11/site-packages/numpy/lib/nanfunctions.py:1563: RuntimeWarning:
All-NaN slice encountered

And now there is no predict on results, only actual data. Capturar2

blacehoule commented 5 months ago

I'm not sure that this is a bug. It looks like these might be historical conversion rates expressed in percentages, or something like that. If some of the percentages are 0% or 100%, which it looks like they are, you would get undefined behavior in the Logit transform. Maybe the program should fail more gracefully here?