首页 文章

如何通过分类器获得前5个主题的精确度?

提问于
浏览
0

我有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))

1 回答

  • 0

    在你的方法精度几乎相同 - 你只关注一个特定的标签(因为精度是每标签指标),让我们说你计算标签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))
    

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

相关问题