使用sklearn将pkl文件(来自python2)加载到python 3中

时间:2019-10-23 11:42:25

标签: python

将python 2生成的pkl文件加载到python3模块中,是否可以加载?

我尝试使用“字节”给定进行编码

  

sklearn.grid_search error.Traceback (most recent call last): File "/home/analysis/run.py", line 227, in run_predictions gs_model = gs_lib.load_model_from_pkl(r'model.pkl') File "/home/analysis/gs_lib.py", line 326, in load_model_from_pkl gs_model = pickle.load(f,encoding='latin1') ModuleNotFoundError: No module named 'sklearn.grid_search'

def loadpkl(filename=None):
    if filename is None:
        filename = 'old.pkl'
        f = open(filename, 'rb')
        model = pickle.load(f,encoding='latin1')
        data = pickle.load(model,encoding='bytes')
        return model 

0 个答案:

没有答案