Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loss function for OneVsRestClassifier

I have a OneVsRestClassifier (scikit-learn) which has been trained.

clf = OneVsRestClassifier(LogisticRegression(C=1.2, penalty='l1')).fit(X_train, y_train)

I want to find out the loss for my test data. I used log_loss function but it does not seem to work because I have multiple classes as outputs for each test case. What do I do?

like image 594
Hima Varsha Avatar asked Aug 11 '26 05:08

Hima Varsha


1 Answers

The classification problem that you are referring to is known as a Multi-Label Classification problem. You have made a good decision of using the OneVsRestClassifier for this purpose. By default the score method uses the subset accuracy which is a very harsh metric as it requires you to guess the entire subset of labels correctly.

Some other loss functions, provided by scikit-learn, that you can use are as follows:

  1. Hamming Loss - This measures the hamming distance between your prediction of labels and the true label. This is an intuitive formula to understand the hamming distance.
  2. Jaccard Similarity Coefficient Score - This measures the Jaccard similarity between your predicted labels and the true labels.
  3. Precision, Recall and F-Measures - In the case of multi-label classification, the notion of Precision, Recall and F-Measures can be applied to each class independently. The following guide explains how to combine them across all labels in multi-label classification.

If you need to also rank the labels as it is done in multi-label ranking problems, then there are other more advanced techniques available in scikit-learn which are very well documented with examples here. If you are dealing with this kind of a problem, then let me know in the comments, I will explain each of these metrics in more details.

Hope this helps!

like image 102
Abhinav Arora Avatar answered Aug 13 '26 04:08

Abhinav Arora