统计模型在Windows上保存泡菜文件时出错



我在Mac上开发了下面的代码,它运行良好。 我在 jupyter 笔记本中运行代码,其中包含 anaconda 和下面的 python 版本。 一切运行良好,并将泡菜文件正确保存在我的Mac上。 当我尝试与我的朋友共享相同的代码时,他使用下面的版本信息在他的 Windows 机器上运行它。 他得到下面的错误。 代码中的所有内容都运行良好,除了他保存 pickle 文件的步骤。 他还在Jupyter笔记本中运行它。 所有 ARIMA 代码运行良好,它只是将模型保存到引发错误的泡菜文件中。 有谁知道问题可能是什么,你能提出解决方案吗? 任何提示都非常感谢。

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)
~Anaconda3libsite-packagespyramidarimaarima.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
~Anaconda3libsite-packagesstatsmodelsbasewrapper.py in save(self, fname, remove_data)
70             self.remove_data()
71 
---> 72         save_pickle(self, fname)
73 
74     @classmethod
~Anaconda3libsite-packagesstatsmodelsiolibsmpickle.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
def __getnewargs__(self):
return ((self.endog),(self.k_lags, self.k_diff, self.k_ma))
ARIMA.__getnewargs__ = __getnewargs__

使用 statsmodels 版本 0.9.0 来解决此问题

最新更新