def dprime(confusion_matrix):
"""
Function takes in a 2x2 confusion matrix and returns the d-prime value for the predictions.
d' = z(hit rate)-z(false alarm rate)
http://en.wikipedia.org/wiki/D'
"""
if max(confusion_matrix.shape) > 2:
return False
else:
hit_rate = confusion_matrix[0, 0] / confusion_matrix[0, :].sum()
fa_rate = confusion_matrix[1, 0] / confusion_matrix[1, :].sum()
nudge = 0.0001
if (hit_rate >= 1): hit_rate = 1 - nudge
if (hit_rate <= 0): hit_rate = 0 + nudge
if (fa_rate >= 1): fa_rate = 1 - nudge
if (fa_rate <= 0): fa_rate = 0 + nudge
dp = norm.ppf(hit_rate)-norm.ppf(fa_rate)
return dp
# accuracy (% correct)
评论列表
文章目录