04cd555be76efc7baced753c751c4257d41eb75d,EvalMetrics.py,,ErrorRateAt95Recall,#Any#Any#,10

Before Change


def ErrorRateAt95Recall(labels, scores):
    recall_point = 0.95
    // Sort label-score tuples by the score in descending order.
    sorted_scores = zip(labels, scores)
    sorted_scores.sort(key=operator.itemgetter(1), reverse=False)

    // Compute error rate
    n_match = sum(1 for x in sorted_scores if x[0] == 1)
    n_thresh = recall_point * n_match
    tp = 0
    count = 0
    for label, score in sorted_scores:
        count += 1
        if label == 1:
            tp += 1
        if tp >= n_thresh:
            break

    return float(count - tp) / count

After Change



import numpy as np
def ErrorRateAt95Recall(labels, scores):
    distances = 1.0 / (scores + 1e-8)
    recall_point = 0.95
    labels = labels[np.argsort(distances)]
    // Sliding threshold: get first index where recall >= recall_point. 
    // This is the index where the number of elements with label==1 below the threshold reaches a fraction of 
    // "recall_point" of the total number of elements with label==1. 
    // (np.argmax returns the first occurrence of a "1" in a bool array). 
    threshold_index = np.argmax(np.cumsum(labels) >= recall_point * np.sum(labels)) 

    FP = np.sum(labels[:threshold_index] == 0) // Below threshold (i.e., labelled positive), but should be negative
    TN = np.sum(labels[threshold_index:] == 0) // Above threshold (i.e., labelled negative), and should be negative
    return float(FP) / float(FP + TN)
"""import operator
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 8

Instances


Project Name: DagnyT/hardnet
Commit Name: 04cd555be76efc7baced753c751c4257d41eb75d
Time: 2017-07-27
Author: ducha.aiki@gmail.com
File Name: EvalMetrics.py
Class Name:
Method Name: ErrorRateAt95Recall


Project Name: flow-project/flow
Commit Name: 94a405c5f6caafc99550d5267a6c94cf20af2d59
Time: 2017-10-27
Author: eugenevinitsky@airbears2-10-142-37-47.airbears2.1918.berkeley.edu
File Name: flow/envs/loop_accel.py
Class Name: SimpleMultiAgentAccelerationEnvironment
Method Name: get_state


Project Name: soft-matter/trackpy
Commit Name: c6607119c25d0178245243ef3fdd3d176dd0d8f2
Time: 2020-01-22
Author: anntzer.lee@gmail.com
File Name: trackpy/linking/utils.py
Class Name:
Method Name: coords_from_df