【问题标题】:Cheapest way to classify HTTP post objects分类 HTTP post 对象的最便宜方法
【发布时间】:2017-03-09 14:13:05
【问题描述】:

我可以使用 SciPy 对我机器上的文本进行分类,但我需要实时或近乎实时地对来自 HTTP POST 请求的字符串对象进行分类。如果我的目标是高并发、接近实时的输出和小内存占用,我应该研究什么算法?我想我可以通过 Go 中的支持向量机 (SVM) 实现来解决问题,但这是否是我用例的最佳算法?

【问题讨论】:

    标签: algorithm go machine-learning svm text-classification


    【解决方案1】:

    是的,SVM(带有线性内核)应该是一个很好的起点。您可以使用scikit-learn(我相信它包含liblinear)来训练您的模型。学习模型后,模型只是您要分类的每个类别的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-learn,您可以使用您在服务器后端使用的任何语言进行线性计算。假设一个特定的 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-idf 分数),那么您的预测可能变为:

    linear_score[class1] += class1[feature3] x feature_weight[feature3]
    so on and so forth.
    

    注意feature_weight[feature k] 对于每个请求通常是不同的。 由于对于每个请求,活动特征的总数必须远小于考虑的特征的总数(考虑 50 个标记或特征与 1 MM 标记的整个词汇表),因此预测应该非常快。我可以想象,一旦你的模型准备好,预测的实现就可以基于键值存储(例如,redis)编写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-21
      • 2023-04-11
      • 1970-01-01
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      相关资源
      最近更新 更多