title: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples
body: <p>I'm getting this weird error:</p>
  
  <pre><code>classification.py:1113: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
  'precision', 'predicted', average, warn_for)`
  </code></pre>
  
  <p>but then it also prints the f-score the first time I run: </p>
  
  <pre><code>metrics.f1_score(y_test, y_pred, average='weighted')
  </code></pre>
  
  <p>The second time I run, it provides the score without error. Why is that?</p>
  
  <pre><code>&gt;&gt;&gt; y_pred = test.predict(X_test)
  &gt;&gt;&gt; y_test
  array([ 1, 10, 35,  9,  7, 29, 26,  3,  8, 23, 39, 11, 20,  2,  5, 23, 28,
         30, 32, 18,  5, 34,  4, 25, 12, 24, 13, 21, 38, 19, 33, 33, 16, 20,
         18, 27, 39, 20, 37, 17, 31, 29, 36,  7,  6, 24, 37, 22, 30,  0, 22,
         11, 35, 30, 31, 14, 32, 21, 34, 38,  5, 11, 10,  6,  1, 14, 12, 36,
         25,  8, 30,  3, 12,  7,  4, 10, 15, 12, 34, 25, 26, 29, 14, 37, 23,
         12, 19, 19,  3,  2, 31, 30, 11,  2, 24, 19, 27, 22, 13,  6, 18, 20,
          6, 34, 33,  2, 37, 17, 30, 24,  2, 36,  9, 36, 19, 33, 35,  0,  4,
          1])
  &gt;&gt;&gt; y_pred
  array([ 1, 10, 35,  7,  7, 29, 26,  3,  8, 23, 39, 11, 20,  4,  5, 23, 28,
         30, 32, 18,  5, 39,  4, 25,  0, 24, 13, 21, 38, 19, 33, 33, 16, 20,
         18, 27, 39, 20, 37, 17, 31, 29, 36,  7,  6, 24, 37, 22, 30,  0, 22,
         11, 35, 30, 31, 14, 32, 21, 34, 38,  5, 11, 10,  6,  1, 14, 30, 36,
         25,  8, 30,  3, 12,  7,  4, 10, 15, 12,  4, 22, 26, 29, 14, 37, 23,
         12, 19, 19,  3, 25, 31, 30, 11, 25, 24, 19, 27, 22, 13,  6, 18, 20,
          6, 39, 33,  9, 37, 17, 30, 24,  9, 36, 39, 36, 19, 33, 35,  0,  4,
          1])
  &gt;&gt;&gt; metrics.f1_score(y_test, y_pred, average='weighted')
  C:\Users\Michael\Miniconda3\envs\snowflakes\lib\site-packages\sklearn\metrics\classification.py:1113: UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 in labels with no predicted samples.
    'precision', 'predicted', average, warn_for)
  0.87282051282051276
  &gt;&gt;&gt; metrics.f1_score(y_test, y_pred, average='weighted')
  0.87282051282051276
  &gt;&gt;&gt; metrics.f1_score(y_test, y_pred, average='weighted')
  0.87282051282051276
  </code></pre>
  
  <p>Also, why is there a trailing <code>'precision', 'predicted', average, warn_for)</code> error message? There is no open parenthesis so why does it end with a closing parenthesis? I am running sklearn 0.18.1 using Python 3.6.0 in a conda environment on Windows 10.</p>
  
  <p>I also looked at <a href="https://stackoverflow.com/questions/31677218/scikit-f-score-metric-error">here</a> and I don't know if it's the same bug. This <a href="https://stackoverflow.com/questions/35225369/scikit-learn-error-message-precision-and-f-score-are-ill-defined-and-being-set">SO post</a> doesn't have solution either.</p>