Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x python中矩阵的计数_Python 3.x_Math_Machine Learning_Deep Learning - Fatal编程技术网

Python 3.x python中矩阵的计数

Python 3.x python中矩阵的计数,python-3.x,math,machine-learning,deep-learning,Python 3.x,Math,Machine Learning,Deep Learning,我想计算三个类别的真阳性、假阳性、假阴性、真阴性。我曾经有两个类别猫狗,这是我用来计算混淆矩阵的方法 Y_pred has either a cat or dog y_true has either a cat or dog confusion_matrix_output =confusion_matrix(y_true, y_pred) True_Positive = confusion_matrix_output[0][0] False_Pos

我想计算三个类别的真阳性、假阳性、假阴性、真阴性。我曾经有两个类别猫狗,这是我用来计算混淆矩阵的方法

    Y_pred has either a cat or dog 
    y_true has either a cat or dog  
    confusion_matrix_output =confusion_matrix(y_true, y_pred) 
    True_Positive = confusion_matrix_output[0][0]
    False_Positive = confusion_matrix_output[0][1]
    False_Negative = confusion_matrix_output[1][0]
    True_Negative = confusion_matrix_output[1][1]
现在我有三门课“猫”“狗”“兔子”

Y_pred has Cat Dog rabbit
y_true has Cat Dog rabbit

如何计算真阳性、假阳性、假阴性、真阴性???

现在你有三个类,所以不再只是阳性和阴性。 你必须看看: 猫被预测为猫,狗被预测为狗,兔子被预测为兔子,狗被预测为猫,猫被预测为狗,等等。在这种情况下,您将得到3乘3的混淆矩阵。混淆矩阵的大小是n乘n,其中n是类的数量

sklearn.metrics.conflusion_矩阵将所有这些抽象出来,并为您创建一个n×n矩阵。试试这个:

from sklearn.metrics import confusion_matrix
confusion_matrix_output =confusion_matrix(y_true, y_pred) 
Cat_P_Cat = confusion_matrix_output[0][0]

对于像这样的普通事情,以前总是有一个正确编写的模块:我在上面提到的代码中使用它,混淆_matrixy _true,y _pred当您有多个类时,那么您使用的是召回和精确性,而不是T/F-P/N。对于两个类,您选择Cat为正,Dog为负,对于三个类,二进制逻辑不再工作。