EER的基本知识和使用
生活随笔
收集整理的這篇文章主要介紹了
EER的基本知识和使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- @[toc]
- EER值求取
- ROC概念
- 代碼示例
- @[toc]
- EER值求取
- ROC概念
- 代碼示例
EER值求取
EER:等錯誤概率是說話人識別中常用的評價標準,是錯誤接受率(FA)和錯誤拒絕率(FR)的一個相對平衡點的閾值點,這個閾值點可以作為實際使用階段的固定閾值。
def calculate_eer(y, y_score):# y denotes groundtruth scores,(真實標簽)# y_score denotes the prediction scores.(經過softmax得到的標簽)from scipy.optimize import brentqfrom sklearn.metrics import roc_curvefrom scipy.interpolate import interp1dfpr, tpr, thresholds = roc_curve(y, y_score, pos_label=1)eer = brentq(lambda x : 1. - x - interp1d(fpr, tpr)(x), 0., 1.)thresh = interp1d(fpr, thresholds)(eer)return eer, threshROC概念
ROC(Receiver Operating Characteristic)全稱受試者工作特征曲線。縱軸是真正例率(True Postitive Rate,TPR),橫軸是假正例率(False Positive Rate,FPR)
TPR = TP/(TP + FN)
FPR = FP/(FP + TN)
代碼示例
import numpy as np import matplotlib.pyplot as plt from itertools import cyclefrom sklearn import svm, datasets from sklearn.metrics import roc_curve, auc from sklearn.model_selection import train_test_split from sklearn.preprocessing import label_binarize from sklearn.multiclass import OneVsRestClassifier from scipy import interp# Import some data to play with iris = datasets.load_iris() X = iris.data y = iris.target# Binarize the output y = label_binarize(y, classes=[0, 1, 2]) n_classes = y.shape[1]# Add noisy features to make the problem harder random_state = np.random.RandomState(0) n_samples, n_features = X.shape X = np.c_[X, random_state.randn(n_samples, 200 * n_features)]# shuffle and split training and test sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.5,random_state=0)# Learn to predict each class against the other classifier = OneVsRestClassifier(svm.SVC(kernel='linear', probability=True,random_state=random_state)) y_score = classifier.fit(X_train, y_train).decision_function(X_test)# Compute ROC curve and ROC area for each class fpr = dict() tpr = dict() roc_auc = dict() for i in range(n_classes):fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])roc_auc[i] = auc(fpr[i], tpr[i])# Compute micro-average ROC curve and ROC area fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel()) roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])plt.figure() lw = 2 plt.plot(fpr[2], tpr[2], color='darkorange',lw=lw, label='ROC curve (area = %0.2f)' % roc_auc[2]) 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()plt.legend(loc="lower right") plt.show()引用了下面一篇博客:
P-R曲線與ROC曲線,python sklearn實現
僅作為學習記錄,供之后復習使用。
總結
以上是生活随笔為你收集整理的EER的基本知识和使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PTA 数组 7-6 二进制数据转换成十
- 下一篇: 如何选房