Answers.Body: <p>The comments already are giving you some good tips about how to improve what your model recognizes, but I think your question goes above that asking if there's a way to <em>ensure</em> that it will always recognize the cats.</p>
  
  <p>The short answer is "no".</p>
  
  <p>The slightly longer answer is "yes, but cheating".</p>
  
  <p>Regardless, there are a lot of steps you might take to improve the generalization aspect of your model.</p>
  
  <hr>
  
  <p>Long answer:</p>
  
  <h2>A drama: cat classification in three acts</h2>
  
  <h3>Act I: Cat as texts</h3>
  
  <p>Let's start with an example. Say that your model is trained with these inputs, and learns to correctly recognize them as a cat or not a cat:</p>
  
  <pre><code>cat → yes!
  Cat → yes!
  ferret → no
  cat. → yes!
  Cat! → yes!
  Three MC's and one DJ → no
  </code></pre>
  
  <p>Your goal is to train your model so that every new variation, even unseen ones, will correctly be identified.</p>
  
  <p>With a good level of generalization, your model will correctly classify new inputs that it has never seen before:</p>
  
  <pre><code>skunk → no
  cat? → yes!
  dog → no
  CAT → yes
  </code></pre>
  
  <p>With this scenario, let's say the model now finds this:</p>
  
  <pre><code>kat → ?
  </code></pre>
  
  <p>Is that a "cat" misspelled? Is that short for Katherine? What should the model do?</p>
  
  <h3>Act II: But surely this doesn't happen in real life</h3>
  
  <p>Leaving the analogy for a bit, will your model that's looking at domestic cats properly accommodate for <a href="https://i.ytimg.com/vi/p1JxifyK-Ts/maxresdefault.jpg" rel="nofollow noreferrer">Savannah Cats</a>, or will it consider them out? (They kind of look like cheetahs.) What about <a href="https://www.prestigeanimalhospital.com/services/cats/breeds/sphynx" rel="nofollow noreferrer">Sphinx cats</a>? (They look like raw chicken to me.) <a href="https://blog.homesalive.ca/14-weird-but-cool-cat-breeds" rel="nofollow noreferrer">Elf cats</a>? (They look like bats.) This is just an example, but you can probably figure out more.</p>
  
  <p>And the reason behind this problem is that the distinction itself between different classifications (in real life) is not binary, but rather a transition between "yes, that's a textbook cat" and "that's a chair". Your model will output binary decisions (maybe accompanied by a confidence interval, but even with it, you'll make the call into deciding if it's a cat or not).</p>
  
  <p>Setting specific boundaries will help. You can define that your model will only detect domestic cats, maybe no bigger than a certain size, only of certain colors, etc... This is limiting what the model will correctly recognize as a cat when we (humans) might disagree. For instance, I would still argue that <a href="https://www.bbc.com/news/science-environment-14882008" rel="nofollow noreferrer">flourescent cats</a> are still cats.</p>
  
  <p>Going back to the simple text analogy, this is similar to deciding that to be detected as a cat, it has to start with a "c". So now you've discarded <code>¡Cat!</code>.</p>
  
  <p><em>In this way, it's not possible to <strong>ensure</strong> (notice the word) that your model will detect all of these unknown variations.</em> There will be always some room for error that needs to be accepted, as long as the errors are infrequent or rare enough that they can be accepted as a regular part of the model.</p>
  
  <h3>Act III: <a href="https://en.wikipedia.org/wiki/Concept_drift" rel="nofollow noreferrer">Concept drift</a>, a cautionary tale</h3>
  
  <p>Finally, the problem becomes even harder as we might be dealing with concepts that change over time, outside of the knowledge of the model, and outside of the knowledge of the person that supervised the model learning.</p>
  
  <p>As and the breeds of cat changes, your model will have to accommodate by what we (users of the model) consider a valid definition of cat. Which might change in really unexpected ways and not really "look" like a cat. And since your model can only learn from what "looks" like a cat, it's always held in a disadvantaged position.</p>
  
  <p>This will happen with almost any machine learning model that is approximating a result, regardless of the technique/algorithm. Approximations include a level of error because reality is usually complex in ways that we either don't know about or that are too computationally expensive.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-27T13:08:08.440Z
