(cm, pos_indices, beta=1)
return pr, re, fbeta
Uses a confusion matrix to compute precision, recall and fbeta
Uses a confusion matrix to compute precision, recall and fbeta
Uses a confusion matrix to compute precision recall and fbeta
def pr_re_fbeta(cm, pos_indices, beta=1):
    """Uses a confusion matrix to compute precision, recall and fbeta"""
    num_classes = cm.shape[0]
    neg_indices = [i for i in range(num_classes) if i not in pos_indices]
    cm_mask = np.ones([num_classes, num_classes])
    cm_mask[neg_indices, neg_indices] = 0
    diag_sum = tf.reduce_sum(tf.diag_part(cm * cm_mask))

    cm_mask = np.ones([num_classes, num_classes])
    cm_mask[:, neg_indices] = 0
    tot_pred = tf.reduce_sum(cm * cm_mask)

    cm_mask = np.ones([num_classes, num_classes])
    cm_mask[neg_indices, :] = 0
    tot_gold = tf.reduce_sum(cm * cm_mask)

    pr = safe_div(diag_sum, tot_pred)
    re = safe_div(diag_sum, tot_gold)
    fbeta = safe_div((1. + beta**2) * pr * re, beta**2 * pr + re)

    return pr, re, fbeta
def pr_re_fbeta ( cm , pos_indices , beta = 1 ) : num_classes = cm . shape [ 0 ] neg_indices = [ i for i in range ( num_classes ) if i not in pos_indices ] cm_mask = np . ones ( [ num_classes , num_classes ] ) cm_mask [ neg_indices , neg_indices ] = 0 diag_sum = tf . reduce_sum ( tf . diag_part ( cm * cm_mask ) ) cm_mask = np . ones ( [ num_classes , num_classes ] ) cm_mask [ : , neg_indices ] = 0 tot_pred = tf . reduce_sum ( cm * cm_mask ) cm_mask = np . ones ( [ num_classes , num_classes ] ) cm_mask [ neg_indices , : ] = 0 tot_gold = tf . reduce_sum ( cm * cm_mask ) pr = safe_div ( diag_sum , tot_pred ) re = safe_div ( diag_sum , tot_gold ) fbeta = safe_div ( ( 1. + beta ** 2 ) * pr * re , beta ** 2 * pr + re ) return pr , re , fbeta