Class ConfusionMetrics
java.lang.Object
org.tribuo.classification.evaluation.ConfusionMetrics
Static functions for computing classification metrics based on a 
ConfusionMatrix.- 
Method SummaryModifier 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- 
accuracypublic 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 target
- cm- The confusion matrix
- Returns:
- The accuracy
 
- 
accuracyCalculates a per label accuracy given this confusion matrix.- Type Parameters:
- T- The type parameter
- Parameters:
- label- The label
- cm- The confusion matrix
- Returns:
- The accuracy
 
- 
accuracypublic 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 average
- cm- The confusion matrix
- Returns:
- The accuracy
 
- 
balancedErrorRateCalculates 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.
 
- 
tpReturns the number of true positives, possibly averaged depending on the metric target.- Type Parameters:
- T- the type parameter
- Parameters:
- tgt- The metric target
- cm- The confusion matrix
- Returns:
- the true positives.
 
- 
fpReturns the number of false positives, possibly averaged depending on the metric target.- Type Parameters:
- T- the type parameter
- Parameters:
- tgt- The metric target
- cm- The confusion matrix
- Returns:
- the false positives.
 
- 
tnReturns the number of true negatives, possibly averaged depending on the metric target.- Type Parameters:
- T- the type parameter
- Parameters:
- tgt- The metric target
- cm- The confusion matrix
- Returns:
- the true negatives.
 
- 
fnReturns the number of false negatives, possibly averaged depending on the metric target.- Type Parameters:
- T- the type parameter
- Parameters:
- tgt- The metric target
- cm- The confusion matrix
- Returns:
- the false negatives.
 
- 
precisionpublic 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 target
- cm- The confusion matrix
- Returns:
- the precision.
 
- 
precisionpublic static double precision(double tp, double fp, double tn, double fn) Calculates the precision based upon the supplied statistics.- Parameters:
- tp- the true positives
- fp- the false positives
- tn- the true negatives
- fn- the false negatives
- Returns:
- The recall.
 
- 
recallCalculates the recall for this metric target.- Type Parameters:
- T- the type parameter
- Parameters:
- tgt- The metric target
- cm- The confusion matrix
- Returns:
- The recall.
 
- 
recallpublic static double recall(double tp, double fp, double tn, double fn) Calculates the recall based upon the supplied statistics.- Parameters:
- tp- the true positives
- fp- the false positives
- tn- the true negatives
- fn- the false negatives
- Returns:
- The recall.
 
- 
f1Computes the F_1 score.- Type Parameters:
- T- the type parameter
- Parameters:
- tgt- the metric target.
- cm- the confusion matrix.
- Returns:
- the F_1 score.
 
- 
f1public static double f1(double tp, double fp, double tn, double fn) Computes the F_1 score.- Parameters:
- tp- the true positives
- fp- the false positives
- tn- the true negatives
- fn- the false negatives
- Returns:
- the F_1 score.
 
- 
fscorepublic 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.
 
- 
fscorepublic 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 target
- cm- The confusion matrix
- beta- the beta
- Returns:
- The F_beta score.
 
 
-