简体   繁体   English

从混淆矩阵中获取假阴性、假阳性、真阳性和真阴性的相关数据集

[英]Getting relevant datasets of false negatives, false positives, true positive and true negative from confusion matrix

I ran a random classifier on my text data and calculated a confusion matrix using the following code我对我的文本数据运行了一个随机分类器,并使用以下代码计算了一个混淆矩阵

#Plot the confusion matrix
plot_confusion_matrix(y_test, y_pred, normalize=False,figsize=(15,8))

在此处输入图像描述

The above fig is what my confusion matrix looks like.上图是我的混淆矩阵的样子。 Now, I want to see some datasets that belong to false negatives, false positives, true positives and true negative?.现在,我想查看一些属于假阴性、假阳性、真阳性和真阴性的数据集?。 So far written following codes:到目前为止编写了以下代码:

import pandas as pd
df_test = pd.DataFrame(x_test)
df_test['case'] = np.where((y_test == 1) & (y_pred == 0), 'false negative', np.where((y_test == 0) & (y_pred == 1), 'false positive', 'correct prediction'))
df_test.head(5)

This code gives me false negative, false positive and correct predictions but does not give me true positive and true negative.这段代码给出了假阴性、假阳性和正确的预测,但没有给出真阳性和真阴性。 Any idea how to modify this code so that df_test shows all these label results datasets: false negative, false positive, true positive, true negative and correct predictions?知道如何修改此代码以便df_test显示所有这些 label 结果数据集:假阴性、假阳性、真阳性、真阴性和正确预测吗? Thanks in advance提前致谢

You can create a label array, then use numpy indexing index:您可以创建一个标签数组,然后使用 numpy 索引索引:

labels = np.array(['true negative',   # y_test, y_pred = 0,0
                   'false positive',  # y_test, y_pred = 0,1
                   'false negative',  # y_test, y_pred = 1,0
                   'true positive'    # y_test, y_pred = 1,1
                  ])

df_test['case'] = labesl[y_test * 2 + y_pred]

You could try using numpy.select here.您可以尝试在此处使用numpy.select eg:例如:

condlist = [
    (y_test == 1) & (y_pred == 1), # True positive
    (y_test == 1) & (y_pred == 0), # False Negative
    (y_test == 0) & (y_pred == 0), # True negative
    (y_test == 0) & (y_pred == 1), # False positive
]

choicelist = ['true positive', 'false negative', 'true negative', 'false positive']

df_test['case'] = np.select(condlist, choicelist)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取混淆矩阵的误报和漏报相关数据集? - Getting False positives and False negatives relevant datasets of confusion matrix? 有没有办法用已知的真阳性、真阴性、假阳性和假阴性来绘制混淆矩阵? - Is there a way to draw confusion matrix with known True Positive, True Negative, False Positive and False Negative? 使用 tensorflow 获取真阳性、假阳性、假阴性和真阴性列表 - Get list of true positives, false positives, false negatives and true negatives with tensorflow 是否可以检索由混淆矩阵识别的误报/误报? - Is it possible to retrieve False Positives/ False Negatives identified by a confusion Matrix? 计算 DataFrame 中响应的真阳性和假阴性 - Calculate True Positives and False Negatives for Responses Within a DataFrame 考虑到所有类,如何找到所有真阳性、阴性和假阳性和阴性 - How to find all the True Positives,negatives and False Positives and Negatives considering all the classes True positive, False positive, False Negative 计算数据帧 python - True positive, False positive, False Negative calculation data frame python 哪个是哪个? (真阳性、真阴性、假阳性、假阴性) - Which one is which ? (True Positive, True Negative, False Positive, False Negative) Scikit-learn:如何获取True Positive、True Negative、False Positive和False Negative - Scikit-learn: How to obtain True Positive, True Negative, False Positive and False Negative 如何从多类分类的混淆矩阵中提取假阳性,假阴性 - How to extract False Positive, False Negative from a confusion matrix of multiclass classification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM