(score_vec, label_vec, thresholds=None, FARs=None, get_false_indices=False)
Compute Receiver operating characteristic (ROC) with a score and label vector.
Compute Receiver operating characteristic (ROC) with a score and label vector.
Compute Receiver operating characteristic ( ROC ) with a score and label vector .
def ROC(score_vec, label_vec, thresholds=None, FARs=None, get_false_indices=False):
    ''' Compute Receiver operating characteristic (ROC) with a score and label vector.
    '''
    assert score_vec.ndim == 1
    assert score_vec.shape == label_vec.shape
    assert label_vec.dtype == np.bool
    
    if thresholds is None:
        thresholds = find_thresholds_by_FAR(score_vec, label_vec, FARs=FARs)

    assert len(thresholds.shape)==1 
    if np.size(thresholds) > 10000:
        warn('number of thresholds (%d) very large, computation may take a long time!' % np.size(thresholds))

    # FARs would be check again
    TARs = np.zeros(thresholds.shape[0])
    FARs = np.zeros(thresholds.shape[0])
    false_accept_indices = []
    false_reject_indices = []
    for i,threshold in enumerate(thresholds):
        accept = score_vec >= threshold
        TARs[i] = np.mean(accept[label_vec])
        FARs[i] = np.mean(accept[~label_vec])
        if get_false_indices:
            false_accept_indices.append(np.argwhere(accept & (~label_vec)).flatten())
            false_reject_indices.append(np.argwhere((~accept) & label_vec).flatten())

    if get_false_indices:
        return TARs, FARs, thresholds, false_accept_indices, false_reject_indices
    else:
        return TARs, FARs, thresholds
def ROC ( score_vec , label_vec , thresholds = None , FARs = None , get_false_indices = False ) : assert score_vec . ndim == 1 assert score_vec . shape == label_vec . shape assert label_vec . dtype == np . bool if thresholds is None : thresholds = find_thresholds_by_FAR ( score_vec , label_vec , FARs = FARs ) assert len ( thresholds . shape ) == 1 if np . size ( thresholds ) > 10000 : warn ( 'number of thresholds (%d) very large, computation may take a long time!' % np . size ( thresholds ) ) # FARs would be check again TARs = np . zeros ( thresholds . shape [ 0 ] ) FARs = np . zeros ( thresholds . shape [ 0 ] ) false_accept_indices = [ ] false_reject_indices = [ ] for i , threshold in enumerate ( thresholds ) : accept = score_vec >= threshold TARs [ i ] = np . mean ( accept [ label_vec ] ) FARs [ i ] = np . mean ( accept [ ~ label_vec ] ) if get_false_indices : false_accept_indices . append ( np . argwhere ( accept & ( ~ label_vec ) ) . flatten ( ) ) false_reject_indices . append ( np . argwhere ( ( ~ accept ) & label_vec ) . flatten ( ) ) if get_false_indices : return TARs , FARs , thresholds , false_accept_indices , false_reject_indices else : return TARs , FARs , thresholds