我可以使用SciPy对机器上的文本进行分类,但我需要实时地对HTTP请求中的字符串对象进行分类。如果我的目标是高并发性、接近实时输出和较小的内存占用,我应该研究哪些算法?我想我可以通过Go中的支持向量机( Support,SVM)实现,但这是我用例的最佳算法吗?
发布于 2016-10-27 03:26:52
是的,支持向量机(带有线性核)应该是一个很好的起点。您可以使用科学知识-学习 (我相信它封装了线性化 )来训练您的模型。在学习了模型之后,模型仅仅是要分类到的每个类别的feature:weight列表。类似这样的内容(假设您只有3个类):
class1[feature1] = weight11
class1[feature2] = weight12
...
class1[featurek] = weight1k ------- for class 1
... different <feature, weight> ------ for class 2
... different <feature, weight> ------ for class 3 , etc在预测时,您根本不需要scikit学习,您可以使用服务器后端使用的任何语言来进行线性计算。假设特定的POST请求包含功能(feature3、feature5),您需要做的如下所示:
linear_score[class1] = 0
linear_score[class1] += lookup weight of feature3 in class1
linear_score[class1] += lookup weight of feature5 in class1
linear_score[class2] = 0
linear_score[class2] += lookup weight of feature3 in class2
linear_score[class2] += lookup weight of feature5 in class2
..... same thing for class3
pick class1, or class2 or class3 whichever has the highest linear_score更进一步的:如果您可以有某种方法来定义特征权重(例如,使用tf的标记),那么您的预测可能变成:
linear_score[class1] += class1[feature3] x feature_weight[feature3]
so on and so forth.注对于每个请求,feature_weight[feature k]通常是不同的。由于对于每个请求,活动功能的总数必须比考虑的功能总数(考虑50个标记或特性相对于整个词汇表1 MM标记)要小得多,所以预测应该非常快。我可以想象,一旦您的模型准备就绪,预测的实现就可以基于键值存储(例如雷迪斯)编写。
https://stackoverflow.com/questions/40275368
复制相似问题