首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过我的分类器获得前5个主题的精确度?

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

Stack Overflow用户
提问于 2016-03-20 13:38:41
回答 1查看 812关注 0票数 0

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

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

代码语言:javascript
复制
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:]]

为了准确起见

代码语言:javascript
复制
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指标拒绝使用

代码语言:javascript
复制
q=model1.predict(mat_tmp_test)
print(metrics.precision_score(n, q))
EN

回答 1

Stack Overflow用户

发布于 2016-03-20 20:31:28

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

代码语言:javascript
复制
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))

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36110603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档