Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Machine Learning by (19k points)

I run a python program that calls sklearn.metrics's methods to calculate precision and F1 score. Here is the output when there is no predicted sample:


ics/ UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 due to no predicted samples. 'precision', 'predicted', average, warn_for)


ics/ UndefinedMetricWarning: F-score is ill-defined and being set to 0.0 due to no predicted samples.

  'precision', 'predicted', average, warn_for)

When there is no predicted sample, it means that TP+FP is 0, so

precision defined as

TP/(TP+FP)) is 0/0

not defined,

F1 score (defined as 2TP/(2TP+FP+FN)) is 0 if FN is not zero.

In my case, sklearn.metrics also returns the accuracy as 0.8, and recall as 0. So FN is not zero.

But why does scikilearn says F1 is ill-defined?

What is the definition of F1 used by Scikilearn?

1 Answer

0 votes
by (33.1k points)

You can take a look at this well defined Github Repository from Scikit learn developers. It has detailed information for evaluation metrics.


F1 = 2 * (precision * recall) / (precision + recall)

precision = TP/(TP+FP) 

if the predictor doesn't predict positive class overall, then precision is 0.

recall = TP/(TP+FN)

But if the predictor doesn't predict positive class - TP is 0 - recall is 0.

Finally, you are dividing 0/0.

Hope this answer helps.

To learn what is machine learning and applications of machine learning, visit the machine learning course by Intellipaat.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories