avatarLiu Zuo Lin

Summary

The provided web content explains the concepts of accuracy, precision, and recall in the context of machine learning classification problems, illustrating their practical application and implementation in code using sklearn.

Abstract

The article "Accuracy, Precision, and Recall Explained in Plain English" clarifies the key metrics used in evaluating classification models within machine learning. It defines true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN) as the foundational elements for understanding accuracy, precision, and recall. Accuracy is presented as the ratio of correct predictions to all predictions, precision as the ratio of correctly predicted true outcomes to all predicted true outcomes, and recall as the ratio of correctly predicted true outcomes to all actual true outcomes. The article further demonstrates these metrics with a concrete example and shows how to calculate them using sklearn functions in Python. The author also encourages readers to support their work by signing up for a Medium membership and to follow their content for continued learning in coding and machine learning.

Opinions

  • The author believes that understanding these metrics is crucial for anyone learning about classification in machine learning.
  • The article suggests that precision and recall are more informative than accuracy alone, especially in scenarios with imbalanced classes.
  • The author implies that practical examples and code implementation are effective ways to solidify the understanding of these metrics.
  • There is an opinion that the younger version of the author could have benefited from such explanations, indicating a personal belief in the value of clear and concise educational content.
  • The author promotes their work and Medium membership as a means of supporting content creation, indicating a preference for this platform and its community-driven approach to content consumption and distribution.

Accuracy, Precision, and Recall Explained in Plain English

Explaining the accuracy, precision, and recall metrics in Machine Learning.

If you’re learning about classification in machine learning, you have probably come into contact with these metrics. This article attempts to explain what these terms are in plain English.

Note: these metrics work only for classification, not regression.

Concept of True Positives, True Negatives, False Positives & False Negatives

We need to understand these 4 terms before we can understand the metrics.

  • true positive (TP) → actual answer is true, we correctly predict as true
  • true negative (TN) → actual answer is false, we correctly predict as false
  • false positive (FP) → actual answer is false, we wrongly predict as true
  • false negative (FN) → actual answer is true, we wrongly predict as false

Accuracy Score

Accuracy = no. correct predictions / all predictions

Accuracy = (TP + TN) / (TP + TN + FP + TN)

Accuracy → Out of all my predictions (both true and false), how many of them are correct

Precision Score

Precision = TP / (TP + FP)

Precision → Out of all my predictions that are true, how many of them are actually true

Recall Score

Recall = TP / (TP + FN)

Recall → Out of all the answers that are true, how many of them did I predict as true

Accuracy, Precision & Recall In Practice

Let’s say we have this set of answers and predictions:

answers = [1,1,1,1,1,0,0,0]
predict = [1,1,1,0,0,1,0,0]

Accuracy is the proportion of answers that we predicted correctly. Out of 8 predictions, we predicted 5 of them correctly (3 true positives and 2 true negatives). Our accuracy score is hence 5/8 which is 62.5%

Precision is true positives / (true positives + false positives). Here, we predicted 4 positives. Out of these 4 predicted positives, 3 of them are actually positive. As such, our precision score is 3/4, which is 75%

Recall is true positives / (true positives + false ngatives). Here, there are 5 actual positives. Out of these 5 actual positives, we predicted 3 of them correctly. As such, our recall score is 3/5, which is 60%

Accuracy, Precision & Recall In Code

We can use sklearn's built-in functions to calculate the accuracy, precision, and recall score for us:

from sklearn.metrics import *
answers = [1,1,1,1,1,0,0,0]
predict = [1,1,1,0,0,1,0,0]
print("accuracy:", accuracy_score(answers, predict))
print("precision:", precision_score(answers, predict))
print("recall:", recall_score(answers, predict))

The output:

accuracy: 0.625
precision: 0.75
recall: 0.6

Note: when calling the score functions, remember to put the answers before the predictions.

Conclusion

If this article provided value and you wish to support me, do consider signing up for a Medium membership — It’s $5 a month, and you get unlimited access to articles on Medium. If you sign up using my link below, I’ll earn a tiny commission at zero additional cost to you.

Sign up using my link here to read unlimited Medium articles.

I write coding articles (once per 1–2 days) that would have probably helped the younger me speed up my learning curve. Do join my email list to get notified whenever I publish.

More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow us on Twitter and LinkedIn. Join our community Discord.

Python
Python3
Machine Learning
Programming
Coding
Recommended from ReadMedium