Model persistence in Scikit-Learn?

荒凉一梦 提交于 2019-12-20 02:28:25

问题


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:

  1. 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
    
  2. 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).

来源:https://stackoverflow.com/questions/38320910/model-persistence-in-scikit-learn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!