title: Scikit F-score metric error
body: <p>I am trying to predict a set of labels using <a href="http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html#sklearn-linear-model-logisticregressioncv">Logistic Regression from SciKit.</a> My data is really imbalanced (there are many more '0' than '1' labels) so I have to use the <a href="https://en.wikipedia.org/wiki/F1_score">F1 score metric</a> during the cross-validation step to "balance" the result.</p>
  
  <pre><code>[Input]
  X_training, y_training, X_test, y_test = generate_datasets(df_X, df_y, 0.6)
  logistic = LogisticRegressionCV(
      Cs=50,
      cv=4,
      penalty='l2', 
      fit_intercept=True,
      scoring='f1'
  )
  logistic.fit(X_training, y_training)
  print('Predicted: %s' % str(logistic.predict(X_test)))
  print('F1-score: %f'% f1_score(y_test, logistic.predict(X_test)))
  print('Accuracy score: %f'% logistic.score(X_test, y_test))
  
  [Output]
  &gt;&gt; Predicted: [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]
  &gt;&gt; Actual:    [0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 1 1]
  &gt;&gt; F1-score: 0.285714
  &gt;&gt; Accuracy score: 0.782609
  &gt;&gt; C:\Anaconda3\lib\site-packages\sklearn\metrics\classification.py:958:  
     UndefinedMetricWarning:
     F-score is ill-defined and being set to 0.0 due to no predicted samples.
  </code></pre>
  
  <p>I certainly know that the problem is related to my dataset: it is too small (it is only a sample of the real one). However, can anybody explain the meaning of the "UndefinedMetricWarning" warning that I am seeing? What is actually happening behind the curtains?</p>