P4-metric

From HandWiki
Revision as of 22:18, 6 March 2023 by Corlink (talk | contribs) (add)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

P4 metric [1][2] enables performance evaluation of the binary classifier. It is calculated from precision, recall, specificity and NPV (negative predictive value). P4 is designed in similar way to F1 metric, however addressing the criticisms leveled against F1. It may be perceived as its extension.

Like the other known metrics, P4 is a function of: TP (true positives), TN (true negatives), FP (false positives), FN (false negatives).

Justification

The key concept of P4 is to leverage the four key conditional probabilities:

[math]\displaystyle{ P(+ \mid C{+}) }[/math] - the probability that the sample is positive, provided the classifier result was positive.
[math]\displaystyle{ P(C{+} \mid +) }[/math] - the probability that the classifier result will be positive, provided the sample is positive.
[math]\displaystyle{ P(C{-} \mid -) }[/math] - the probability that the classifier result will be negative, provided the sample is negative.
[math]\displaystyle{ P(- \mid C{-}) }[/math] - the probability the sample is negative, provided the classifier result was negative.

The main assumption behind this metric is, that a properly designed binary classifier should give the results for which all the probabilities mentioned above are close to 1. P4 is designed the way that [math]\displaystyle{ \mathrm{P}_4 = 1 }[/math] requires all the probabilities being equal 1. It also goes to zero when any of these probabilities go to zero.

Definition

P4 is defined as a harmonic mean of four key conditional probabilities:

[math]\displaystyle{ \mathrm{P}_4 = \frac{4}{\frac{1}{P(+ \mid C{+})} + \frac{1}{P(C{+} \mid +)} + \frac{1}{P(C{-} \mid -)} + \frac{1}{P(- \mid C{-})}} = \frac{4}{\frac{1}{\mathit{precision}} + \frac{1}{\mathit{recall}} + \frac{1}{\mathit{specificity}} + \frac{1}{\mathit{NPV}}} }[/math]

In terms of TP,TN,FP,FN it can be calculated as follows:

[math]\displaystyle{ \mathrm{P}_4 = \frac{4\cdot\mathrm{TP}\cdot\mathrm{TN}}{4\cdot\mathrm{TP}\cdot\mathrm{TN} + (\mathrm{TP} + \mathrm{TN}) \cdot (\mathrm{FP} + \mathrm{FN})} }[/math]

Evaluation of the binary classifier performance

Evaluating the performance of binary classifier is a multidisciplinary concept. It spans from the evaluation of medical tests, psychiatric tests to machine learning classifiers from a variety of fields. Thus, many metrics in use exist under several names. Some of them being defined independently.


Properties of P4 metric

  • Symmetry - contrasting to the F1 metric, P4 is symmetrical. It means - it does not change its value when dataset labeling is changed - positives named negatives and negatives named positives.
  • Range: [math]\displaystyle{ \mathrm{P}_4 \in [0,1] }[/math]
  • Achieving [math]\displaystyle{ \mathrm{P}_4 \approx 1 }[/math] requires all the key four conditional probabilities being close to 1.
  • For [math]\displaystyle{ \mathrm{P}_4 \approx 0 }[/math] it is sufficient that one of the key four conditional probabilities is close to 0.

Examples, comparing with the other metrics

Dependency table for selected metrics ("true" means depends, "false" - does not depend):

[math]\displaystyle{ P(+ \mid C{+}) }[/math] [math]\displaystyle{ P(C{+} \mid +) }[/math] [math]\displaystyle{ P(C{-} \mid -) }[/math] [math]\displaystyle{ P(- \mid C{-}) }[/math]
P4 true true true true
F1 true true false false
Informedness false true true false
Markedness true false false true

Metrics that do not depend on a given probability are prone to misrepresentation when it approaches 0.

Example 1: Rare disease detection test

Let us consider the medical test aimed to detect kind of rare disease. Population size is 100 000, while 0.05% population is infected. Test performance: 95% of all positive individuals are classified correctly (TPR=0.95) and 95% of all negative individuals are classified correctly (TNR=0.95). In such a case, due to high population imbalance, in spite of having high test accuracy (0.95), the probability that an individual who has been classified as positive is in fact positive is very low:

[math]\displaystyle{ P(+ \mid C{+}) = 0.0095 }[/math]

And now we can observe how this low probability is reflected in some of the metrics:

  • [math]\displaystyle{ \mathrm{P}_4 = 0.0370 }[/math]
  • [math]\displaystyle{ \mathrm{F}_1 = 0.0188 }[/math]
  • [math]\displaystyle{ \mathrm{J} = \mathbf{0.9100} }[/math] (Informedness / Youden index)
  • [math]\displaystyle{ \mathrm{MK} = 0.0095 }[/math] (Markedness)

Example 2: Image recognition - cats vs dogs

We are training neural network based image classifier. We are considering only two types of images: containing dogs (labeled as 0) and containing cats (labeled as 1). Thus, our goal is to distinguish between the cats and dogs. The classifier overpredicts in favor of cats ("positive" samples): 99.99% of cats are classified correctly and only 1% of dogs are classified correctly. The image dataset consists of 100000 images, 90% of which are pictures of cats and 10% are pictures of dogs. In such a situation, the probability that the picture containing dog will be classified correctly is pretty low:

[math]\displaystyle{ P(C-|-) = 0.01 }[/math]

Not all the metrics are noticing this low probability:

  • [math]\displaystyle{ \mathrm{P}_4 = 0.0388 }[/math]
  • [math]\displaystyle{ \mathrm{F}_1 = \mathbf{0.9478} }[/math]
  • [math]\displaystyle{ \mathrm{J} = 0.0099 }[/math] (Informedness / Youden index)
  • [math]\displaystyle{ \mathrm{MK} = \mathbf{0.8183} }[/math] (Markedness)

See also

References

  1. Sitarz, Mikolaj (2022). "Extending F1 metric, probabilistic approach". arXiv:2210.11997 [cs.LG].
  2. "P4 metric, a new way to evaluate binary classifiers". https://orange-attractor.eu/a/691/.