I am trying to save and load scikit-learn model but facing issues when the save and load are happening on different python versions. Here what I have tried:
Using pickle to save a model in python3 and deserialize in python2.This works for some of the models like LR,SVM but it fails for KNN.
>>> pickle.load(open("inPy3.pkl", 'rb')) #KNN model ValueError: non-string names in Numpy dtype unpickling
Also , I tried to serialize and deserialize in json using jsonpickle but getting the following error.
data = jsonpickle.encode(lr) #lr = logisticRegression Model jsonpickle.decode(data) AttributeError: 'dict' object has no attribute '__name__'
Also, I want to know if there is some utility which I can use to serialize and deserialize scikit-learn model objects to human readable format (json,xml,protobuf etc).
protocol=2
keyword argument in thepickle.dump
method, which is the highest protocol understood by pickle in Python 2. – Armin