def performance_measure(tp, tn, fp, fn):
    """
    For output of confusion table gives various perfomance performance_measures:
      :return: tpr, fpr, precision, recall, balanced accuracy, accuracy, f1-score
    """
    tpr = float(tp) / (tp + fn) if tp + fn != 0 else 0
    fpr = float(fp) / (fp + tn) if fp + tn != 0 else 0
    tnr = float(tn) / (tn + fp) if tn + fp != 0 else 0
    recall = float(tp) / (tp + fn) if tp + fn != 0 else 0
    precision = float(tp) / (tp + fp) if tp + fp != 0 else 1
    bal_accur = 0.5 * tpr + 0.5 * tnr
    accur = float(tp + tn) / (tp + tn + fp + fn)
    if precision + recall != 0:
        f1 = 2 * precision * recall / (precision + recall)
    else:
        f1 = 0
    return tpr, fpr, precision, recall, bal_accur, accur, f1
