首页 > 解决方案 > Fbprophet 错误“系列”对象没有属性“非零”

问题描述

我正在尝试使用 FBProphet 实现时间序列预测。

数据是one yearofdaily frequency并且有 2 列:DateDaily Total Time

我的代码是:

Date            Total Time
317 3/19/2020   495.256579
318 3/20/2020   312.727632
319 3/21/2020   278.980263
320 3/22/2020   0.000000
321 3/23/2020   153.446053

df.dropna(axis=1, how='all', inplace=True)
df.dropna(axis=0, how='all', inplace=True)
df['Date'] = pd.to_datetime(df['Date'])

def positive_average(num):
  return num[num > 0].mean()

daily_data = df.groupby('Date').apply(positive_average)
daily_data.head()

daily_data = daily_data.dropna()


weekly_data = daily_data.iloc[:, (daily_data.isna().sum() <=8).values]
weekly_data = weekly_data.dropna()

from fbprophet import Prophet
import logging

logging.getLogger().setLevel(logging.ERROR)

df = weekly_data.reset_index()
df.columns = ['ds', 'y']
df.head()

       ds            y
0   2019-03-01  124.813158
1   2019-03-04  154.826316
2   2019-03-05  628.684211
3   2019-03-06  690.492105
4   2019-03-07  719.939474

prediction_size = 30
train_df = df[:-prediction_size]

model = Prophet()
model.fit(train_df)

model.fit()方法引发以下错误:

`AttributeError                            Traceback (most recent call last)
<ipython-input-20-014bed53c8b5> in <module>()
  1 model = Prophet()
----> 2 model.fit(train_df)

/anaconda3/lib/python3.6/site-packages/fbprophet/forecaster.py in fit(self, df, **kwargs)
776         history = self.setup_dataframe(history, initialize_scales=True)
777         self.history = history
--> 778         self.set_auto_seasonalities()
779         seasonal_features, prior_scales = (
780             self.make_all_seasonality_features(history))

/anaconda3/lib/python3.6/site-packages/fbprophet/forecaster.py in set_auto_seasonalities(self)
637         last = self.history['ds'].max()
638         dt = self.history['ds'].diff()
--> 639         min_dt = dt.iloc[dt.nonzero()[0]].min()
640 
641         # Yearly seasonality

/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in __getattr__(self, name)
5272             if self._info_axis._can_hold_identifiers_and_holds_name(name):
5273                 return self[name]
-> 5274             return object.__getattribute__(self, name)
5275 
5276     def __setattr__(self, name: str, value) -> None:

AttributeError: 'Series' object has no attribute 'nonzero'`

我出错的任何原因或代码有任何问题?

任何帮助表示赞赏。谢谢你。

笔记: Python Version: 3.6.5

Pandas Version: 1.0.3

Numpy Version: 1.18.2

Fbprophet Version: 0.2

标签: pythonpandastime-seriesfacebook-prophet

解决方案


我不得不更新我的 Fbprophet 版本。为 0.2。我将它更新到 0.6 并解决了这个问题。


推荐阅读