Example #1
0
def matthews_correlation_coefficient(y_true, y_pred):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred,
                                       matthews_correlation_coefficient)
    if TP is not None:
        rrr = mcc_basic(TP, FP, TN, FN)
    elif rrr == _NON_BINARY:
        y_true, y_pred = prep_ys(y_true, y_pred)

        true_class_names = inv_map(nnstate.CURRENT_TRUE_MAP)

        reduced_y_true = []
        for y in y_true:
            tru_nam = true_class_names[int(y)]
            reduced_y_true.append(reduced_label(tru_nam))

        reduced_y_pred = []
        for y in y_pred:
            tru_nam = true_class_names[int(y)]
            reduced_y_pred.append(reduced_label(tru_nam))

        TP, FP, TN, FN, P, N = binary_results(reduced_y_true, reduced_y_pred)
        if TP is not None:
            rrr = mcc_basic(TP, FP, TN, FN)

    return update_met_log(matthews_correlation_coefficient, rrr, inc=True)
Example #2
0
def sensitivity(y_true, y_pred):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred, sensitivity)
    if TP is not None:
        if P == 0:
            rrr = _EMPTY_TENSOR
        else:
            rrr = TP / P
    return update_met_log(sensitivity, rrr)
Example #3
0
def miss_rate(y_true, y_pred):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred, miss_rate)
    if TP is not None:
        if P == 0:
            rrr = _EMPTY_TENSOR
        else:
            rrr = FN / P
    return update_met_log(miss_rate, rrr)
Example #4
0
def specificity(y_true, y_pred):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred, specificity)
    if TP is not None:
        if N == 0:
            rrr = -2
        else:
            rrr = TN / N
    return update_met_log(specificity, rrr)
Example #5
0
def false_positive_rate(y_true, y_pred):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred, false_positive_rate)
    if TP is not None:
        if N == 0:
            rrr = _EMPTY_TENSOR
        else:
            rrr = FP / N
    return update_met_log(false_positive_rate, rrr)
Example #6
0
def precision(y_true, y_pred):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred, precision)
    if TP is not None:
        if (TP + FP) == 0:
            rrr = _EMPTY_TENSOR
        else:
            rrr = TP / (TP + FP)
    return update_met_log(precision, rrr)
Example #7
0
def error_rate(y_true, y_pred, real_error=True):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred, error_rate)
    # breakpoint()
    if TP is not None:
        if (P + N) == 0:
            rrr = _EMPTY_TENSOR
        else:
            rrr = error_rate_basic(FP, FN, P, N)
    elif rrr == _NON_BINARY:
        y_true, y_pred = prep_ys(y_true, y_pred)
        rrr = error_rate_core(y_true, y_pred)
    return update_met_log(error_rate, rrr) if real_error else rrr
Example #8
0
def mcc_multi(y_true, y_pred):
    rrr, TP, FP, TN, FN, P, N = basics(y_true, y_pred, mcc_multi)
    if TP is not None:
        err('this should never happen if i have >2 classes')
        rrr = mcc_basic(TP, FP, TN, FN)
    elif rrr == _NON_BINARY:
        y_true, y_pred = prep_ys(y_true, y_pred)
        import sklearn.metrics
        # https://github.com/scikit-learn/scikit-learn/issues/16924
        go = True
        for i in range(nnstate.num_pred_classes()):
            if count_nonzero(y_pred == i) == 0:
                go = False
                break
        if go:
            rrr = sklearn.metrics.matthews_corrcoef(list(map(int, y_true)),
                                                    y_pred.tolist())

        else:
            rrr = -6

    return update_met_log(mcc_multi, rrr, inc=True)
Example #9
0
def accuracy(y_true, y_pred):
    rrr = 1 - error_rate(y_true, y_pred, real_error=False)
    return update_met_log(accuracy, rrr)