2
$\begingroup$

Suppose I train a multi-class classifier with K classes. However, in a practical application, an input can belong to none of the K classes. Thus, the K+1 class is introduced. The training data for this out-of-domain class is needed of course. The training of such classifier and usage is no different than the K-class classifier.

My question is: Why can't we get away with the original K binary classifiers including the case of out-of-domain input?

If an object belongs to one of of K classes, its score (or confidence) is 1.0 for the respective class. And it is zero for other K-1 classes. This is the case of highest certainty or lowest entropy.

If input belongs to none of the K classes, its score is 1/K for all K classes. This is the case of highest uncertainty or maximum entropy.

In a practical setting, I would compute entropy of the discrete distribution (scores/confidences must sum to one). If it is very close to uniform, the decision is "out-of-domain". If entropy is very low, then the classifier's prediction is the class for which the score is the highest (classical usage).

Is it possible to construct such classifier? If not, what are the reasons? A link to a publication would be great.

By extension, would that work for a multiple layer neural network? The last layer in the feed-forward neural network is essentially a linear classifier with a softmax at the end.

$\endgroup$

2 Answers 2

1
$\begingroup$

It seems like a reasonable thing to try, but I expect that it will fail in many scenarios.

The problem is the binary classifiers never see out-of-distribution samples during training time, so they might behave arbitrarily poorly on out-of-distribution samples. It's possible that an out-of-distribution sample might be (wrongly) accepted by one of your binary classifiers as belonging to one of the classes, even though it doesn't actually. There is nothing in training to prevent this.

Let me give you a concrete example. Suppose we have $K=2$ classes, and you have a training dataset that comes from the following distribution: each sample lies in a two-dimensional space $\mathbb{R}^2$; class 0 samples are distributed as $(X_0,10)$ where $X_0 \sim \mathcal{N}(5,1)$; and class 1 samples are distributed as $(X_1,10)$ where $X_1 \sim \mathcal{N}(-5,1)$. If we train a binary linear classifier for each class, the class 0 classifier is likely to accept samples $(x,y)$ where $x \ge 0$ as being in class 0; and the class 1 classifier is likely to accept samples $(x,y)$ where $x \le 0$ as being in class 0.

Now suppose that you receive an out-of-distribution sample, say $(5,-10)$. What is going to happen? The class 0 classifier will accept it as being a part of class 0; therefore, you will predict that this sample is "class 0". That is undesirable -- we wish it would recognize that this should be treated as "unknown". Unfortunately, your strategy is unable to recognize this sample as "unknown", because during training, the classifier was never trained on anything outside of the normal distribution, so there was no signal or pressure for the classifier to reject points from outside the in-distribution data.

In short, the issue with your scheme is, when we feed an out-of-distribution sample to a discriminative classifier trained only on in-distribution data, arbitrarily bad things can happen. The classifier is free to do whatever it wants on out-of-distribution data: there is nothing in the training process that forces it to do what you want in that region of the feature space.

$\endgroup$
3
  • $\begingroup$ I agree, but would like to add that depending on your problem, it might be reasonable to assume this works. If, for example, you use K one-vs-rest classifiers to achieve multi-class classification, then there is a pressure on each classifier to reject samples which are not similar to its class. Of course, the similarity is then measured in relation to the other K-1 classes, but if the "unknown" class is different from the K classes in the same way that the K classes differ among themselves it is reasonable to expect the one-vs-rest classifiers to still peform well. $\endgroup$
    – Erik
    Commented Mar 18, 2023 at 13:23
  • $\begingroup$ @Erik, there are no guarantees; the example I gave can be adapted to show that such a classifier also isn't guaranteed to work. In my opinion, it is not reasonable to assume that it works; you have to test it and see whether it actually works or not. It might work, or it might not, depending on the data you are working with. $\endgroup$
    – D.W.
    Commented Mar 18, 2023 at 20:57
  • $\begingroup$ Agreed, that's what I tried to convey with "depending on your problem" and the part about assuming how the unkown class differs. To assume anything about how out-of-distribution detection will work on unseen data will always require assumptions on the unseen data, either from testing or from domain knowledge, and I wanted to complement your answer with the domain knowledge perspective. $\endgroup$
    – Erik
    Commented Mar 19, 2023 at 21:38
0
$\begingroup$

It is worth pointing out that your problem of training a classifier to detect $k$ known classes and 1 "unknown" class can be split into a two-step problem. We would like a model to 1) classify a point as being "known" or "unknown" and 2) if "known", classify the point into one of $k$ classes.

Since you are apparently familiar with methods to classify things into $k$ classes, your problem has been reduced to classifying points as being "known" or "unknown". This is what is commonly called novelty detection or anomaly detection. For continuous input, a popular method is one-class SVM, which, in some sense, tries to find a "soft" convex hull for the training data. Other methods for anomaly detection abound in time-series and for other types of input.

$\endgroup$
2
  • $\begingroup$ "If input belongs to none of the K classes, its score is 1/K for all K classes." This almost never happens for real classifiers. In my experience neural networks are somehow 90% confident even when you feed them total rubbish. $\endgroup$
    – Him
    Commented Sep 4, 2019 at 3:30
  • 1
    $\begingroup$ The score of 1/K for unknown input is used during training. At the prediction stage, the distribution over K classes in practice will of course almost never be exactly uniform. I am wondering whether such classifier can be trained. If not, what are the clear reasons why it is not even worth setting up and running this experiment? $\endgroup$ Commented Sep 4, 2019 at 17:03

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.