测量系统 Roc 的性能

mesuring the performance of system Roc

我对机器学习还很陌生 python。任何帮助将不胜感激。

通常在Matlab中,很容易绘制出来。 我想绘制 roc 曲线来评估人脸识别系统的性能,我计算了两个图像之间的欧几里德距离和余弦相似度,我想将其两个参数的计算应用于数据库(测试列车)。我如何在这个数据库图像上绘制 roc 曲线

我如何衡量自动编码器的性能?

此代码无效:

predictions_prob = your_model.predict_proba(x_test)
false_positive_rate, recall, thresholds = roc_curve(y_test, predictions_prob[:,1])
roc_auc = auc(false_positive_rate, recall)
plt.plot(false_positive_rate, recall, 'g', label = 'AUC %s = %0.2f' % ('model name', roc_auc))
plt.plot([0,1], [0,1], 'r--')
plt.legend(loc = 'lower right')
plt.ylabel('Recall')
plt.xlabel('Fall-out')
plt.title('ROC Curve')

这是预训练模型weights

所以现在我有两个数组 y_true 如果两张脸相似 '1' 或者不相似 '0'

y_true [0 1 1 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 0 0]

y_score数组表示y_score

[0.43031937 0.09115553 0.00650781 0.02242869 0.38608587 0.09407699
 0.40521139 0.08062053 0.37445426 0.73493853 0.7103999  0.72978038
 0.66644344 0.63952136 0.61384821 0.58388719 0.64563826 0.7302449
 0.50854671 0.74351138 0.74457312 0.86807218 0.83802608 0.74165669
 0.74858481 0.76547028 0.73587325 0.78119443 0.59438175 0.74271324
 0.65287331 0.55672997 0.6840947  0.86698833 0.69892132 0.9039218
 0.73688647 0.88281097 0.65161654 0.6082072  0.60127196 0.59740826
 0.63763261 0.60536379 0.642178   0.61151108 0.62726742 0.61947313
 0.67193428 0.7865534  0.65491107 0.6640633  0.68394253 0.63343072
 0.79708609 0.78625438 0.70690271 0.75213048 0.76652744 0.85628764
 0.82893997 0.75122409 0.76786727 0.7644964  0.75824204 0.78366616
 0.65271395 0.75293976 0.72236988 0.56250972 0.72455084 0.9160955
 0.74614334 0.94117467 0.75922103 0.91618422]

当我 运行 代码时,我得到了这个情节:

我应该如何更改分数标签我丢失了任何帮助将不胜感激。

我不知道为什么我在 tpr 和 fpr 和阈值中只得到 4 个元素

fpr [0. 0. 0. 1.]
tpr [0.  0.2 1.  1. ]
thresholds [1.99308544 0.99308544 0.90004301 0.        ]

假设y_test是一个包含0和1的numpy数组,其中0表示两个面不同(负),1表示两个面相同(正)。

还假设您在预测中使用 verifyFace。假设它的输出是 pred,其中包含每对之间的距离。

根据定义,两个低于阈值的面孔将被视为正值。这与典型的二元分类任务正好相反。

所以这是一个解决方法:

from sklearn.metrics import roc_curve, auc
import numpy as np
import matplotlib.pyplot as plt

n_samples = 1000
pred = np.random.randn(n_samples)
y_test = np.random.randint(2, size=(n_samples,))

max_dist = max(pred)
pred = np.array([1-e/max_dist for e in pred])
fpr, tpr, thresholds = roc_curve(y_test, pred)
roc_auc = auc(fpr, tpr)
plt.figure()
lw = 2
plt.plot(fpr, tpr, color='darkorange',
         lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.show()

关键概念是将 pred 转换为 confidence.

的序列

参考: How to use prediction score in creating ROC curve with Scikit-Learn

Receiver Operating Characteristic (ROC)