title: How to choose a suitable decision threshold in the inference of a model?
body: <p>I am carrying out an speaker recognition project, I have the model already trained and its precision is 90%, but I have a problem when I make inference, the model gives two probabilities, since it was trained for two interlocutors, but I want that when I detect an speaker who was not in the training set, tell me that he is an &quot;unknown speaker&quot;, therefore, how can I choose the decision threshold according to the two probabilities that the model gives me?</p>
  <p>This is a snippet of the code in question:</p>
  <pre><code>sample_df = pd.DataFrame(list_).transpose()
  sample_pred =  model.predict(sample_df)[0] # Here the model returns the name of the 
                                             # predicted speaker
  
  sample_prob = model.predict_proba(sample_df)[0] # Here I get a list of two items, the 
                                                  # probabilities for each speaker 
  print(sample_prob) # Output example: [0.46 0.54]
  
  for k,j in enumerate(sample_prob):
      if j &lt;= 0.6 and sample_prob[k+1] &lt;= 0.6: # How to change dynamically according to the 
                                               # result of sample_prob, this threshold ?, 
                                               # for example I put 0.6.
          sample_pred= &quot;unknown speaker&quot;
          break
      else:
          break
  </code></pre>