简体   繁体   English

如何从sklearn的gridsearchcv中获取灵敏度和特异性(真阳性率和真阴性率)?

[英]How to acquire sensitivity and specificty(true positive rate and true negative rate) from sklearn's gridsearchcv?

I've been using Gridsearchcv with a RBF SVM (binary classifier) to obtain validation accuracy heatmaps. 我一直在使用带有RBF SVM(二进制分类器)的Gridsearchcv来获得验证精度热图。 The code I've used is pretty much straight from SKlearn's website. 我用过的代码非常直接来自SKlearn的网站。 Is there a way to find the sensitivity and specificity from this? 有没有办法从中找到灵敏度和特异性? As in for the range of parameter values used by Gridsearchcv? 与Gridsearchcv使用的参数值范围一样?

If your problem is binary or multi-class classification then confusion matrix might be what you're looking for. 如果您的问题是二元或多类分类,那么混淆矩阵可能就是您正在寻找的。

from sklearn.metrics import confusion_matrix

y_true = [2, 0, 2, 2, 0, 1]
y_pred = [0, 0, 2, 2, 0, 2]
confusion_matrix(y_true, y_pred)

array([[2, 0, 0],
       [0, 0, 1],
       [1, 0, 2]])

The explanation is the following : 解释如下:

For the examples belonging to class 0, the estimator predicted 100% of them correctly (2/2). 对于属于0类的示例, 估计器正确预测了100%(2/2)。
For the examples belonging to class 1, the estimator was 100% wrong because it predicted the only example to class 2. 对于属于类1的示例,估计器是100%错误的,因为它预测了类2的唯一示例。
For the examples belonging to class 2, the estimator was 66% correct (2/3) because it predicted 2 examples to class 2 and 1 to class 0. 对于属于类2的示例,估计量为66%正确(2/3),因为它预测了2个示例到2级,1个到0级。

For binary classification : 对于二进制分类

y_true = [1, 0, 1, 0, 0, 1]
y_pred = [1, 0, 1, 1, 0, 1]

cm = confusion_matrix(y_true, y_pred)
print cm

tp = float(cm[0][0])/np.sum(cm[0])
tn = float(cm[1][1])/np.sum(cm[1])

print tp
print tn

[[2 1]
 [0 3]]
0.666666666667
1.0

About the parameters used in your GridSearchCV , you can found them in the grid_scores_ attribute. 关于GridSearchCV中使用的参数 ,您可以在grid_scores_属性中找到它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从此代码中获取真实负利率? - How to get the True Negative Rate from this code? 自定义 TensorFlow 指标:给定假阳性率下的真阳性率 - Custom TensorFlow metric: true positive rate at given false positive rate 如何找到plot ROC曲线的真阳性率和假阳性率? - How to find true positive rate and false positive rate to plot ROC curve? Pandas:计算每一行的真阳性率 - Pandas: Calculate true positive rate for each row Sklearn - 来自 GridSearchCV 的最佳估计器,refit = True - Sklearn - Best estimator from GridSearchCV with refit = True 如何计算误报率 (FPR) 和误报率百分比? - How to compute false positive rate (FPR) and False negative rate percantage? Scikit-learn:如何获取True Positive、True Negative、False Positive和False Negative - Scikit-learn: How to obtain True Positive, True Negative, False Positive and False Negative 为什么我在 Keras 神经网络中计算真阳性率的结果不同? - Why do I have different results calculating True Positive rate in Keras Neural Network? 学习率的 GridSearchCV - GridSearchCV for learning rate 从混淆矩阵中获取假阴性、假阳性、真阳性和真阴性的相关数据集 - Getting relevant datasets of false negatives, false positives, true positive and true negative from confusion matrix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM