How to add ROC AUC as a metric in tensorflow/keras

The way to add the ROC AUC as a metric on your tensorflow/keras project is to copy this function that computes the ROC AUC and use the function name in the model.

To use the function in the model. We first need to compile with the function (not a string) as shown next

model.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics=['acc',auc_roc])

and after to use it in the callbacks we need to refer it by the function name (a string with the “”) as shown in the model checkpoint example

checkpoint = ModelCheckpoint(weights_path, monitor="auc_roc", verbose=1, save_best_only=True, mode='max', save_weights_only = True)

That’s pretty much all. Other customized functions follow the same pattern.

Leave a comment

Your email address will not be published. Required fields are marked *