测量系统Roc的性能

问题描述 投票:0回答:1

我是机器学习和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数组representy_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]

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

plot

我应该更改分数标签我失去了任何帮助将欣赏它。

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

fpr [0. 0. 0. 1.]
tpr [0.  0.2 1.  1. ]
thresholds [1.99308544 0.99308544 0.90004301 0.        ]
python keras scikit-learn face-recognition roc
1个回答
1
投票

假设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)

© www.soinside.com 2019 - 2024. All rights reserved.