I created a model and I saved it in a pickle file using the Algorithm SVR(Support Vector Regression)

import pickle
pickle.dump(model,open('carb patients data/Pickles/svr.pickle', 'wb'))

In jupyter notebook it gives an error

can't pickle _thread.RLock objects

So I converted that jupyter file in to a .py file and downloaded it and executed using the Python Idle. Then it got saved in that particular location. But when I try to load my pickle file from another Jupyter Notebook it gives an error called,

No module named 'sklearn.svm._classes'

The code how i tried to load the pickle file,

from flask import Flask, request, redirect, url_for, flash, jsonify
import numpy as np
import pickle as p
import json
from sklearn import ensemble
app = Flask(__name__)

@app.route('/api/', methods=['POST'])
def makecalc():
  data = request.get_json()
  prediction = np.array2string(model.predict(data))

  return jsonify(prediction)

if __name__ == '__main__':
   modelfile = 'Clustering Patients/carb patients data/Pickles/svr.pickle'
   model = p.load(open(modelfile, 'rb'))
   app.run(debug=True, host='')

Any thing I have done wrong or is it an issue in the Jupyter Notebook? How can I load my saved pickle file?


1 Answer 1


According to the scikit-learn model persistence docs, it may be better to use joblib instead:

Save model

from joblib import dump

dump(model, 'filename.joblib')

Load model

from joblib import load

model = load('filename.joblib') 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.