【问题标题】:How can I get the precision of top 5 topics through my classifier?如何通过我的分类器获得前 5 个主题的精度?
【发布时间】:2016-07-06 18:08:03
【问题描述】:

我有 22465 个测试文档,我将它们分类为 88 个不同的主题。 我正在使用 predict_proba 来获得前 5 个预测主题。那么如何打印这 5 个主题的精度呢?

为了准确,这就是我正在做的:

model1 = LogisticRegression()
model1 = model1.fit(matrix, labels)

y_train_pred = model1.predict_log_proba(matrix_test)
order=np.argsort(y_train_pred, axis=1)
print(order[:,-5:]) #gives top 5 probabilities

n=model1.classes_[order[:, -5:]]

为了准确

z=0
for x, y in zip(label_tmp_test, n):
    if x in y:
        z=z+1
print(z)
print(z/22465) #This gives me the accuracy by considering top 5 topics

如何以相同的方式找到前 5 个主题的精确度? Scikit 指标拒绝使用

q=model1.predict(mat_tmp_test)
print(metrics.precision_score(n, q))

【问题讨论】:

    标签: python machine-learning scikit-learn data-science


    【解决方案1】:

    您的方法精度几乎相同 - 您只需关注特定标签(因为精度是每个标签的指标),假设您计算标签 L 的精度:

    TP = 0.
    FP = 0.
    for x, y in zip(label_tmp_test, n):
    
        if x == L: # this is the label we are interested in
            if L in y: # correct prediction is among selected ones
                TP = TP + 1 # we get one more true positive instance
    
        else: # this is some other label
            if L in y: # if we predicted that this is a particular label
                FP = FP + 1 # we have created another false positive
    
    print(TP / (TP + FP))
    

    现在,如果您需要“一般”精度 - 您通常会平均每个标签的精度。出于显而易见的原因,您需要大量标签才能使这些措施有意义。

    【讨论】:

      猜你喜欢
      • 2019-12-15
      • 2020-02-20
      • 2017-06-10
      • 2015-11-02
      • 1970-01-01
      • 1970-01-01
      • 2020-04-15
      • 2012-01-13
      • 2018-05-13
      相关资源
      最近更新 更多