4
$\begingroup$

I'm training a MLP classifier with a softmax output that outputs 4 classes.

For my particular application I'd like the classifier to output a fifth 'other' class when the input don't belong to any of the 4 classes.

I've seen several discussions on the topic here and elsewhere, but couldn't get to a final solution.

I can think of two main approaches

  1. Add examples outside of the four classes to the training data. I can get realistic examples of these (which I believe is better than just feeding random noise, which I will never see in a real situation)

  2. Perform per-class thresholding on the softmax output. If none of the classes reaches threshold them output 'other', otherwise output the class with highest score.

Approach 1 is easier, but to work well I would need to cover the vast majority of 'other'cases my classifier might encounter, and I can't be sure of that. Also, the 'other' class will be much more heterogeneous and probably much more difficult to learn.

I've seen examples of approach 2 for binary classification, where the 'best' threshold is chosen by building an ROC curve or by looking at some metric of choice. My understanding is that to extend this to multiple classes I should transform my problem into several binary classifications where I look at class 1 Vs the rest, then class 2 vs the rest and so on. I can then find a threshold for each class.

So my questions:

Are these viable approaches, and which is better? Or, is there any better solution?

Do you have recommendations for choosing a metric to establish the best threshold?

If someone could provide links to relevant literature that would be fantastic

$\endgroup$
4
  • 1
    $\begingroup$ Maybe helpful for you? ai.stackexchange.com/q/4889 $\endgroup$ Sep 16, 2022 at 14:55
  • 1
    $\begingroup$ @CamilleGontier Thanks, I did not see that. The two answers actually are essentially the two options I am describing... so well at least I am not completely wrong! $\endgroup$
    – nico
    Sep 16, 2022 at 15:06
  • $\begingroup$ More generally, how to handle unseen classes is an important field of research in theoretical machine learning, see for instance en.wikipedia.org/wiki/Zero-shot_learning $\endgroup$ Sep 16, 2022 at 15:11
  • $\begingroup$ Yes, although I don't necessarily care about what "other" is, as long as it is not classified as one of the classes, if that makes sense $\endgroup$
    – nico
    Sep 16, 2022 at 15:26

2 Answers 2

2
$\begingroup$

This is an important and surprisingly difficult question. Two of the reasons why it's hard:

  1. One way that classifiers work is by constructing directions in feature space that separate the classes you are interested in. If you train it on dogs and horses, it might learn that horses are (a) bigger and (b) tend to be less hairy. Along that direction in feature space you find buses. A bus is even bigger and less hairy than a horse, so it is super-horse-like and your classifier will be extremely confident that it's a horse.

  2. Another way that classifiers work is by taking the test data and finding 'nearby' points in the training set. You might say that a test point should be classified as 'other' if there are no nearby points. This works when you have low-dimensional data. For high-dimensional data, though, there are no points that are 'nearby' on all variables. If you have a 'nearby' decision rule, it has to work by ignoring/downweighting many of the variables, so a new test point can appear 'nearby' even if it's very different on those ignored/downweighted variables.

As further evidence that it's a hard problem, people overgeneralise learned decision rules. They don't mistake a skyscraper for a dog, but they do (for example) learn the features that distinguish edible and inedible mushrooms in their home region and then move somewhere else and tragically fail to recognise that the distinguishing features are different in their new home.

$\endgroup$
1
$\begingroup$

My understanding of this question is that you have a model that distinguishes between pictures of dogs, alligators, and magpies, and you want it to come back and tell you, “I dunno,” when you feed it a picture of the Empire State Building.

I see two options.

  1. Use the continuous outputs of your multi-class model. If you show a picture of a skyscraper to the animal classifier, I would hope for it to give approximately equal probabilities of each category.

  2. Train a multi-label model that can give low probabilities of all categories. If you feed a picture of a skyscraper to the animal classifier, I would hope that it would give low probabilities for every animal.

Both of these would, at least roughly, correspond to your second idea. As far as determining the threshold at which you would classify as “other” instead of one of your categories, that depends on the cost of misclassification.

The trouble with the first idea is that there is basically no limit to what would constitute the “other” category. A skyscraper is not one of those three animals, but neither is a Corvette. Do you then train the model on an “other” category that contains both skyscrapers and cars? Then what about motorcycles, airplanes, or birthday cakes? By calling all of these the same category, you are telling the model that these are the same, yet they are not.

$\endgroup$
1
  • $\begingroup$ Excellent point about putting together all of the "other" classes in the same bin. In my particular case as I will not do anything else with those points. However, I can see how this could be an issue in other situations. $\endgroup$
    – nico
    Apr 3, 2023 at 11:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.