程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

EER的基本知识和使用

发布于2020-11-28 11:17     阅读(1566)     评论(0)     点赞(19)     收藏(5)


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 brentq
    from sklearn.metrics import roc_curve
    from scipy.interpolate import interp1d

    fpr, 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, thresh

ROC概念

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 cycle
 
from 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实现
仅作为学习记录,供之后复习使用。



所属网站分类: 技术文章 > 博客

作者:74873487

链接:https://www.pythonheidong.com/blog/article/635216/3de93c425ea8f40c4b08/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

19 0
收藏该文
已收藏

评论内容:(最多支持255个字符)