将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