vals[count++] = tc.getTruePositive(); vals[count++] = tc.getFalseNegative(); vals[count++] = tc.getFalsePositive(); vals[count++] = tc.getTrueNegative(); vals[count++] = tc.getFalsePositiveRate(); vals[count++] = tc.getTruePositiveRate(); vals[count++] = tc.getPrecision(); vals[count++] = tc.getRecall(); vals[count++] = tc.getFallout(); vals[count++] = tc.getFMeasure(); double ss = (tc.getTruePositive() + tc.getFalsePositive()) / (tc.getTruePositive() + tc.getFalsePositive() + tc.getTrueNegative() + tc .getFalseNegative()); vals[count++] = ss; double expectedByChance = (ss * (tc.getTruePositive() + tc .getFalseNegative())); if (expectedByChance < 1) { vals[count++] = Utils.missingValue(); } else { vals[count++] = tc.getTruePositive() / expectedByChance;
/** * Calculate the F-Measure. This is defined as * <p> * * <pre> * 2 * recall * precision * ---------------------- * recall + precision * </pre> * * @return the F-Measure */ public double getFMeasure() { double precision = getPrecision(); double recall = getRecall(); if ((precision + recall) == 0) { return Double.NaN; } return 2 * precision * recall / (precision + recall); }
TwoClassStats tc = new TwoClassStats(totPos, totNeg, 0, 0); double threshold = 0; double cumulativePos = 0; tc.setTruePositive(tc.getTruePositive() - cumulativePos); tc.setFalseNegative(tc.getFalseNegative() + cumulativePos); tc.setFalsePositive(tc.getFalsePositive() - cumulativeNeg); tc.setTrueNegative(tc.getTrueNegative() + cumulativeNeg); threshold = probs[sorted[i]]; insts.add(makeInstance(tc, threshold)); if (tc.getFalseNegative() != totPos || tc.getTrueNegative() != totNeg) { tc = new TwoClassStats(0, 0, totNeg, totPos); threshold = probs[sorted[sorted.length - 1]] + 10e-6; insts.add(makeInstance(tc, threshold));
/** * Gets the performance with respect to one of the classes as a TwoClassStats * object. * * @param classIndex the index of the class of interest. * @return the generated TwoClassStats object. */ public TwoClassStats getTwoClassStats(int classIndex) { double fp = 0, tp = 0, fn = 0, tn = 0; for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { if (row == classIndex) { if (col == classIndex) { tp += get(row, col); } else { fn += get(row, col); } } else { if (col == classIndex) { fp += get(row, col); } else { tn += get(row, col); } } } } return new TwoClassStats(tp, fp, tn, fn); }
TwoClassStats tc = new TwoClassStats(totPos, totNeg, 0, 0); double threshold = 0; double cumulativePos = 0; tc.setTruePositive(tc.getTruePositive() - cumulativePos); tc.setFalseNegative(tc.getFalseNegative() + cumulativePos); tc.setFalsePositive(tc.getFalsePositive() - cumulativeNeg); tc.setTrueNegative(tc.getTrueNegative() + cumulativeNeg); threshold = probs[sorted[i]]; insts.add(makeInstance(tc, threshold)); if (tc.getFalseNegative() != totPos || tc.getTrueNegative() != totNeg) { tc = new TwoClassStats(0, 0, totNeg, totPos); threshold = probs[sorted[sorted.length - 1]] + 10e-6; insts.add(makeInstance(tc, threshold));
/** * Calculate the F-Measure. This is defined as * <p> * * <pre> * 2 * recall * precision * ---------------------- * recall + precision * </pre> * * @return the F-Measure */ public double getFMeasure() { double precision = getPrecision(); double recall = getRecall(); if ((precision + recall) == 0) { return Double.NaN; } return 2 * precision * recall / (precision + recall); }
/** * Gets the performance with respect to one of the classes as a TwoClassStats * object. * * @param classIndex the index of the class of interest. * @return the generated TwoClassStats object. */ public TwoClassStats getTwoClassStats(int classIndex) { double fp = 0, tp = 0, fn = 0, tn = 0; for (int row = 0; row < size(); row++) { for (int col = 0; col < size(); col++) { if (row == classIndex) { if (col == classIndex) { tp += get(row, col); } else { fn += get(row, col); } } else { if (col == classIndex) { fp += get(row, col); } else { tn += get(row, col); } } } } return new TwoClassStats(tp, fp, tn, fn); }
vals[count++] = tc.getTruePositive(); vals[count++] = tc.getFalseNegative(); vals[count++] = tc.getFalsePositive(); vals[count++] = tc.getTrueNegative(); vals[count++] = tc.getFalsePositiveRate(); vals[count++] = tc.getTruePositiveRate(); vals[count++] = tc.getPrecision(); vals[count++] = tc.getRecall(); vals[count++] = tc.getFallout(); vals[count++] = tc.getFMeasure(); double ss = (tc.getTruePositive() + tc.getFalsePositive()) / (tc.getTruePositive() + tc.getFalsePositive() + tc.getTrueNegative() + tc .getFalseNegative()); vals[count++] = ss; double expectedByChance = (ss * (tc.getTruePositive() + tc .getFalseNegative())); if (expectedByChance < 1) { vals[count++] = Utils.missingValue(); } else { vals[count++] = tc.getTruePositive() / expectedByChance;
/** * Returns a string containing the various performance measures for the * current object */ @Override public String toString() { StringBuffer res = new StringBuffer(); res.append(getTruePositive()).append(' '); res.append(getFalseNegative()).append(' '); res.append(getTrueNegative()).append(' '); res.append(getFalsePositive()).append(' '); res.append(getFalsePositiveRate()).append(' '); res.append(getTruePositiveRate()).append(' '); res.append(getPrecision()).append(' '); res.append(getRecall()).append(' '); res.append(getFMeasure()).append(' '); res.append(getFallout()).append(' '); return res.toString(); }
/** * Returns a string containing the various performance measures for the * current object */ @Override public String toString() { StringBuffer res = new StringBuffer(); res.append(getTruePositive()).append(' '); res.append(getFalseNegative()).append(' '); res.append(getTrueNegative()).append(' '); res.append(getFalsePositive()).append(' '); res.append(getFalsePositiveRate()).append(' '); res.append(getTruePositiveRate()).append(' '); res.append(getPrecision()).append(' '); res.append(getRecall()).append(' '); res.append(getFMeasure()).append(' '); res.append(getFallout()).append(' '); return res.toString(); }