Skip to content
Snippets Groups Projects
Commit 183582ed authored by Nikolai.Hartmann's avatar Nikolai.Hartmann
Browse files

option to plot thresholds for ROC

parent cebf5f26
No related branches found
No related tags found
No related merge requests found
...@@ -17,31 +17,49 @@ def overlay_ROC(filename, *projects, **kwargs): ...@@ -17,31 +17,49 @@ def overlay_ROC(filename, *projects, **kwargs):
xlim = kwargs.pop("xlim", (0,1)) xlim = kwargs.pop("xlim", (0,1))
ylim = kwargs.pop("ylim", (0,1)) ylim = kwargs.pop("ylim", (0,1))
plot_thresholds = kwargs.pop("plot_thresholds", False)
threshold_log = kwargs.pop("threshold_log", True)
if kwargs: if kwargs:
raise KeyError("Unknown kwargs: {}".format(kwargs)) raise KeyError("Unknown kwargs: {}".format(kwargs))
logger.info("Overlay ROC curves for {}".format([p.name for p in projects])) logger.info("Overlay ROC curves for {}".format([p.name for p in projects]))
for p in projects: fig, ax = plt.subplots()
if plot_thresholds:
ax2 = ax.twinx()
ax2.set_ylabel("Thresholds")
if threshold_log:
ax2.set_yscale("log")
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
for p, color in zip(projects, colors):
fpr, tpr, threshold = roc_curve(p.y_test, p.scores_test, sample_weight = p.w_test) fpr, tpr, threshold = roc_curve(p.y_test, p.scores_test, sample_weight = p.w_test)
fpr = 1.0 - fpr fpr = 1.0 - fpr
roc_auc = auc(tpr, fpr) roc_auc = auc(tpr, fpr)
plt.grid(color='gray', linestyle='--', linewidth=1) ax.grid(color='gray', linestyle='--', linewidth=1)
plt.plot(tpr, fpr, label=str(p.name+" (AUC = {})".format(roc_auc))) ax.plot(tpr, fpr, label=str(p.name+" (AUC = {:.3f})".format(roc_auc)), color=color)
if plot_thresholds:
ax2.plot(tpr, threshold, "--", color=color)
if xlim is not None: if xlim is not None:
plt.xlim(*xlim) ax.set_xlim(*xlim)
if ylim is not None: if ylim is not None:
plt.ylim(*ylim) ax.set_ylim(*ylim)
# plt.xticks(np.arange(0,1,0.1)) # plt.xticks(np.arange(0,1,0.1))
# plt.yticks(np.arange(0,1,0.1)) # plt.yticks(np.arange(0,1,0.1))
plt.legend(loc='lower left', framealpha=1.0) ax.legend(loc='lower left', framealpha=1.0)
plt.title('Receiver operating characteristic') ax.set_title('Receiver operating characteristic')
plt.ylabel("Background rejection") ax.set_ylabel("Background rejection")
plt.xlabel("Signal efficiency") ax.set_xlabel("Signal efficiency")
plt.savefig(filename) if plot_thresholds:
plt.clf() # to fit right y-axis description
fig.tight_layout()
fig.savefig(filename)
plt.close(fig)
def overlay_loss(filename, *projects, **kwargs): def overlay_loss(filename, *projects, **kwargs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment