scikit learn 的 SGDClassifier 线程的 predict_proba 方法是否安全? [英] Is the predict_proba method of scikit learn's SGDClassifier thread safe?

查看:55
本文介绍了scikit learn 的 SGDClassifier 线程的 predict_proba 方法是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 Web API 公开使用 sklearn.linear_model.SGDClassifier 构建的模型.每个 Web 请求都会调用模型的 predict_proba 方法,但是由于性能和一致性原因,我将在该过程中只有一个模型实例;它将在 Web 应用程序启动时创建,并在训练完成后开始服务请求.这就提出了一个问题——模型的 predict_proba 方法实际上是线程安全的吗?

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.

推荐答案

一句话:是的.

sklearn.linear_model.SGDClassifier 的 predict_proba 方法仅使用输入和权重之间的简单点积,因此它只从类中读取权重.所以你不能因为线程在任何状态相关的问题中运行.

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.

但是,由于 scikit-learn 是用 Python 编写的,您可能会遇到 GIL.

However, as scikit-learn is written in python, you might have some trouble with the GIL.

这篇关于scikit learn 的 SGDClassifier 线程的 predict_proba 方法是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