Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: [email protected]
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Precision & Recall — An Illustrative
Latest   Machine Learning

Precision & Recall — An Illustrative

Last Updated on July 25, 2023 by Editorial Team

Author(s): Yalda Shankar

Originally published on Towards AI.

Precision is defined as TP / (TP + FP), while Recall is defined as TP / (TP + FN). Clearly, Precision is maximised when FP = 0, while Recall is maximised when FN = 0

Precision and Recall are two evaluation metrics, used to measure the performance of a classification algorithm (that outputs discrete labels) in machine learning / information retrieval. The metrics may possibly be used for continuous output variables (like in a regression algorithm) by discretising them using value ranges or intervals [1]; however, such a usage is rare.

To build an intuition about Precision and Recall, let us consider a binary classification problem, i.e., having two output labels. We can define precision and recall for each class C1 and C2. For any class C*,

  • Precision tells us how many objects categorized as C* are correct.
  • Recall tells us how many objects belonging to C* were categorized as C*.
Precision quantifies how many objects of other class (non-rat) enter our class (rat), while recall quantifies how many objects of our class (rat) escape out to the other class (non-rat).

Let us understand this better, taking the example of airport security check-in. Here, the main problem is to identify the presence of any prohibited items in the baggage, like pet, liquid, weapon, etc.

Classes — Let us consider three classes, pet, liquid, and weapon. Precision and Recall can be calculated for each class.

Class of Interest — Let us say that we target the class Pet

Model / AI Algorithm Prediction — The airport scanner using AI algorithm, asks the question (Is there a pet?)

The AI predictions (predicted_y) can answer :

  • Yes ⇒ Positive Prediction
  • No ⇒ Negative Prediction

Comparison with Actual Labels — The security in charge then asks the question (Does the AI predicted result match the actual label?) (predicted_y == actual_y?). The answers can be:

  • Yes ⇒ True (AI prediction was Correct)
  • No ⇒ False (AI prediction was Wrong)

Thus we have four combinations :

  • True Positives (TP) ⇒ [ Correct Detection ]
    Pet detected, and there was indeed a pet
  • True Negatives (TN) ⇒ [ Correct Rejection ]
    No Pet was Detected, and there was indeed no pet
  • False Positives (FP) ⇒ [ Wrong Detection ]
    Pet detected, but there was no pet
    (overestimation, meaning the AI model brings other objects to the class)
  • False Negatives (FN) ⇒ [ Wrong Rejection ]
    No pet was detected, but there was a pet
    (missing objects, meaning the model takes out the desired objects)

Precision is defined as TP / (TP + FP).
A recall is defined as TP / (TP + FN).

Precision and Recall generally (in most real-world scenarios) have an inverse relationship, i.e., if one increases, the other decreases. This happens because:

  • As we raise the detection threshold (a number between 0 and 1, above which detection is positive, else negative), we get more conservative in the positive predictions, which may then cause us to miss some actual positive instances, thereby reducing recall.
    In other words, when we reduce FP, FN may increase.
  • Conversely, if we lower the detection threshold, we predict more positive instances, thereby increasing recall, but that leads to more false positives, leading to lower precision.
    In other words, in a bid to decrease FN, FP tends to increase.

In practice, this trade-off between precision and recall is qualitatively visualized using a precision-recall curve and quantitatively managed using the F1 score —

F1 score is the harmonic mean of precision and recall. It can help in finding a balance between precision and recall, optimising the classifier’s performance based on the specific problem and application requirements.

  • For instance, in the case of email spam detection, we prioritize precision (than recall), since we do not want non-spam emails to go to spam, even if some spam emails come to our inbox.
  • On the other hand, in applications like a medical diagnosis of cancer, we prioritize recall (than precision), since we definitely do not want to miss a cancer case, although some non-cancer cases may be classified as cancer (which can be further diagnosed for correctness).

There are, however cases where precision and recall have a direct relationship, i.e., both increase or decrease. This happens when either the AI model is very robust (both precision and recall are very high), or very poor (both precision and recall are very low).

[1] Torgo, L. and Ribeiro, R., 2009. Precision and recall for regression. In Discovery Science: 12th International Conference, DS 2009, Porto, Portugal, October 3–5, 2009 12 (pp. 332–346). Springer Berlin Heidelberg.

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