def plot_one_pr_curve(comps_removed, precision_vectors, recall_vectors, auprc_list, ymax, batch_column, total_comp, filename): colors_lines = pt.get_style_combos(['lines', 'colors']) fig = plt.figure(figsize = (7, 7)) ax = fig.add_subplot(1,1,1) for i, ncomps in enumerate(comps_removed): # Since sklearn sets the first precision at recall=0 to 1, # I remove this value and any subsequent values at recall=0 # so that plotting only starts with the precision obtained # at the threshold of the first true positive observation # (in case multiple true positives have the same associated # score). recall_vec = recall_vectors[i] precision_vec = precision_vectors[i] first_nonzero_recall_ind = np.nanmin(np.where(recall_vec > 0)[0]) first_nonzero_recall_val = recall_vec[first_nonzero_recall_ind] last_first_nonzero_recall_ind = np.nanmax(np.where(recall_vec == first_nonzero_recall_val)[0]) recall_vec = recall_vec[last_first_nonzero_recall_ind:] precision_vec = precision_vec[last_first_nonzero_recall_ind:] # On to plotting style = colors_lines.next() ax.plot(recall_vec, precision_vec, style, label = '{} (normalized AUPRC = {:.3f})'.format(ncomps, auprc_list[i])) ax.set_xscale('log') ax.set_ylim([0, ymax]) ax.set_ylabel('Precision') ax.set_xlabel('Recall') plt.title('Precision-recall analysis of\n"{}" batch effects'.format(batch_column)) if total_comp > 1: plt.title('Precision-recall analysis of\n"{}" batch effects'.format(batch_column)) lgd = ax.legend(bbox_to_anchor = (1.05, 1), loc = 2, title = "Number of components\nremoved") plt.savefig(filename, bbox_extra_artists = ([lgd]), bbox_inches = 'tight') else: plt.title('Precision-recall analysis of "{}"\nbatch effects (normalized AUPRC = {:.3f})'.format(batch_column, auprc_list[i])) plt.savefig(filename)
def plot_one_pr_curve(comps_removed, precision_vectors, recall_vectors, auc_list, ymax, batch_column, filename): colors_lines = pt.get_style_combos(['lines', 'colors']) fig = plt.figure(figsize = (7, 7)) ax = fig.add_subplot(1,1,1) for i, ncomps in enumerate(comps_removed): style = colors_lines.next() ax.plot(recall_vectors[i], precision_vectors[i], style, label = '{} (normalized AUC = {:.3f})'.format(ncomps, auc_list[i])) ax.set_xscale('log') ax.set_ylim([0, ymax]) ax.set_ylabel('Precision') ax.set_xlabel('Recall') lgd = ax.legend(bbox_to_anchor = (1.05, 1), loc = 2, title = "Number of components\nremoved") plt.title('Precision-recall analysis of\n"{}" batch effects'.format(batch_column)) plt.savefig(filename, bbox_extra_artists = ([lgd]), bbox_inches = 'tight')
def plot_roc_curves(comps_removed, fpr_vecs, tpr_vecs, auc_list, batch_column, pr_folder): filename = get_lda_roc_curve_filename(pr_folder) colors_lines = pt.get_style_combos(['lines', 'colors']) fig = plt.figure(figsize = (7, 7)) ax = fig.add_subplot(1,1,1) for i, ncomps in enumerate(comps_removed): style = colors_lines.next() ax.plot(fpr_vecs[i], tpr_vecs[i], style, label = '{} (AUC = {:.3f})'.format(ncomps, auc_list[i])) ax.set_ylim([0, 1]) ax.set_xlabel('False Positive Rate (Specificity)') ax.set_ylabel('True Positive Rate (Sensitivity)') lgd = ax.legend(bbox_to_anchor = (1.05, 1), loc = 2, title = "Number of components\nremoved") plt.title('ROC analysis of\n"{}" batch effects'.format(batch_column)) plt.savefig(filename, bbox_extra_artists = ([lgd]), bbox_inches = 'tight')