title: How To Calculate F1-Score For Multilabel Classification?
body: <p>I try to calculate the <code>f1_score</code> but I get some warnings for some cases when I use the sklearn <code>f1_score</code> method.</p>
  
  <p>I have a multilabel 5 classes problem for a prediction.</p>
  
  <pre><code>import numpy as np
  from sklearn.metrics import f1_score
  
  y_true = np.zeros((1,5))
  y_true[0,0] = 1 # =&gt; label = [[1, 0, 0, 0, 0]]
  
  y_pred = np.zeros((1,5))
  y_pred[:] = 1 # =&gt; prediction = [[1, 1, 1, 1, 1]]
  
  result_1 = f1_score(y_true=y_true, y_pred=y_pred, labels=None, average="weighted")
  
  print(result_1) # prints 1.0
  
  result_2 = f1_score(y_true=y_ture, y_pred=y_pred, labels=None, average="weighted")
  
  print(result_2) # prints: (1.0, 1.0, 1.0, None) for precision/recall/fbeta_score/support
  </code></pre>
  
  <p>When I use <code>average="samples"</code> instead of <code>"weighted"</code> I get (0.1, 1.0, 0.1818..., None). Is the <code>"weighted"</code> option not useful for a multilabel problem or how do I use the <code>f1_score</code> method correctly?</p>
  
  <p>I also get a warning when using <code>average="weighted"</code>:</p>
  
  <blockquote>
    <p>"UndefinedMetricWarning: Recall and F-score are ill-defined and being set to 0.0 in labels with no true samples."</p>
  </blockquote>