Class ConfusionMetrics


  • public class ConfusionMetrics
    extends java.lang.Object
    A util class for handling confusion matrix metrics that are solely based on counts of true positives (tp), false positives (fp), true negatives (tn), and false negatives (fn).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double getAccuracy​(int tp, int fp, int tn, int fn)
      The accuracy (ACC).
      static double getBalancedAccuracy​(int tp, int fp, int tn, int fn)
      The balanced accuracy (BA)
      static double getCriticalSuccessIndex​(int tp, int fp, int fn)
      The threat score (TS) aka. critical success index (CSI).
      static double getDiagnosticOddsRatio​(int tp, int fp, int tn, int fn)
      The diagnostic odds ratio (DOR).
      static double getErrorRate​(int tp, int fp, int tn, int fn)
      The misclassification rate, error rate.
      static double getF1Score​(int tp, int fp, int fn)
      The F1-score, harmonic mean of precision and recall.
      static double getFallOut​(int fp, int tn)
      Fall-out aka. false positive rate (FPR).
      static double getFalseDiscoveryRate​(int tp, int fp)
      False discovery rate (FDR)
      static double getFalseNegativeRate​(int tp, int fn)
      Miss rate, false negative rate (FNR).
      static double getFalseOmissionRate​(int tn, int fn)
      The false omission rate (FOR).
      static double getFMeasure​(double beta, int tp, int fp, int fn)
      The general F-Measure being parameterized by a constant beta.
      static double getFowlkesMallowsIndex​(int tp, int fp, int fn)
      The Fowlkes-Mallows index (FMI).
      static double getInformedness​(int tp, int fp, int tn, int fn)
      The informedness or bookmaker informedness(BM)
      static double getMarkedness​(int tp, int fp, int tn, int fn)
      The markedness (MK) or deltaP.
      static double getMatthewsCorrelationCoefficient​(int tp, int fp, int tn, int fn)
      The Matthews correlation coefficient (MCC).
      static double getNegativeLikelihoodRatio​(int tp, int fp, int tn, int fn)
      The negative likelihood ratio (NLR).
      static double getNegativePredictiveValue​(int tn, int fn)
      Negative predictive value (NPV).
      static double getPositiveLikelihoodRatio​(int tp, int fp, int tn, int fn)
      The positive likelihood ratio (PLR).
      static double getPrecision​(int tp, int fp)
      Precision aka. positive predictive value (PPV).
      static double getPredictedPositiveConditionRate​(int tp, int fp, int tn, int fn)
      The predicted positive condition rate (PPCR).
      static double getPrevalenceThreshold​(int tp, int fp, int tn, int fn)
      The prevalence threshold (PT).
      static double getRecall​(int tp, int fn)
      Recall aka. sensitivity aka. hit rate aka. true positive rate (TPR).
      static double getTrueNegativeRate​(int fp, int tn)
      Specificity, selectivity, true negative rate (TNR).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getPrecision

        public static double getPrecision​(int tp,
                                          int fp)
        Precision aka. positive predictive value (PPV).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        Returns:
        The positive predictive value (PPV) aka. Precision. 1 iff both tp and fp are 0.
      • getRecall

        public static double getRecall​(int tp,
                                       int fn)
        Recall aka. sensitivity aka. hit rate aka. true positive rate (TPR).
        Parameters:
        tp - Count of true positives.
        fn - Count of false negatives.
        Returns:
        The recall/sensitivity/hit rate/TPR.
      • getTrueNegativeRate

        public static double getTrueNegativeRate​(int fp,
                                                 int tn)
        Specificity, selectivity, true negative rate (TNR).
        Parameters:
        fp - Count of false positives.
        tn - Count of true negatives.
        Returns:
        The specificity/selectivity/TNR
      • getNegativePredictiveValue

        public static double getNegativePredictiveValue​(int tn,
                                                        int fn)
        Negative predictive value (NPV).
        Parameters:
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The NPV.
      • getFalseNegativeRate

        public static double getFalseNegativeRate​(int tp,
                                                  int fn)
        Miss rate, false negative rate (FNR).
        Parameters:
        tp - Count of true positives.
        fn - Count of false negatives.
        Returns:
        The miss rate/FNR.
      • getFallOut

        public static double getFallOut​(int fp,
                                        int tn)
        Fall-out aka. false positive rate (FPR).
        Parameters:
        fp - Count of false positives.
        tn - Count of true negatives.
        Returns:
        The fall-out, FPR.
      • getFalseDiscoveryRate

        public static double getFalseDiscoveryRate​(int tp,
                                                   int fp)
        False discovery rate (FDR)
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        Returns:
        The FDR.
      • getFalseOmissionRate

        public static double getFalseOmissionRate​(int tn,
                                                  int fn)
        The false omission rate (FOR).
        Parameters:
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The FOR.
      • getPrevalenceThreshold

        public static double getPrevalenceThreshold​(int tp,
                                                    int fp,
                                                    int tn,
                                                    int fn)
        The prevalence threshold (PT).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives
        fn - Count of false negatives.
        Returns:
        The PT.
      • getCriticalSuccessIndex

        public static double getCriticalSuccessIndex​(int tp,
                                                     int fp,
                                                     int fn)
        The threat score (TS) aka. critical success index (CSI).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives
        fn - Count of false negatives.
        Returns:
        The TS/CSI.
      • getAccuracy

        public static double getAccuracy​(int tp,
                                         int fp,
                                         int tn,
                                         int fn)
        The accuracy (ACC).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives
        fn - Count of false negatives.
        Returns:
        The ACC.
      • getErrorRate

        public static double getErrorRate​(int tp,
                                          int fp,
                                          int tn,
                                          int fn)
        The misclassification rate, error rate.
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives
        fn - Count of false negatives.
        Returns:
        The misclassification rate/error rate.
      • getBalancedAccuracy

        public static double getBalancedAccuracy​(int tp,
                                                 int fp,
                                                 int tn,
                                                 int fn)
        The balanced accuracy (BA)
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The BA.
      • getF1Score

        public static double getF1Score​(int tp,
                                        int fp,
                                        int fn)
        The F1-score, harmonic mean of precision and recall.
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        fn - Count of false negatives.
        Returns:
        The F1-score.
      • getFMeasure

        public static double getFMeasure​(double beta,
                                         int tp,
                                         int fp,
                                         int fn)
        The general F-Measure being parameterized by a constant beta.
        Parameters:
        beta - The constant to weight precision and recall.
        tp - Count of true positives.
        fp - Count of false positives.
        fn - Count of false negatives.
        Returns:
        The F-Measure score.
      • getMatthewsCorrelationCoefficient

        public static double getMatthewsCorrelationCoefficient​(int tp,
                                                               int fp,
                                                               int tn,
                                                               int fn)
        The Matthews correlation coefficient (MCC).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The MCC.
      • getFowlkesMallowsIndex

        public static double getFowlkesMallowsIndex​(int tp,
                                                    int fp,
                                                    int fn)
        The Fowlkes-Mallows index (FMI).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        fn - Count of false negatives.
        Returns:
        The FMI.
      • getInformedness

        public static double getInformedness​(int tp,
                                             int fp,
                                             int tn,
                                             int fn)
        The informedness or bookmaker informedness(BM)
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The informedness/BM.
      • getMarkedness

        public static double getMarkedness​(int tp,
                                           int fp,
                                           int tn,
                                           int fn)
        The markedness (MK) or deltaP.
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The MK/deltaP.
      • getPredictedPositiveConditionRate

        public static double getPredictedPositiveConditionRate​(int tp,
                                                               int fp,
                                                               int tn,
                                                               int fn)
        The predicted positive condition rate (PPCR).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The PPCR.
      • getPositiveLikelihoodRatio

        public static double getPositiveLikelihoodRatio​(int tp,
                                                        int fp,
                                                        int tn,
                                                        int fn)
        The positive likelihood ratio (PLR).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The PLR.
      • getNegativeLikelihoodRatio

        public static double getNegativeLikelihoodRatio​(int tp,
                                                        int fp,
                                                        int tn,
                                                        int fn)
        The negative likelihood ratio (NLR).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The NLR.
      • getDiagnosticOddsRatio

        public static double getDiagnosticOddsRatio​(int tp,
                                                    int fp,
                                                    int tn,
                                                    int fn)
        The diagnostic odds ratio (DOR).
        Parameters:
        tp - Count of true positives.
        fp - Count of false positives.
        tn - Count of true negatives.
        fn - Count of false negatives.
        Returns:
        The DOR.