import pickle as p output_model_file = 'saved_model.pkl' with open(output_model_file,'w') as f: p.dump(linear_regressor,f)
TypeError: write() argument must be str, not bytesp
In Python 3 it makes a difference whether you open the file in binary or text mode. Just add the bflag to make it binary:
with open('random.bin','wb') as f:This works in Python 2 too.
本文介绍如何在Python中正确地将模型保存为文件。重点讲解了在不同Python版本中,使用pickle模块保存模型时应选择正确的文件打开模式。通过示例说明了在Python 3中保存模型时需要使用二进制模式。

544

被折叠的 条评论
为什么被折叠?



