Is the predict_proba method of scikit learn's SGDClassifier thread safe?

☆樱花仙子☆ 提交于 2021-01-28 19:40:51

问题


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

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