daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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"))))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top