Answers.Body: <p>The best approach may be to have a cat, dog, and neither class (3 classes total) and go with a regression approach — specifically, outputting the probabilities of each class for any given input. From there, you can always take the probabilities of each output and derive the probability of a cat and dog class or neither class. Also, make sure you use the right activation on the output layer and cost function so that you can interpret the outputs as probabilities (e.g. softmax activation and cross-entropy loss).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-25T19:46:52.483Z
Answers.Text: This answer does not explain why your suggestion is the best approach. You should [edit your post](https://ai.stackexchange.com/posts/5813/edit) to explain why that's the case.
Answers.UserDisplayName: nbro
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-09-26T06:50:03.977Z
Answers.Text: @nbro This was over 2 years ago and the answer has been accepted. It’s certainly not perfect, but unless a specific clarification is asked I don’t intend to revisit it.
Answers.UserDisplayName: Greenstick
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-03-27T18:49:02.383Z
Answers.LastActivityDate: 2020-09-26T06:52:24.870Z
Answers.LastEditDate: 2020-09-26T06:52:24.870Z
Answers.UserDisplayName: Greenstick
Answers.Body: <p>If you want to determine if something is either a</p>
  <blockquote>
  <p>cat/dog or neither</p>
  </blockquote>
  <p>you need 2 classes:</p>
  <ol>
  <li>one for dog or cat, and</li>
  <li>one for anything else.</li>
  </ol>
  <p>However, if you assign all cats and dogs to the same class <span class="math-container">$A$</span>, if an input is classified as <span class="math-container">$A$</span>, then you won't be able to know whether it is a dog or a cat, you will just know that it is <em>either</em> a dog or a cat.</p>
  <p>In case you wanted to distinguish between cats and dogs too (apart from <em>neither</em> of them), then you'll need <span class="math-container">$3$</span> classes.</p>
  <p>Finally, if you specify only 2 classes:</p>
  <ol>
  <li>dog, and</li>
  <li>cat,</li>
  </ol>
  <p>then your CNN will try to classify any new input as either a dog or a cat, even though it is neither a dog nor a cat (e.g. maybe it is a horse).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-26T18:05:08.823Z
Answers.Text: To put it more in more general terms, I basically try to determine if something was "A or B" or "neither A or B" (2 classes). There's no need to determine whether an input was A or B. I just thought if assigning both A-objects to the same class as B-objects (the "A or B" class), the CNN may "diffuse" the features of A and B.
Answers.UserDisplayName: John M.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-03-26T14:34:52.437Z
Answers.LastActivityDate: 2020-09-25T19:56:56.690Z
Answers.LastEditDate: 2020-09-25T19:56:56.690Z
Answers.UserDisplayName: nsaura
Answers.Body: <p>As far as generalization error is concerned, you are better off by learning the data distribution of (A and B) classes using unsupervised criterion.   </p>
  
  <p>If you capture the underlying factors that explain most of the variations belong to A and B classes, after that, fine-tune it using a supervised criterion. in this way if you used two classes one for (A or B) and the other for neither (A or B), you will not force the model to learn features don't belong to (A or B), because the model just checks if a new data point is probably likely drawn from the data distribution that resembles (A or B).</p>
  
  <p>Side note: you will never have the data necessary to explore the internal structure of the otherwise class (neither A nor B).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-06T05:20:52.640Z
Answers.LastActivityDate: 2018-05-06T05:20:52.640Z
Answers.UserDisplayName: Fadi Bakoura
Body: <p>Suppose one trains a CNN to determine if something was either a cat/dog or neither (2 classes), would it be a good idea to assign all cats and dogs to one class and everything else to another? Or would it be better to have a class for cats, a class for dogs, and a class for everything else (3 classes)? My colleague argues for 3 classes because dogs and cats have different features, but I wonder if he's right.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-09-25T19:48:52.140Z
Comments.Text: Normally you only have two classes along with a threshold probability. It's how systems like YOLO work.
Comments.UserDisplayName: FourierFlux
Tags: <neural-networks><convolutional-neural-networks><training><datasets><binary-classification>
Title: If we want to classify something as either a cat/dog or neither, do we need 2 or 3 classes?
UserDisplayName: John M.
ThreadText: # If we want to classify something as either a cat/dog or neither, do we need 2 or 3 classes?
  
  (Asked by: username_0 on 2018-03-26)
  
  Suppose one trains a CNN to determine if something was either a cat/dog or neither (2 classes), would it be a good idea to assign all cats and dogs to one class and everything else to another? Or would it be better to have a class for cats, a class for dogs, and a class for everything else (3 classes)? My colleague argues for 3 classes because dogs and cats have different features, but I wonder if he's right.
  
  **Tags:** neural-networks, convolutional-neural-networks, training, datasets, binary-classification
  
  > **Comments:**
  > **username_1**: Normally you only have two classes along with a threshold probability. It's how systems like YOLO work.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2018-03-27. Score: 1 | Accepted answer
  
  The best approach may be to have a cat, dog, and neither class (3 classes total) and go with a regression approach — specifically, outputting the probabilities of each class for any given input. From there, you can always take the probabilities of each output and derive the probability of a cat and dog class or neither class. Also, make sure you use the right activation on the output layer and cost function so that you can interpret the outputs as probabilities (e.g. softmax activation and cross-entropy loss).
  
  > **Comments:**
  > **username_3**: This answer does not explain why your suggestion is the best approach. You should [edit your post](https://ai.stackexchange.com/posts/5813/edit) to explain why that's the case.  
  > **username_2**: @username_3 This was over 2 years ago and the answer has been accepted. It’s certainly not perfect, but unless a specific clarification is asked I don’t intend to revisit it.  
  
  ---
  
  ### Answer by username_4 on 2018-03-26. Score: 2
  
  If you want to determine if something is either a
  
  > cat/dog or neither
  
  you need 2 classes:
  
  1. one for dog or cat, and
  2. one for anything else.
  
  However, if you assign all cats and dogs to the same class $A$, if an input is classified as $A$, then you won't be able to know whether it is a dog or a cat, you will just know that it is *either* a dog or a cat.
  
  In case you wanted to distinguish between cats and dogs too (apart from *neither* of them), then you'll need $3$ classes.
  
  Finally, if you specify only 2 classes:
  
  1. dog, and
  2. cat,
  
  then your CNN will try to classify any new input as either a dog or a cat, even though it is neither a dog nor a cat (e.g. maybe it is a horse).
  
  > **Comments:**
  > **username_0**: To put it more in more general terms, I basically try to determine if something was "A or B" or "neither A or B" (2 classes). There's no need to determine whether an input was A or B. I just thought if assigning both A-objects to the same class as B-objects (the "A or B" class), the CNN may "diffuse" the features of A and B.  
  
  ---
  
  ### Answer by username_5 on 2018-05-06. Score: 1
  
  As far as generalization error is concerned, you are better off by learning the data distribution of (A and B) classes using unsupervised criterion.
  
  If you capture the underlying factors that explain most of the variations belong to A and B classes, after that, fine-tune it using a supervised criterion. in this way if you used two classes one for (A or B) and the other for neither (A or B), you will not force the model to learn features don't belong to (A or B), because the model just checks if a new data point is probably likely drawn from the data distribution that resembles (A or B).
  
  Side note: you will never have the data necessary to explore the internal structure of the otherwise class (neither A nor B).
  
  
  ---
  
  