如何从python3释放python 2中的sklearn.tree.DescisionTreeRegressor
在Python 3中保存Pickle文件
从joblib导入转储,加载
dump(rfc,'rfc.joblib',protocol = 2)
在python 2.7.14中加载Pickle文件
从joblib导入转储,加载
rfc = load('rfc.joblib')
from lib2to3.fixes.fix_imports import MAPPING
REVERSE_MAPPING={}
for key,val in MAPPING.items():
REVERSE_MAPPING[val]=key
class Python_3_Unpickler(pickle.Unpickler):
"""Class for pickling objects from Python 3"""
def find_class(self,module,name):
if module in REVERSE_MAPPING:
module=REVERSE_MAPPING[module]
import(module)
mod = sys.modules[module]
klass = getattr(mod, name)
return klass
def loads(str):
file = pickle.StringIO(str)
return Python_3_Unpickler(file).load()
with open('JULY_18_rfc_python_2.pkl', 'rb') as file_:
rfc = Python_3_Unpickler(file_).load()