Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. import base64
  2. import pickle
  3. from io import BytesIO
  4.  
  5. from sklearn.svm import LinearSVC
  6. from sklearn.calibration import CalibratedClassifierCV
  7.  
  8.  
  9. # create classifier
  10. clf = CalibratedClassifierCV(LinearSVC())
  11.  
  12. # create byte-string with pickled model
  13. model_pickle_bytes = BytesIO()
  14. pickle.dump(clf, model_pickle_bytes)
  15.  
  16. # create cube params odict
  17. cube_params = {
  18. "model_pickled": base64.encodebytes(model_pickle_bytes.getvalue()).decode("ascii")
  19. }
  20.  
  21. # save to JSON
  22. json_dict = json.dumps(cube_params)
  23.  
  24. ####
  25.  
  26. # load from JSON
  27. clf_loaded = pickle.load(BytesIO(base64.decodebytes(cube_params["model_pickled"].encode("ascii"))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement