public static double f1Measure(double tp, double fp, double fn) { double precision = precision(tp, fp); double recall = recall(tp, fn); return f1Measure(precision, recall); }
public static double f1Measure(Matrix confusionMatrix, long catIndex) { VerifyUtil.verifySquare(confusionMatrix); return f1Measure(precision(confusionMatrix, catIndex), recall(confusionMatrix, catIndex)); }
public static double precisionMacro(Matrix confusionMatrix) { VerifyUtil.verifySquare(confusionMatrix); double sum = 0; for (int catIndex = 0; catIndex < confusionMatrix.getRowCount(); catIndex++) { sum += precision(confusionMatrix, catIndex); } return sum / confusionMatrix.getRowCount(); }
public static double precision(Matrix confusionMatrix, long catIndex) { VerifyUtil.verifySquare(confusionMatrix); double tp = confusionMatrix.getAsDouble(catIndex, catIndex); double fp = 0; for (int c = 0; c < confusionMatrix.getRowCount(); c++) { if (c == catIndex) { continue; } fp += confusionMatrix.getAsDouble(catIndex, c); } return precision(tp, fp); }
public static double precisionMicro(Matrix confusionMatrix) { double tp = 0; double fp = 0; for (int catIndex = 0; catIndex < confusionMatrix.getRowCount(); catIndex++) { tp += confusionMatrix.getAsDouble(catIndex, catIndex); for (int c = 0; c < confusionMatrix.getRowCount(); c++) { if (c == catIndex) { continue; } fp += confusionMatrix.getAsDouble(catIndex, c); } } return precision(tp, fp); }
public Map<String, Object> calculateObjects(Map<String, Object> input) { Map<String, Object> result = new HashMap<String, Object>(); Matrix source = MathUtil.getMatrix(input.get(SOURCE)); Matrix target = Matrix.Factory.zeros(source.getRowCount(), 1); long cols = source.getColumnCount(); long rows = source.getRowCount(); for (int k = 0; k < rows; k++) { int tp = 0; int fp = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int count = source.getAsInt(r, c); boolean expected = r == k; boolean predicted = c == k; if (expected && predicted) { tp += count; } else if ((!expected) && predicted) { fp += count; } } } target.setAsDouble(MathUtil.precision(tp, fp), k, 0); } result.put(TARGET, target); return result; }