Answers.Text: @mdurrant I'm glad! In your particular case, I would suggest just setting up acceptable boundaries and moving forward. Yes, the model might not be future-proof of 100% accurate... but it still might be useful!
Answers.UserDisplayName: Alpha
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-26T22:16:00.810Z
Answers.Text: I think that explaining by example is usually easier to grasp, so I thought it would make a better answer. However, being an example it doesn't really tackle the underlying issues with model errors in detail, leaving it incomplete. If readers want to expand on it, please, feel free to do so.
Answers.UserDisplayName: Alpha
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-27T00:16:17.573Z
Answers.Text: Thank you for this answer! Definitely got me thinking, much appreciated.
Answers.UserDisplayName: mdurrant
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-26T22:14:48.853Z
Answers.LastActivityDate: 2020-02-26T22:14:48.853Z
Answers.UserDisplayName: Alpha
Body: <p>My question is more theoretical than practical. Let's say that I am training my cat classifier with a dataset that I feel is pretty representative of cat images in general. But then a new breed of cat is created that is distinct from other cats and it does not exist in my dataset.</p>
  <p>My question is: is there a way to ensure that my model is still able to recognize this unseen breed, even though I didn't know it would come into existence when I originally trained my model?</p>
  <p>I have been trying to answer this question by intentionally designing my validation and test sets such that they contain examples that are quite distantly related to those that exist in the training set (think of it like intentionally leaving out specific breeds of cats from the training set).</p>
  <p>The results are interesting. For example, slight changes to parameters can dramatically change performance on the distantly related test examples, while not changing performance very much for the more closely related examples. I was wondering if anyone has done a deeper analysis of this phenomenon.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-25T18:01:19.653Z
