"Found NaN in column" for added regressor
Hello! If I understand correctly, if I put in function any value for different dates, for example 400000, this means that prediction values will increase on 400000, yes? I don't see that it work. Function as the same below:
def ss_happy(ds):
date = pd.to_datetime(ds)
if (date.month == 10 and (date.day==13 or date.day==14) and date.year == 2017) or date=='2017-09-08' or date =='2017-09-09' :
return 4000000
else:
return 0
And what it means:
---> 25 hop_prophet.fit(fin_df)
26 hop_future = hop_prophet.make_future_dataframe(periods=500,freq = "d")
27 hop_future['ss_happy'] = hop_future['ds'].apply(ss_happy)
/usr/local/lib/python3.4/dist-packages/fbprophet-0.2-py3.4.egg/fbprophet/forecaster.py in fit(self, df, **kwargs)
774 self.history_dates = pd.to_datetime(df['ds']).sort_values()
775
--> 776 history = self.setup_dataframe(history, initialize_scales=True)
777 self.history = history
778 self.set_auto_seasonalities()
/usr/local/lib/python3.4/dist-packages/fbprophet-0.2-py3.4.egg/fbprophet/forecaster.py in setup_dataframe(self, df, initialize_scales)
252 df[name] = ((df[name] - props['mu']) / props['std'])
253 if df[name].isnull().any():
--> 254 raise ValueError('Found NaN in column ' + name)
255 return df
256
ValueError: Found NaN in column ss_happy
when I do 👍
fin_df['ss_happy'] = fin_df['ds'].apply(ss_happy)
def ss_happy(ds):
date = pd.to_datetime(ds)
if (date.month == 10 and (date.day==13 or date.day==14) and date.year == 2017) or date=='2017-09-08' or date =='2017-09-09' :
return 4000
else:
return 0
new['ss_happy'] = new['ds'].apply(ss_happy)
m = Prophet()
m.add_regressor('ss_happy')
m.fit(new)
hop_future = m.make_future_dataframe(periods=500,freq = "d")
hop_future['ss_happy'] = hop_future['ds'].apply(ss_happy)
hop_forecast = m.predict(hop_future)
m.plot_components(hop_forecast)
hop_predict=hop_forecast[['ds', 'yhat']]
hop_predict['y'] = np.exp(new['y'])
hop_predict['yhat'] = np.exp(hop_predict['yhat'])
I'm trying to add regressor for different ts w\o any empty rows or values and I see the same problem:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-2b01601bdb24> in <module>()
13 m = Prophet()
14 m.add_regressor('ss_happy')
---> 15 m.fit(new)
16 shop_future = m.make_future_dataframe(periods=500,freq = "d")
17 shop_future['ss_happy'] = shop_future['ds'].apply(ss_happy)
/usr/local/lib/python3.4/dist-packages/fbprophet-0.2-py3.4.egg/fbprophet/forecaster.py in fit(self, df, **kwargs)
774 self.history_dates = pd.to_datetime(df['ds']).sort_values()
775
--> 776 history = self.setup_dataframe(history, initialize_scales=True)
777 self.history = history
778 self.set_auto_seasonalities()
/usr/local/lib/python3.4/dist-packages/fbprophet-0.2-py3.4.egg/fbprophet/forecaster.py in setup_dataframe(self, df, initialize_scales)
252 df[name] = ((df[name] - props['mu']) / props['std'])
253 if df[name].isnull().any():
--> 254 raise ValueError('Found NaN in column ' + name)
255 return df
256
ValueError: Found NaN in column ss_happy
I can avoid this error only when I set ',standardize=False' in add_regsressor()
Thanks for pointing this out, there is a bug that is making added regressors fail if the added column contains only zeros. I suspect that if you look at new['ss_happy'].values it has only zeros.
If that isn't the case, then if you could post new['ds'] that'd be helpful.
This is fixed in https://github.com/facebook/prophet/commit/feb7be397bc4d4932d03b08ba241d7a538ae03cb, which raises an exception if the regressor is constant (since we can't fit it anyway).
Fix pushed to PyPI in v0.2.1.