Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does tf.keras.metrics.AUC work on multi-class problems?

I have a multi-class classification problem and I want to measure AUC on training and test data.

tf.keras has implemented AUC metric (tf.keras.metrics.AUC), but I'm not be able to see whether this metric could safely be used in multi-class problems. Even, the example "Classification on imbalanced data" on the official Web page is dedicated to a binary classification problem.

I have implemented a CNN model that predicts six classes, having a softmax layer that gives the probabilities of all the classes. I used this metric as follows

self.model.compile(loss='categorical_crossentropy',
                       optimizer=Adam(hp.get("learning_rate")),
                       metrics=['accuracy', AUC()]),

and the code was executed without any problem. However, sometimes I see some results that are quite strange for me. For example, the model reported an accuracy of 0.78333336 and AUC equal to 0.97327775, Is this possible? Can a model have a low accuracy and an AUC so high?

I wonder that, although the code does not give any error, the AUC metric is computing wrong.

Somebody may confirm me whether or not this metrics support multi-class classification problems?

like image 525
Oscar Gabriel Reyes Pupo Avatar asked Oct 30 '19 17:10

Oscar Gabriel Reyes Pupo


People also ask

What is the best performance metric for multiclass classification?

Most commonly used metrics for multi-classes are F1 score, Average Accuracy, Log-loss.

What are the different performance metrics that can be used for multiclass classification problems?

So, this post will be about the 7 most commonly used MC metrics: precision, recall, F1 score, ROC AUC score, Cohen Kappa score, Matthew's correlation coefficient, and log loss. You will learn how they are calculated, their nuances in Sklearn and how to use them in your own workflow.

Does Keras use metric functions for anything other than reporting?

In addition to offering standard metrics for classification and regression problems, Keras also allows you to define and report on your own custom metrics when training deep learning models.


2 Answers

There is the argument multi_label which is a boolean inside your tf.keras.metrics.AUC call.

If True (not the default), multi-label data will be treated as such, and so AUC is computed separately for each label and then averaged across labels.

When False (the default), the data will be flattened into a single label before AUC computation. In the latter case, when multi-label data is passed to AUC, each label-prediction pair is treated as an individual data point.

The documentation recommends to set it to False for multi-class data.

e.g.: tf.keras.metrics.AUC(multi_label = True)

See the AUC Documentation for more details.

like image 177
PMC1234 Avatar answered Oct 20 '22 05:10

PMC1234


AUC can have a higher score than accuracy. Additionally, you can use AUC to decide the cutoff threshold for a binary classifier(this cutoff is by default 0.5). Though there are more technical ways to decide this cutoff, you could simply simply increase it from 0 to 1 to find the value which maximizes your accuracy(this is a naive solution and 1 recommend you to read this https://ncss-wpengine.netdna-ssl.com/wp-content/themes/ncss/pdf/Procedures/NCSS/One_ROC_Curve_and_Cutoff_Analysis.pdf for an in depth explanation on cutoff analysis )

like image 1
Yasas Wijesekara Avatar answered Oct 20 '22 06:10

Yasas Wijesekara