问题
I would like to expose a model built using sklearn.linear_model.SGDClassifier through a web API. Every web request would call into the predict_proba method of the model, however I will have just one instance of the model in the process, due to performance and consistency reasons; it would get created when the web application starts and start serving requests once the training completes. This raises the question - is the predict_proba method of the model actually thread safe?
Any help will be much appreciated. Thank you.
回答1:
In one word: yes.
sklearn.linear_model.SGDClassifier's predict_proba method uses just a simple dot product between input and weights and therefore it only reads the weights from the class. So you can't run in any state related problems due to threads.
However, as scikit-learn is written in python, you might have some trouble with the GIL.
来源:https://stackoverflow.com/questions/35290942/is-the-predict-proba-method-of-scikit-learns-sgdclassifier-thread-safe