Class ConfusionMetrics
java.lang.Object
org.tribuo.classification.evaluation.ConfusionMetrics
Static functions for computing classification metrics based on a
ConfusionMatrix.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Classifiable<T>>
doubleaccuracy(EvaluationMetric.Average average, ConfusionMatrix<T> cm) Calculates the accuracy using the specified average type and confusion matrix.static <T extends Classifiable<T>>
doubleaccuracy(MetricTarget<T> target, ConfusionMatrix<T> cm) Calculates the accuracy given this confusion matrix.static <T extends Classifiable<T>>
doubleaccuracy(T label, ConfusionMatrix<T> cm) Calculates a per label accuracy given this confusion matrix.static <T extends Classifiable<T>>
doublebalancedErrorRate(ConfusionMatrix<T> cm) Calculates the balanced error rate, i.e., the mean of the recalls.static doublef1(double tp, double fp, double tn, double fn) Computes the F_1 score.static <T extends Classifiable<T>>
doublef1(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Computes the F_1 score.static <T extends Classifiable<T>>
doublefn(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Returns the number of false negatives, possibly averaged depending on the metric target.static <T extends Classifiable<T>>
doublefp(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Returns the number of false positives, possibly averaged depending on the metric target.static doublefscore(double beta, double tp, double fp, double tn, double fn) Computes the Fscore.static <T extends Classifiable<T>>
doublefscore(MetricTarget<T> tgt, ConfusionMatrix<T> cm, double beta) Computes the Fscore.static doubleprecision(double tp, double fp, double tn, double fn) Calculates the precision based upon the supplied statistics.static <T extends Classifiable<T>>
doubleprecision(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Calculates the precision for this metric target.static doublerecall(double tp, double fp, double tn, double fn) Calculates the recall based upon the supplied statistics.static <T extends Classifiable<T>>
doublerecall(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Calculates the recall for this metric target.static <T extends Classifiable<T>>
doubletn(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Returns the number of true negatives, possibly averaged depending on the metric target.static <T extends Classifiable<T>>
doubletp(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Returns the number of true positives, possibly averaged depending on the metric target.
-
Method Details
-
accuracy
public static <T extends Classifiable<T>> double accuracy(MetricTarget<T> target, ConfusionMatrix<T> cm) Calculates the accuracy given this confusion matrix.- Type Parameters:
T- The type parameter- Parameters:
target- The metric targetcm- The confusion matrix- Returns:
- The accuracy
-
accuracy
Calculates a per label accuracy given this confusion matrix.- Type Parameters:
T- The type parameter- Parameters:
label- The labelcm- The confusion matrix- Returns:
- The accuracy
-
accuracy
public static <T extends Classifiable<T>> double accuracy(EvaluationMetric.Average average, ConfusionMatrix<T> cm) Calculates the accuracy using the specified average type and confusion matrix.- Type Parameters:
T- the type parameter- Parameters:
average- the averagecm- The confusion matrix- Returns:
- The accuracy
-
balancedErrorRate
Calculates the balanced error rate, i.e., the mean of the recalls.- Type Parameters:
T- the type parameter- Parameters:
cm- The confusion matrix- Returns:
- the balanced error rate.
-
tp
Returns the number of true positives, possibly averaged depending on the metric target.- Type Parameters:
T- the type parameter- Parameters:
tgt- The metric targetcm- The confusion matrix- Returns:
- the true positives.
-
fp
Returns the number of false positives, possibly averaged depending on the metric target.- Type Parameters:
T- the type parameter- Parameters:
tgt- The metric targetcm- The confusion matrix- Returns:
- the false positives.
-
tn
Returns the number of true negatives, possibly averaged depending on the metric target.- Type Parameters:
T- the type parameter- Parameters:
tgt- The metric targetcm- The confusion matrix- Returns:
- the true negatives.
-
fn
Returns the number of false negatives, possibly averaged depending on the metric target.- Type Parameters:
T- the type parameter- Parameters:
tgt- The metric targetcm- The confusion matrix- Returns:
- the false negatives.
-
precision
public static <T extends Classifiable<T>> double precision(MetricTarget<T> tgt, ConfusionMatrix<T> cm) Calculates the precision for this metric target.- Type Parameters:
T- the type parameter- Parameters:
tgt- The metric targetcm- The confusion matrix- Returns:
- the precision.
-
precision
public static double precision(double tp, double fp, double tn, double fn) Calculates the precision based upon the supplied statistics.- Parameters:
tp- the true positivesfp- the false positivestn- the true negativesfn- the false negatives- Returns:
- The recall.
-
recall
Calculates the recall for this metric target.- Type Parameters:
T- the type parameter- Parameters:
tgt- The metric targetcm- The confusion matrix- Returns:
- The recall.
-
recall
public static double recall(double tp, double fp, double tn, double fn) Calculates the recall based upon the supplied statistics.- Parameters:
tp- the true positivesfp- the false positivestn- the true negativesfn- the false negatives- Returns:
- The recall.
-
f1
Computes the F_1 score.- Type Parameters:
T- the type parameter- Parameters:
tgt- the metric target.cm- the confusion matrix.- Returns:
- the F_1 score.
-
f1
public static double f1(double tp, double fp, double tn, double fn) Computes the F_1 score.- Parameters:
tp- the true positivesfp- the false positivestn- the true negativesfn- the false negatives- Returns:
- the F_1 score.
-
fscore
public static double fscore(double beta, double tp, double fp, double tn, double fn) Computes the Fscore.- Parameters:
beta- the beta.tp- the true positives.fp- the false positives.tn- the true negatives.fn- the false negatives.- Returns:
- the F_beta score.
-
fscore
public static <T extends Classifiable<T>> double fscore(MetricTarget<T> tgt, ConfusionMatrix<T> cm, double beta) Computes the Fscore.- Type Parameters:
T- the type parameter- Parameters:
tgt- The metric targetcm- The confusion matrixbeta- the beta- Returns:
- The F_beta score.
-