使用咸菜保存Facebook Prophet模型时出现“ TypeError:无法咸菜_thread.RLock对象”

时间:2020-03-02 05:51:34

标签: python machine-learning pickle facebook-prophet

我正在训练一个模型,以使用Facebook Prophet模型预测能耗值。 但是在使用pickle保存模型时出现此错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-54-9ef2990419d8> in <module>
      1 with open('forecast_model.pckl', 'wb') as fout:
----> 2     pickle.dump(model, fout)

TypeError: can't pickle _thread.RLock objects

代码:

from fbprophet import Prophet
import pickle
model = Prophet()
model.fit(df)
with open('forecast_model.pkl', 'wb') as fout:   <== Error coming here
    pickle.dump(model, fout)

df.head()

                     ds   y
0   2018-12-19 15:00:02   250.0
1   2018-12-19 16:00:03   295.0
2   2018-12-19 18:00:02   288.0
3   2018-12-19 19:00:02   286.0
4   2018-12-19 20:00:02   229.0

[EDIT] 解决方案链接:https://github.com/facebook/prophet/issues/1361
下面给出的代码对我有用

model = Prophet()
model.stan_backend.logger = None

with open('test.pickle', 'wb') as f:
   pickle.dump(m, f)

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。 我重新安装了fbprophet 0.5版,例如

pip install -U fbprophet==0.5

如果您不需要最新版本:0.6,可以尝试一下。