svc预测概率_改进单个样本的SVC预测性能

我有用于文本分类的大型SVC模型(?50Mb cPickles),并且我正在尝试各种在生产环境中使用它们的方法.对一批文档进行分类非常有效(使用predict和predict_proba大约每分钟1k个文档).

但是,对单个文档的预测是另一回事,如对this question的注释所述:

Are you doing predictions in batches? The SVC.predict method, unfortunately, incurs a lot of overhead because it has to reconstruct a LibSVM data structure similar to the one that the training algorithm produced, shallow-copy in the support vectors, and convert the test samples to a LibSVM format that may be different from the NumPy/SciPy formats. Therefore, prediction on a single sample is bound to be slow. – 07001

我已经将SVC模型用作Flask Web应用程序了,所以一部分开销已经消失了(取消分配),但是单个文档的预测时间仍然偏高(0.25s).

我已经看过预测方法中的代码,但是无法弄清楚是否有一种方法可以“预热”它们,从而在服务器启动时提前重建LibSVM数据结构……有什么想法吗?

def predict(self, X):

"""Perform classification on samples in X.

For an one-class model, +1 or -1 is returned.

Parameters

----------

X : {array-like, sparse matrix}, shape = [n_samples, n_features]

Returns

-------

y_pred : array, shape = [n_samples]

Class labels for samples in X.

"""

y = super(BaseSVC, self).predict(X)

return self.classes_.take(y.astype(np.int))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值