【问题标题】:statsmodel error saving pickle file on windowsstatsmodel 在 Windows 上保存泡菜文件时出错
【发布时间】:2018-06-07 15:25:39
【问题描述】:

我在我的 Mac 上开发了下面的代码,它运行良好。我在带有 anaconda 和下面的 python 版本的 jupyter notebook 中运行代码。一切运行良好,并在我的 Mac 上正确保存了 pickle 文件。当我尝试与我的朋友共享相同的代码并且他使用下面的版本信息在他的 Windows 机器上运行它时。他得到下面的错误。代码中的所有内容都运行良好,除了他保存泡菜文件的步骤。他还在 jupyter notebook 中运行它。所有 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

【问题讨论】:

    标签: windows python-3.x macos pickle statsmodels


    【解决方案1】:
    def __getnewargs__(self):
        return ((self.endog),(self.k_lags, self.k_diff, self.k_ma))
    ARIMA.__getnewargs__ = __getnewargs__
    

    【讨论】:

    • 包含对您的代码的作用以及它回答问题的原因的解释可能会更有帮助。仅发布代码有时可能不清楚。
    【解决方案2】:

    使用 statsmodels 0.9.0 版解决此问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-01
      • 2020-08-23
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多