def optimize_threshold_with_roc(roc, thresholds, criterion='dist'):
if roc.shape[1] > roc.shape[0]:
roc = roc.T
assert(roc.shape[0] == thresholds.shape[0])
if criterion == 'margin':
scores = roc[:,1]-roc[:,0]
else:
scores = -cdist(np.array([[0,1]]), roc)
ti = np.nanargmax(scores)
return thresholds[ti], ti
评论列表
文章目录