public double getAccuracy (InstanceList ilist) { return new Trial(this, ilist).getAccuracy(); } public double getPrecision (InstanceList ilist, int index) { return new Trial(this, ilist).getPrecision(index); }
public double getPrecision (InstanceList ilist, int index) { return new Trial(this, ilist).getPrecision(index); } public double getPrecision (InstanceList ilist, Labeling labeling) { return new Trial(this, ilist).getPrecision(labeling); }
/** Calculate the F1-measure for a particular target index from an array list of classifications */ public double getF1 (int index) { double precision = getPrecision (index); double recall = getRecall (index); // gdruck@cs.umass.edu // When both precision and recall are 0, F1 is 0. if (precision==0.0 && recall==0.0) { return 0; } return 2*precision*recall/(precision+recall); }
private List<String> createRow( InstanceList training, InstanceList testing, String e, Classifier classifier, Trial trial) { List<String> row = new ArrayList<>(); row.add(e); row.add(Integer.toString(training.size())); row.add(Integer.toString(testing.size())); row.add(Double.toString(trial.getAccuracy())); for (String label : (String[]) classifier.getLabelAlphabet().toArray(new String[0])) { row.add(Double.toString(trial.getF1(label))); row.add(Double.toString(trial.getPrecision(label))); row.add(Double.toString(trial.getRecall(label))); } return row; }
logger.fine ("Training underlying classifier"); Classifier c = underlyingClassifierTrainer.train (trainList); confusionMatrix = new ConfusionMatrix(new Trial(c, trainList)); Trial t = new Trial (c, validationSet); double accuracy = t.getAccuracy(); InstanceList confidencePredictionTraining = new InstanceList (confidencePredictingPipe); logger.fine ("Creating confidence prediction instance list"); double weight; for (int i = 0; i < t.size(); i++) { Classification classification = t.get(i); confidencePredictionTraining.add (classification, null, classification.getInstance().getName(), classification.getInstance().getSource());
Trial trial = testTrainSplit(instanceList); System.out.println(join(new Object[] {// i, trial.getPrecision(TESTING), trial.getRecall(TESTING), trial.getF1(TESTING) }, "\t")); f1s += trial.getF1(TESTING);
private void logAccuracyMetrics(Classifier classifier, Trial trial) { getMonitor().info("Accuracy: {}", trial.getAccuracy()); for (String label : (String[]) classifier.getLabelAlphabet().toArray(new String[0])) { getMonitor().info("F1 for class '{}': {}", label, trial.getF1(label)); getMonitor().info("Precision for class '{}' : {}", label, trial.getPrecision(label)); } }
public double getAverageRank (InstanceList ilist) { return new Trial(this, ilist).getAverageRank(); }
public AccuracyCoverage(Classifier C, InstanceList ilist, int numBuckets, String title) { this(new Trial(C, ilist), numBuckets, title, "unnamed"); }
public double getF1 (Labeling label) { return getF1 (label.getBestIndex()); }
public double getPrecision (Labeling label) { return getPrecision (label.getBestIndex()); }
public double getRecall (Labeling label) { return getRecall (label.getBestIndex()); }
int maxCountLength = 0; int maxTotalLength = 0; LabelAlphabet labelAlphabet = trial.getClassifier().getLabelAlphabet(); for (int i = 0; i < numClasses; i++) { int len = labelAlphabet.lookupLabel(i).toString().length(); sb.append("Confusion Matrix, row=true, column=predicted accuracy=").append(trial.getAccuracy()).append("\n"); sb.append(leftPad("label", indexWidth + maxLabelNameLength + 2)); for (int i = 0; i < numClasses; i++) {
public boolean addAll(Collection<? extends Classification> collection) { boolean ret = true; for (Classification c : collection) if (!this.add(c)) ret = false; return ret; }
private List<String> createRow( InstanceList training, InstanceList testing, String e, Classifier classifier, Trial trial) { List<String> row = new ArrayList<>(); row.add(e); row.add(Integer.toString(training.size())); row.add(Integer.toString(testing.size())); row.add(Double.toString(trial.getAccuracy())); for (String label : (String[]) classifier.getLabelAlphabet().toArray(new String[0])) { row.add(Double.toString(trial.getF1(label))); row.add(Double.toString(trial.getPrecision(label))); row.add(Double.toString(trial.getRecall(label))); } return row; }
logger.fine ("Training underlying classifier"); Classifier c = underlyingClassifierTrainer.train (trainList); confusionMatrix = new ConfusionMatrix(new Trial(c, trainList)); Trial t = new Trial (c, validationSet); double accuracy = t.getAccuracy(); InstanceList confidencePredictionTraining = new InstanceList (confidencePredictingPipe); logger.fine ("Creating confidence prediction instance list"); double weight; for (int i = 0; i < t.size(); i++) { Classification classification = t.get(i); confidencePredictionTraining.add (classification, null, classification.getInstance().getName(), classification.getInstance().getSource());