由于缺少fit_class

时间:2017-07-12 10:56:34

标签: facebook stan

我正在尝试使用Facebook提供的名为Facebook Prophet(https://research.fb.com/prophet-forecasting-at-scale/)的创新预测工具。但是在尝试使用" fit" 时,我收到以下错误消息 特征。目前,我在Anaconda环境中使用Python,使用Pystan的2.14版本,Pandas的0.20.2版本和Python的3.5版本。我不明白为什么会遇到这个问题,所以有人可以帮忙吗?

我的代码:

import pandas as pd
import numpy as np
from fbprophet import Prophet
import matplotlib.pyplot as plt
import pystan
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
plt.rcParams['axes.labelsize'] = 14
plt.rcParams['xtick.labelsize'] = 12
plt.rcParams['ytick.labelsize'] = 12
jet=plt.get_cmap('coolwarm')


datapath = "/Users/tuanle/DynamicPricing/Data/"
HAN_BIKE = pd.read_csv(datapath+ "HAN-BIKE_1year_CompletedOrders.csv")
HAN_BIKE['to_char'] = pd.DatetimeIndex(HAN_BIKE['to_char'])
HAN_BIKE = HAN_BIKE.rename(columns={'to_char': 'ds', 'hourr': 'hour','completed_orders': 'y'})
HAN_BIKE['ds'] = HAN_BIKE[['ds','hour']].apply(lambda x : '{}{}'.format(x[0],x[1]), axis=1)
pd.pivot_table(HAN_BIKE, index = ["hour"], values = ["percent_completed", "y"])
HAN_BIKE = HAN_BIKE.drop("hour", axis=1)

HAN_BIKE.hist(bins=50, figsize=(10,15))
HAN_BIKE = HAN_BIKE.drop("percent_completed", axis=1)
# HAN_BIKE.set_index('ds').plot()
HAN_BIKE.loc[(HAN_BIKE['y'] > 500), 'y'] = np.nan
HAN_BIKE.loc[(HAN_BIKE['y'] <= 10), 'y'] = np.nan
HAN_BIKE['y'] = np.log(HAN_BIKE['y'])
# HAN_BIKE.set_index('ds').plot()
HAN_BIKE.hist(bins = 50, figsize = (10,15))
m = Prophet(yearly_seasonality=True)
m.fit(HAN_BIKE)

错误讯息:

WARNING:pystan:numpy.core.multiarray failed to import
WARNING:pystan:Something went wrong while unpickling the StanModel. Consider recompiling.

RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa

WARNING:pystan:numpy.core.multiarray failed to import
WARNING:pystan:Something went wrong while unpickling the StanModel. Consider recompiling.
Disabling yearly seasonality. Run prophet with yearly_seasonality=True to override this.

AttributeError Traceback (most recent call last)
in ()
11 HAN_BIKE["ds"] = HAN_BIKE["ds"].values.astype('datetime64[D]')
12 m = Prophet()
---> 13 m.fit(HAN_BIKE)

/Applications/anaconda/lib/python3.5/site-packages/fbprophet/forecaster.py in fit(self, df, **kwargs)
533
534 else:
--> 535 params = model.optimizing(dat, init=stan_init, iter=1e4, **kwargs)
536 for par in params:
537 self.params[par] = params[par].reshape((1, -1))

/Applications/anaconda/lib/python3.5/site-packages/pystan/model.py in optimizing(self, data, seed, init, sample_file, algorithm, verbose, as_vector, **kwargs)
466 data = {}
467
--> 468 fit = self.fit_class(data)
469
470 m_pars = fit._get_param_names()

AttributeError: 'StanModel' object has no attribute 'fit_class''

2 个答案:

答案 0 :(得分:0)

您似乎正在使用旧版本的pystan。在你的virtualenv尝试:

pip3 install --upgrade pystan

答案 1 :(得分:0)

2021 年:

安装 prophet 而不是 fbprophet

pip install pystan==2.19.1.1
pip install prophet