我在我的mac上开发了下面的代码并且运行正常。我在一个带有anaconda和下面的python版本的jupyter笔记本中运行代码。一切运行正常,并在我的mac上正确保存pickle文件。当我尝试与我的朋友分享相同的代码时,他在他的Windows机器上使用下面的版本信息运行它。他得到以下错误。除了保存pickle文件的步骤之外,代码中的所有内容都运行正常。他也在一个jupyter笔记本中运行它。所有的ARIMA代码运行正常,它只是将模型保存到抛出错误的pickle文件中。有谁知道问题可能是什么,你能建议一个解决方案吗?任何提示都非常感激。
Mac info:
statsmodel: 0.9.0
python: 3.6.5
macOS Sierra version 10.12.6
Windows info Version:
statswisemodel: 0.9.0
python : 3.6.3
Win10 machine
RAM: 16GB
Code:
import numpy as np
import pandas as pd
from time import time
import scipy.stats as stats
from IPython.display import display # Allows the use of display() for DataFrames
# Pretty display for notebooks
%matplotlib inline
import glob
import matplotlib.pyplot as plt
Code:
stepwise_model
Output:
ARIMA(callback=None, disp=0, maxiter=50, method=None, order=(1, 1, 3),
out_of_sample_size=0, scoring='mse', scoring_args={},
seasonal_order=(2, 1, 2, 12), solver='lbfgs', start_params=None,
suppress_warnings=True, transparams=True, trend='c')
# saving stepwise_model to pickle file
import pickle
your_data = stepwise_model
# stepwise_model data (serialize)
with open('stepwise_model.pickle', 'wb') as handle:
pickle.dump(your_data, handle, protocol=pickle.HIGHEST_PROTOCOL)
TypeError Traceback (most recent call last)
<ipython-input-21-cee2e10d7185> in <module>()
6 # stepwise_model data (serialize)
7 with open('stepwise_model.pickle', 'wb') as handle:
----> 8 pickle.dump(your_data, handle, protocol=pickle.HIGHEST_PROTOCOL)
~\Anaconda3\lib\site-packages\pyramid\arima\arima.py in __getstate__(self)
476 # https://github.com/statsmodels/statsmodels/issues/3290
477 self.arima_res_.summary()
--> 478 self.arima_res_.save(fname=new_loc) # , remove_data=False)
479
480 # point to the location of the saved MLE model
~\Anaconda3\lib\site-packages\statsmodels\base\wrapper.py in save(self, fname, remove_data)
70 self.remove_data()
71
---> 72 save_pickle(self, fname)
73
74 @classmethod
~\Anaconda3\lib\site-packages\statsmodels\iolib\smpickle.py in save_pickle(obj, fname)
13 """
14 with get_file_obj(fname, 'wb') as fout:
---> 15 cPickle.dump(obj, fout, protocol=-1)
16
17
TypeError: can't pickle statsmodels.tsa.statespace._statespace.dStatespace objects
答案 0 :(得分:0)
def __getnewargs__(self):
return ((self.endog),(self.k_lags, self.k_diff, self.k_ma))
ARIMA.__getnewargs__ = __getnewargs__
答案 1 :(得分:0)
使用statsmodels 0.9.0版解决此问题