private static void printTrialClassification(Trial trial) { for (int i = 0; i < trial.size(); i++) { Instance instance = trial.get(i).getInstance(); System.out.print(instance.getName() + " " + instance.getTarget() + " "); Labeling labeling = trial.get(i).getLabeling(); for (int j = 0; j < labeling.numLocations(); j++){ System.out.print(labeling.getLabelAtRank(j).toString() + ":" + labeling.getValueAtRank(j) + " "); } System.out.println(); } }
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());
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());
/** Return the fraction of instances that have the correct label as their best predicted label. */ public double getAccuracy () { int numCorrect = 0; for (int i = 0; i < this.size(); i++) if (this.get(i).bestLabelIsCorrect()) numCorrect++; return (double)numCorrect/this.size(); }
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());
/** Return the fraction of instances that have the correct label as their best predicted label. */ public double getAccuracy () { int numCorrect = 0; for (int i = 0; i < this.size(); i++) if (this.get(i).bestLabelIsCorrect()) numCorrect++; return (double)numCorrect/this.size(); }
private static void printTrialClassification(Trial trial) { for (int i = 0; i < trial.size(); i++) { Instance instance = trial.get(i).getInstance(); System.out.print(instance.getName() + " " + instance.getTarget() + " "); Labeling labeling = trial.get(i).getLabeling(); for (int j = 0; j < labeling.numLocations(); j++){ System.out.print(labeling.getLabelAtRank(j).toString() + ":" + labeling.getValueAtRank(j) + " "); } System.out.println(); } }
/** Return the fraction of instances that have the correct label as their best predicted label. */ public double getAccuracy () { int numCorrect = 0; for (int i = 0; i < this.size(); i++) if (this.get(i).bestLabelIsCorrect()) numCorrect++; return (double)numCorrect/this.size(); }
private static void printTrialClassification(Trial trial) { for (int i = 0; i < trial.size(); i++) { Instance instance = trial.get(i).getInstance(); System.out.print(instance.getName() + " " + instance.getTarget() + " "); Labeling labeling = trial.get(i).getLabeling(); for (int j = 0; j < labeling.numLocations(); j++){ System.out.print(labeling.getLabelAtRank(j).toString() + ":" + labeling.getValueAtRank(j) + " "); } System.out.println(); } }
/** Calculate the precision for a particular target index from an array list of classifications */ public double getPrecision (int index) { int numCorrect = 0; int numInstances = 0; int trueLabel, classLabel; for (int i = 0; i<this.size(); i++) { trueLabel = this.get(i).getInstance().getLabeling().getBestIndex(); classLabel = this.get(i).getLabeling().getBestIndex(); if (classLabel == index) { numInstances++; if (trueLabel == index) numCorrect++; } } // gdruck@cs.umass.edu // When no examples are predicted to have this label, // we define precision to be 1. if (numInstances==0) { logger.warning("No examples with predicted label " + classifier.getLabelAlphabet().lookupLabel(index) + "!"); assert(numCorrect == 0); return 1; } return ((double)numCorrect/(double)numInstances); }
/** Calculate the recall for a particular target index from an array list of classifications */ public double getRecall (int labelIndex) { int numCorrect = 0; int numInstances = 0; int trueLabel, classLabel; for (int i = 0; i<this.size(); i++) { trueLabel = this.get(i).getInstance().getLabeling().getBestIndex(); classLabel = this.get(i).getLabeling().getBestIndex(); if ( trueLabel == labelIndex ) { numInstances++; if ( classLabel == labelIndex) numCorrect++; } } // gdruck@cs.umass.edu // When no examples have this label, // we define recall to be 1. if (numInstances==0) { logger.warning("No examples with true label " + classifier.getLabelAlphabet().lookupLabel(labelIndex) + "!"); assert(numCorrect == 0); return 1; } return ((double)numCorrect/(double)numInstances); }
/** Calculate the precision for a particular target index from an array list of classifications */ public double getPrecision (int index) { int numCorrect = 0; int numInstances = 0; int trueLabel, classLabel; for (int i = 0; i<this.size(); i++) { trueLabel = this.get(i).getInstance().getLabeling().getBestIndex(); classLabel = this.get(i).getLabeling().getBestIndex(); if (classLabel == index) { numInstances++; if (trueLabel == index) numCorrect++; } } // gdruck@cs.umass.edu // When no examples are predicted to have this label, // we define precision to be 1. if (numInstances==0) { logger.warning("No examples with predicted label " + classifier.getLabelAlphabet().lookupLabel(index) + "!"); assert(numCorrect == 0); return 1; } return ((double)numCorrect/(double)numInstances); }
/** Calculate the recall for a particular target index from an array list of classifications */ public double getRecall (int labelIndex) { int numCorrect = 0; int numInstances = 0; int trueLabel, classLabel; for (int i = 0; i<this.size(); i++) { trueLabel = this.get(i).getInstance().getLabeling().getBestIndex(); classLabel = this.get(i).getLabeling().getBestIndex(); if ( trueLabel == labelIndex ) { numInstances++; if ( classLabel == labelIndex) numCorrect++; } } // gdruck@cs.umass.edu // When no examples have this label, // we define recall to be 1. if (numInstances==0) { logger.warning("No examples with true label " + classifier.getLabelAlphabet().lookupLabel(labelIndex) + "!"); assert(numCorrect == 0); return 1; } return ((double)numCorrect/(double)numInstances); }
/** Calculate the precision for a particular target index from an array list of classifications */ public double getPrecision (int index) { int numCorrect = 0; int numInstances = 0; int trueLabel, classLabel; for (int i = 0; i<this.size(); i++) { trueLabel = this.get(i).getInstance().getLabeling().getBestIndex(); classLabel = this.get(i).getLabeling().getBestIndex(); if (classLabel == index) { numInstances++; if (trueLabel == index) numCorrect++; } } // gdruck@cs.umass.edu // When no examples are predicted to have this label, // we define precision to be 1. if (numInstances==0) { logger.warning("No examples with predicted label " + classifier.getLabelAlphabet().lookupLabel(index) + "!"); assert(numCorrect == 0); return 1; } return ((double)numCorrect/(double)numInstances); }
/** Calculate the recall for a particular target index from an array list of classifications */ public double getRecall (int labelIndex) { int numCorrect = 0; int numInstances = 0; int trueLabel, classLabel; for (int i = 0; i<this.size(); i++) { trueLabel = this.get(i).getInstance().getLabeling().getBestIndex(); classLabel = this.get(i).getLabeling().getBestIndex(); if ( trueLabel == labelIndex ) { numInstances++; if ( classLabel == labelIndex) numCorrect++; } } // gdruck@cs.umass.edu // When no examples have this label, // we define recall to be 1. if (numInstances==0) { logger.warning("No examples with true label " + classifier.getLabelAlphabet().lookupLabel(labelIndex) + "!"); assert(numCorrect == 0); return 1; } return ((double)numCorrect/(double)numInstances); }
/** Return the average rank of the correct class label as returned by Labeling.getRank(correctLabel) on the predicted Labeling. */ public double getAverageRank () { double rsum = 0; Labeling tmpL; Classification tmpC; Instance tmpI; Label tmpLbl, tmpLbl2; int tmpInt; for(int i = 0; i < this.size(); i++) { tmpC = this.get(i); tmpI = tmpC.getInstance(); tmpL = tmpC.getLabeling(); tmpLbl = (Label)tmpI.getTarget(); tmpInt = tmpL.getRank(tmpLbl); tmpLbl2 = tmpL.getLabelAtRank(0); rsum = rsum + tmpInt; } return rsum/this.size(); }
/** Return the average rank of the correct class label as returned by Labeling.getRank(correctLabel) on the predicted Labeling. */ public double getAverageRank () { double rsum = 0; Labeling tmpL; Classification tmpC; Instance tmpI; Label tmpLbl, tmpLbl2; int tmpInt; for(int i = 0; i < this.size(); i++) { tmpC = this.get(i); tmpI = tmpC.getInstance(); tmpL = tmpC.getLabeling(); tmpLbl = (Label)tmpI.getTarget(); tmpInt = tmpL.getRank(tmpLbl); tmpLbl2 = tmpL.getLabelAtRank(0); rsum = rsum + tmpInt; } return rsum/this.size(); }
/** Return the average rank of the correct class label as returned by Labeling.getRank(correctLabel) on the predicted Labeling. */ public double getAverageRank () { double rsum = 0; Labeling tmpL; Classification tmpC; Instance tmpI; Label tmpLbl, tmpLbl2; int tmpInt; for(int i = 0; i < this.size(); i++) { tmpC = this.get(i); tmpI = tmpC.getInstance(); tmpL = tmpC.getLabeling(); tmpLbl = (Label)tmpI.getTarget(); tmpInt = tmpL.getRank(tmpLbl); tmpLbl2 = tmpL.getLabelAtRank(0); rsum = rsum + tmpInt; } return rsum/this.size(); }