Esempio n. 1
0
def print_auc_table_to_file(preds, target, preds_header=None, filename=None):
    # prints a table of AUROCs and p-values
    # also train the baseline model using df_mdl
    # preds is a dictionary of predictions
    if filename is None:
        filename = 'auc_table.csv'

    f = open(filename, 'w')

    if preds_header is None:
        preds_header = preds.keys()

    P = len(preds_header)
    y = target == 1
    f.write('{}\t'.format(''))

    # print header line
    for p in range(P):
        f.write('{}\t'.format(preds_header[p]))
    f.write('\n')

    for p in range(P):
        f.write('{}\t'.format(preds_header[p]))
        pname = preds_header[p]
        for q in range(P):
            qname = preds_header[q]
            if pname not in preds:
                f.write('{}\t'.format(
                    ''))  # skip this as we do not have the prediction
            elif p == q:
                auc, ci = ru.calc_auc(preds[pname],
                                      y,
                                      with_ci=True,
                                      alpha=0.05)
                f.write('{:0.3f} [{:0.3f}, {:0.3f}]\t'.format(
                    auc, ci[0], ci[1]))
            elif q > p:
                #TODO: cronenback alpha
                f.write('{}\t'.format(''))

            else:
                if qname not in preds:
                    f.write('{}\t'.format(
                        ''))  # skip this as we do not have the prediction
                else:
                    pval, ci = ru.test_auroc(preds[pname], preds[qname], y)
                    if pval > 0.001:
                        f.write('{:0.3f}{}\t'.format(pval, ''))
                    else:
                        f.write('< 0.001{}\t'.format(''))

        f.write('\n')

    f.close()
Esempio n. 2
0
def print_auc_table(preds, target, preds_header, with_alpha=True):
    # prints a table of AUROCs and p-values like what was presented in the sepsis 3 paper
    y = target == 1
    P = len(preds)

    print('{:5s}'.format(''), end='\t')

    for p in range(P):
        print('{:20s}'.format(preds_header[p]), end='\t')

    print('')

    for p in range(P):
        ppred = preds_header[p]
        print('{:5s}'.format(ppred), end='\t')
        for q in range(P):
            qpred = preds_header[q]
            if ppred not in preds:
                print('{:20s}'.format(''),
                      end='\t')  # skip this as we do not have the prediction
            elif p == q:
                auc, ci = ru.calc_auc(preds[ppred],
                                      y,
                                      with_ci=True,
                                      alpha=0.05)
                print('{:0.3f} [{:0.3f}, {:0.3f}]'.format(auc, ci[0], ci[1]),
                      end='\t')
            elif qpred not in preds:
                print('{:20s}'.format(''),
                      end='\t')  # skip this as we do not have the prediction
            elif q > p:
                if with_alpha == False:
                    # skip printing cronbach alpha as requested by input
                    print('{:20s}'.format(''), end='\t')
                else:
                    alpha, ci = cronbach_alpha_bootstrap(np.row_stack(
                        [preds[ppred], preds[qpred]]),
                                                         B=2000)
                    print('{:0.3f} [{:0.3f}, {:0.3f}]'.format(
                        alpha, ci[0], ci[1]),
                          end='\t')
            else:
                pval, ci = ru.test_auroc(preds[ppred], preds[qpred], y)
                if pval > 0.001:
                    print('{:0.3f}{:15s}'.format(pval, ''), end='\t')
                else:
                    print('< 0.001{:15s}'.format(''), end='\t')

        print('')