sample/sample.py
def calc_scores_on_both_classes(y, y_pred, n_folds=10, metric=sk_mt.f1_score):
    """
    Evaluate a score defined by metric for both classes on every partition.
    :param y:
    :param y_pred: predicted labels
    :param n_folds: number of folds. if <=1 then just calculate the score for each class on the whole sample
    :param metric: metric to be assessed over the predictions
    :return: scores of both classes, array of floats with shape (2, n_folds)
    """
    y_true = np.array(y)
    y_true_inv = 1 - y_true
    y_pred = np.array(y_pred)
    y_pred_inv = 1 - y_pred

    scorer = lambda folds: metric(folds[0], folds[1])

    if n_folds > 1:
        folds_y_true = np.array_split(y_true, n_folds)
        folds_y_pred = np.array_split(y_pred, n_folds)
        folds_y_true_inv = np.array_split(y_true_inv, n_folds)
        folds_y_pred_inv = np.array_split(y_pred_inv, n_folds)
        scores_class0 = list(map(scorer, zip(folds_y_true, folds_y_pred)))
        scores_class1 = list(map(scorer, zip(folds_y_true_inv, folds_y_pred_inv)))
    else:
        scores_class0 = scorer((y_true, y_pred))
        scores_class1 = scorer((y_true_inv, y_pred_inv))

    return [scores_class0, scores_class1]

    Evaluate a score defined by metric for both classes on every partition.
    :param y:
    :param y_pred: predicted labels
    :param n_folds: number of folds. if <=1 then just calculate the score for each class on the whole sample
    :param metric: metric to be assessed over the predictions
    :return: scores of both classes, array of floats with shape (2, n_folds)
    
Evaluate a score defined by metric for both classes on every partition.
Evaluate a score defined by metric for both classes on every partition .
def calc_scores_on_both_classes(y, y_pred, n_folds=10, metric=sk_mt.f1_score):
    y_true = np.array(y)
    y_true_inv = 1 - y_true
    y_pred = np.array(y_pred)
    y_pred_inv = 1 - y_pred
    scorer = lambda folds: metric(folds[0], folds[1])
    if n_folds > 1:
        folds_y_true = np.array_split(y_true, n_folds)
        folds_y_pred = np.array_split(y_pred, n_folds)
        folds_y_true_inv = np.array_split(y_true_inv, n_folds)
        folds_y_pred_inv = np.array_split(y_pred_inv, n_folds)
        scores_class0 = list(map(scorer, zip(folds_y_true, folds_y_pred)))
        scores_class1 = list(map(scorer, zip(folds_y_true_inv, folds_y_pred_inv)))
    else:
        scores_class0 = scorer((y_true, y_pred))
        scores_class1 = scorer((y_true_inv, y_pred_inv))
    return [scores_class0, scores_class1]
def calc_scores_on_both_classes ( y , y_pred , n_folds = 10 , metric = sk_mt . f1_score ) : y_true = np . array ( y ) y_true_inv = 1 - y_true y_pred = np . array ( y_pred ) y_pred_inv = 1 - y_pred scorer = lambda folds : metric ( folds [ 0 ] , folds [ 1 ] ) if n_folds > 1 : folds_y_true = np . array_split ( y_true , n_folds ) folds_y_pred = np . array_split ( y_pred , n_folds ) folds_y_true_inv = np . array_split ( y_true_inv , n_folds ) folds_y_pred_inv = np . array_split ( y_pred_inv , n_folds ) scores_class0 = list ( map ( scorer , zip ( folds_y_true , folds_y_pred ) ) ) scores_class1 = list ( map ( scorer , zip ( folds_y_true_inv , folds_y_pred_inv ) ) ) else : scores_class0 = scorer ( ( y_true , y_pred ) ) scores_class1 = scorer ( ( y_true_inv , y_pred_inv ) ) return [ scores_class0 , scores_class1 ]
Evaluate a score defined by metric for both classes on every partition.
Evaluate a score defined by metric for both classes on every partition .
"""
    Evaluate a score defined by metric for both classes on every partition.
    :param y:
    :param y_pred: predicted labels
    :param n_folds: number of folds. if <=1 then just calculate the score for each class on the whole sample
    :param metric: metric to be assessed over the predictions
    :return: scores of both classes, array of floats with shape (2, n_folds)
    """
scores of both classes, array of floats with shape (2, n_folds)
scores of both classes array of floats with shape ( 2 n_folds )
y
None
y_pred
None
n_folds
number of folds. if <=1 then just calculate the score for each class on the whole sample
number of folds . if < = 1 then just calculate the score for each class on the whole sample
metric
metric to be assessed over the predictions
metric to be assessed over the predictions