(y_true, y_score, pos_label=None)
return np.array(fps), np.array(tps), thresholds
Calculate true and false positives per binary classification threshold.

    Parameters
    ----------
    y_true : array, shape = [n_samples]
        True targets of binary classification

    y_score : array, shape = [n_samples]
        Estimated probabilities or decision function

    pos_label : int or str, default=None
        The label of the positive class

    sample_weight : array-like of shape = [n_samples], optional
        Sample weights.

    Returns
    -------
    fps : array, shape = [n_thresholds]
        A count of false positives, at index i being the number of negative
        samples assigned a score >= thresholds[i]. The total number of
        negative samples is equal to fps[-1] (thus true negatives are given by
        fps[-1] - fps).

    tps : array, shape = [n_thresholds <= len(np.unique(y_score))]
        An increasing count of true positives, at index i being the number
        of positive samples assigned a score >= thresholds[i]. The total
        number of positive samples is equal to tps[-1] (thus false negatives
        are given by tps[-1] - tps).

    thresholds : array, shape = [n_thresholds]
        Decreasing score values.
Calculate true and false positives per binary classification threshold.
Calculate true and false positives per binary classification threshold .
def get_fps_tps_thresholds(y_true, y_score, pos_label=None):
    '''
    Calculate true and false positives per binary classification threshold.

    Parameters
    ----------
    y_true : array, shape = [n_samples]
        True targets of binary classification

    y_score : array, shape = [n_samples]
        Estimated probabilities or decision function

    pos_label : int or str, default=None
        The label of the positive class

    sample_weight : array-like of shape = [n_samples], optional
        Sample weights.

    Returns
    -------
    fps : array, shape = [n_thresholds]
        A count of false positives, at index i being the number of negative
        samples assigned a score >= thresholds[i]. The total number of
        negative samples is equal to fps[-1] (thus true negatives are given by
        fps[-1] - fps).

    tps : array, shape = [n_thresholds <= len(np.unique(y_score))]
        An increasing count of true positives, at index i being the number
        of positive samples assigned a score >= thresholds[i]. The total
        number of positive samples is equal to tps[-1] (thus false negatives
        are given by tps[-1] - tps).

    thresholds : array, shape = [n_thresholds]
        Decreasing score values.
    '''
    check_consistent_length(y_true, y_score)
    classes = np.unique(y_true)
    if (pos_label is None and
        not (np.array_equal(classes, [0, 1]) or
             np.array_equal(classes, [-1, 1]) or
             np.array_equal(classes, [0]) or
             np.array_equal(classes, [-1]) or
             np.array_equal(classes, [1]))):
        raise ValueError("Data is not binary and pos_label is not specified")
    elif pos_label is None:
        pos_label = 1.
    y_true = (y_true == pos_label)
    desc_score_indices = np.argsort(y_score, kind="mergesort")[::-1]
    thresholds = np.array(y_score)[desc_score_indices]
    y_true = np.array(y_true)[desc_score_indices]
    y_score = np.array(y_score)[desc_score_indices]
    tps = []
    fps = [] 
    for threshold in thresholds:
        y_prob = [1 if i >= threshold else 0 for i in y_score]
        result = [i == j for i, j in zip(y_true, y_prob)]
        postive = [i == 1 for i in y_prob]
        tp = [i and j for i, j in zip(result, postive)]
        fp = [(not i) and j for i, j in zip(result, postive)]
        tps.append(tp.count(True))
        fps.append(fp.count(True))
    return np.array(fps), np.array(tps), thresholds
def get_fps_tps_thresholds ( y_true , y_score , pos_label = None ) : check_consistent_length ( y_true , y_score ) classes = np . unique ( y_true ) if ( pos_label is None and not ( np . array_equal ( classes , [ 0 , 1 ] ) or np . array_equal ( classes , [ - 1 , 1 ] ) or np . array_equal ( classes , [ 0 ] ) or np . array_equal ( classes , [ - 1 ] ) or np . array_equal ( classes , [ 1 ] ) ) ) : raise ValueError ( "Data is not binary and pos_label is not specified" ) elif pos_label is None : pos_label = 1. y_true = ( y_true == pos_label ) desc_score_indices = np . argsort ( y_score , kind = "mergesort" ) [ : : - 1 ] thresholds = np . array ( y_score ) [ desc_score_indices ] y_true = np . array ( y_true ) [ desc_score_indices ] y_score = np . array ( y_score ) [ desc_score_indices ] tps = [ ] fps = [ ] for threshold in thresholds : y_prob = [ 1 if i >= threshold else 0 for i in y_score ] result = [ i == j for i , j in zip ( y_true , y_prob ) ] postive = [ i == 1 for i in y_prob ] tp = [ i and j for i , j in zip ( result , postive ) ] fp = [ ( not i ) and j for i , j in zip ( result , postive ) ] tps . append ( tp . count ( True ) ) fps . append ( fp . count ( True ) ) return np . array ( fps ) , np . array ( tps ) , thresholds