加载对象时出现Pickle EOF错误

时间:2017-05-31 18:25:40

标签: python scikit-learn pickle

我按如下方式保存了一个模型对象:

with open('bestModel_smv_3class_version2data.pickle','wb') as f:
    pickle.dump(jpsa_svm_3class.g_cv.best_estimator_,f)

现在当我尝试加载它时,它会出错

with open('bestModel_smv_3class_version2data.pickle','rb') as f:
    svm_bestModel=pickle.load(f)

错误:

EOFError                                  Traceback (most recent call last)
<ipython-input-66-df8734c64828> in <module>()
      8 
      9 with open('bestModel_smv_3class_version2data.pickle','rb') as f:
---> 10     svm_bestModel=pickle.load(f)

EOFError: Ran out of input

1 个答案:

答案 0 :(得分:0)

pickle无法处理sklearn个模型,因为它们包含numpy个数组。使用joblib.dump代替它,但它们是特殊的,可以保存/加载大型numpy数组。

https://pythonhosted.org/joblib/persistence.html