33 lines
983 B
Python
33 lines
983 B
Python
import matplotlib.pyplot as plt
|
|
from sklearn.metrics import roc_curve, auc
|
|
|
|
|
|
class ROCEvaluation(object):
|
|
|
|
linewidth = 2
|
|
|
|
def __init__(self, prepare_figure=False):
|
|
self.prepare_figure = prepare_figure
|
|
self.epoch = 0
|
|
|
|
def __call__(self, prediction, label, plotting=False):
|
|
|
|
# Compute ROC curve and ROC area
|
|
fpr, tpr, _ = roc_curve(prediction, label)
|
|
roc_auc = auc(fpr, tpr)
|
|
if plotting:
|
|
fig = plt.gcf()
|
|
fig.plot(fpr, tpr, color='darkorange', lw=self.linewidth, label=f'ROC curve (area = {roc_auc})')
|
|
return roc_auc, fpr, tpr
|
|
|
|
def _prepare_fig(self):
|
|
fig = plt.gcf()
|
|
fig.plot([0, 1], [0, 1], color='navy', lw=self.linewidth, linestyle='--')
|
|
fig.xlim([0.0, 1.0])
|
|
fig.ylim([0.0, 1.05])
|
|
fig.xlabel('False Positive Rate')
|
|
fig.ylabel('True Positive Rate')
|
|
fig.legend(loc="lower right")
|
|
|
|
return fig
|