/** * Calculate the F beta value from counts * * @param beta Beta of value to use * @param tp True positive count * @param fp False positive count * @param fn False negative count * @return F beta */ public static double fBeta(double beta, long tp, long fp, long fn) { double prec = tp / ((double) tp + fp); double recall = tp / ((double) tp + fn); return fBeta(beta, prec, recall); }
/** * Calculate the f_beta for a given class, where f_beta is defined as:<br> * (1+beta^2) * (precision * recall) / (beta^2 * precision + recall).<br> * F1 is a special case of f_beta, with beta=1.0 * * @param beta Beta value to use * @param classLabel Class label * @param defaultValue Default value to use when precision or recall is undefined (0/0 for prec. or recall) * @return F_beta */ public double fBeta(double beta, int classLabel, double defaultValue) { double precision = precision(classLabel, -1); double recall = recall(classLabel, -1); if (precision == -1 || recall == -1) { return defaultValue; } return EvaluationUtils.fBeta(beta, precision, recall); }
/** * Calculate the F-beta value for the given output * * @param beta Beta value to use * @param outputNum Output number * @return F-beta for the given output */ public double fBeta(double beta, int outputNum) { assertIndex(outputNum); double precision = precision(outputNum); double recall = recall(outputNum); return EvaluationUtils.fBeta(beta, precision, recall); }
return EvaluationUtils.fBeta(beta, (long) truePositives.getCount(1), (long) falsePositives.getCount(1), (long) falseNegatives.getCount(1)); fnCount += falseNegatives.getCount(i); return EvaluationUtils.fBeta(beta, tpCount, fpCount, fnCount); } else { throw new UnsupportedOperationException("Unknown averaging approach: " + averaging);