Comments.Text: I am tempted to conclude that the best way to ensure that the network still performs well on unseen examples is to regularize it as much as possible (Dropout rate of 0.5 at every layer, for example). Do you think this intuition is correct?
Comments.UserDisplayName: mdurrant
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-25T18:32:03.777Z
Comments.Text: Dropout is just one way of introducing a regularization effect. There are others. Dropout should help to avoid overfitting and thus the network shouldn't memorize the training dataset (i.e. approximate the function that the training set represents), but, instead, approximate a different function (not the one represented by the training set). Clearly, this should help to predict something that isn't in the training set, but this will not ensure that a specific unseen example will be predicted correctly.
Comments.UserDisplayName: nbro
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-25T21:28:01.903Z
Comments.Text: So assume the typical train-dev-test paradigm, where all three sets have unique examples but are drawn from the same distribution. With a neural network, you can easily overfit to those particular examples that exist in the training set if you don't regularize the parameters. Regularization allows the model to learn a more generalizable function. But if an unseen example that is not well represented in the train, dev, or test sets is introduced, how can we ensure that the model will be more likely to generalize to this distantly related, new example?
Comments.UserDisplayName: mdurrant
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-25T21:29:53.517Z
Comments.Text: Would regularizing the model even more than seemed necessary given your available dataset help you to generalize to these more dissimilar, unseen examples?
Comments.UserDisplayName: mdurrant
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-25T21:38:07.637Z
Comments.Text: The term _regularization_ is often used ambiguously. For example, in L1 or L2 regularization, the goal is to constrain the parameters to lie in a certain range. In other cases, for example, in the case of dropout, the idea is that you attempt to decorrelate the units of the network (by randomly dropping or killing them during training). In the case of Bayesian neural networks, the regularisation is said to be integrated into the networks because they are based on Bayes rule, so, in a certain way, the uncertainty associated with the learned distributions depends on the available data.
Comments.UserDisplayName: nbro
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-25T21:40:14.060Z
Comments.Text: To answer your question directly, regularization may help, but it may depend on the regularization that you use.
Comments.UserDisplayName: nbro
Tags: <neural-networks><machine-learning><overfitting><regularization><generalization>
Title: Is there a way to ensure that my model is able to recognize an unseen example?
UserDisplayName: mdurrant
ThreadText: # Is there a way to ensure that my model is able to recognize an unseen example?
  
  (Asked by: username_0 on 2020-02-24)
  
  My question is more theoretical than practical. Let's say that I am training my cat classifier with a dataset that I feel is pretty representative of cat images in general. But then a new breed of cat is created that is distinct from other cats and it does not exist in my dataset.
  
  My question is: is there a way to ensure that my model is still able to recognize this unseen breed, even though I didn't know it would come into existence when I originally trained my model?
  
  I have been trying to answer this question by intentionally designing my validation and test sets such that they contain examples that are quite distantly related to those that exist in the training set (think of it like intentionally leaving out specific breeds of cats from the training set).
  
  The results are interesting. For example, slight changes to parameters can dramatically change performance on the distantly related test examples, while not changing performance very much for the more closely related examples. I was wondering if anyone has done a deeper analysis of this phenomenon.
  
  **Tags:** neural-networks, machine-learning, overfitting, regularization, generalization
  > **Comments:**
  > **username_0**: I am tempted to conclude that the best way to ensure that the network still performs well on unseen examples is to regularize it as much as possible (Dropout rate of 0.5 at every layer, for example). Do you think this intuition is correct?  
  > **username_1**: Dropout is just one way of introducing a regularization effect. There are others. Dropout should help to avoid overfitting and thus the network shouldn't memorize the training dataset (i.e. approximate the function that the training set represents), but, instead, approximate a different function (not the one represented by the training set). Clearly, this should help to predict something that isn't in the training set, but this will not ensure that a specific unseen example will be predicted correctly.  
  > **username_0**: So assume the typical train-dev-test paradigm, where all three sets have unique examples but are drawn from the same distribution. With a neural network, you can easily overfit to those particular examples that exist in the training set if you don't regularize the parameters. Regularization allows the model to learn a more generalizable function. But if an unseen example that is not well represented in the train, dev, or test sets is introduced, how can we ensure that the model will be more likely to generalize to this distantly related, new example?  
  > **username_0**: Would regularizing the model even more than seemed necessary given your available dataset help you to generalize to these more dissimilar, unseen examples?  
  > **username_1**: The term _regularization_ is often used ambiguously. For example, in L1 or L2 regularization, the goal is to constrain the parameters to lie in a certain range. In other cases, for example, in the case of dropout, the idea is that you attempt to decorrelate the units of the network (by randomly dropping or killing them during training). In the case of Bayesian neural networks, the regularisation is said to be integrated into the networks because they are based on Bayes rule, so, in a certain way, the uncertainty associated with the learned distributions depends on the available data.  
  > **username_1**: To answer your question directly, regularization may help, but it may depend on the regularization that you use.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-02-26. Score: 1
  
  The comments already are giving you some good tips about how to improve what your model recognizes, but I think your question goes above that asking if there's a way to ensure that it will always recognize the cats.
  The short answer is "no".
  The slightly longer answer is "yes, but cheating".
  Regardless, there are a lot of steps you might take to improve the generalization aspect of your model.
  
  Long answer:
  A drama: cat classification in three acts
  Act I: Cat as texts
  Let's start with an example. Say that your model is trained with these inputs, and learns to correctly recognize them as a cat or not a cat:
  cat → yes!
  Cat → yes!
  ferret → no
  cat. → yes!
  Cat! → yes!
  Three MC's and one DJ → no
  
  Your goal is to train your model so that every new variation, even unseen ones, will correctly be identified.
  With a good level of generalization, your model will correctly classify new inputs that it has never seen before:
  skunk → no
  cat? → yes!
  dog → no
  CAT → yes
  
  With this scenario, let's say the model now finds this:
  kat → ?
  
  Is that a "cat" misspelled? Is that short for Katherine? What should the model do?
  Act II: But surely this doesn't happen in real life
  Leaving the analogy for a bit, will your model that's looking at domestic cats properly accommodate for Savannah Cats, or will it consider them out? (They kind of look like cheetahs.) What about Sphinx cats? (They look like raw chicken to me.) Elf cats? (They look like bats.) This is just an example, but you can probably figure out more.
  And the reason behind this problem is that the distinction itself between different classifications (in real life) is not binary, but rather a transition between "yes, that's a textbook cat" and "that's a chair". Your model will output binary decisions (maybe accompanied by a confidence interval, but even with it, you'll make the call into deciding if it's a cat or not).
  Setting specific boundaries will help. You can define that your model will only detect domestic cats, maybe no bigger than a certain size, only of certain colors, etc... This is limiting what the model will correctly recognize as a cat when we (humans) might disagree. For instance, I would still argue that flourescent cats are still cats.
  Going back to the simple text analogy, this is similar to deciding that to be detected as a cat, it has to start with a "c". So now you've discarded ¡Cat!.
  In this way, it's not possible to ensure (notice the word) that your model will detect all of these unknown variations. There will be always some room for error that needs to be accepted, as long as the errors are infrequent or rare enough that they can be accepted as a regular part of the model.
  Act III: Concept drift, a cautionary tale
  Finally, the problem becomes even harder as we might be dealing with concepts that change over time, outside of the knowledge of the model, and outside of the knowledge of the person that supervised the model learning.
  As and the breeds of cat changes, your model will have to accommodate by what we (users of the model) consider a valid definition of cat. Which might change in really unexpected ways and not really "look" like a cat. And since your model can only learn from what "looks" like a cat, it's always held in a disadvantaged position.
  This will happen with almost any machine learning model that is approximating a result, regardless of the technique/algorithm. Approximations include a level of error because reality is usually complex in ways that we either don't know about or that are too computationally expensive.
  
  > **Comments:**
  > **username_2**: I think that explaining by example is usually easier to grasp, so I thought it would make a better answer. However, being an example it doesn't really tackle the underlying issues with model errors in detail, leaving it incomplete. If readers want to expand on it, please, feel free to do so.  
  > **username_0**: Thank you for this answer! Definitely got me thinking, much appreciated.  
  > **username_2**: @mdurrant I'm glad! In your particular case, I would suggest just setting up acceptable boundaries and moving forward. Yes, the model might not be future-proof of 100% accurate... but it still might be useful!  
  
  ---
  
  