[英]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.