private static void printTrialClassification(Trial trial) { for (Classification c : trial) { Instance instance = c.getInstance(); System.out.print(instance.getName() + " " + instance.getTarget() + " "); Labeling labeling = c.getLabeling(); for (int j = 0; j < labeling.numLocations(); j++){ System.out.print(labeling.getLabelAtRank(j).toString() + ":" + labeling.getValueAtRank(j) + " "); } System.out.println(); } }
private static void printTrialClassification(Trial trial) { for (Classification c : trial) { Instance instance = c.getInstance(); System.out.print(instance.getName() + " " + instance.getTarget() + " "); Labeling labeling = c.getLabeling(); for (int j = 0; j < labeling.numLocations(); j++){ System.out.print(labeling.getLabelAtRank(j).toString() + ":" + labeling.getValueAtRank(j) + " "); } System.out.println(); } }
private static void printTrialClassification(Trial trial) { for (Classification c : trial) { Instance instance = c.getInstance(); System.out.print(instance.getName() + " " + instance.getTarget() + " "); Labeling labeling = c.getLabeling(); for (int j = 0; j < labeling.numLocations(); j++){ System.out.print(labeling.getLabelAtRank(j).toString() + ":" + labeling.getValueAtRank(j) + " "); } System.out.println(); } }
/** * Constructs matrix and calculates values * @param t the trial to build matrix from */ public ConfusionMatrix(Trial t) { this.trial = t; this.classifications = t; Labeling tempLabeling = ((Classification) classifications.get(0)).getLabeling(); this.numClasses = tempLabeling.getLabelAlphabet().size(); values = new int[numClasses][numClasses]; for (int i=0; i < classifications.size(); i++) { LabelVector lv = ((Classification)classifications.get(i)).getLabelVector(); Instance inst = ((Classification)classifications.get(i)).getInstance(); int bestIndex = lv.getBestIndex(); int correctIndex = inst.getLabeling().getBestIndex(); assert(correctIndex != -1); //System.out.println("Best index="+bestIndex+". Correct="+correctIndex); values[correctIndex][bestIndex]++; } }
/** * Constructs matrix and calculates values * @param t the trial to build matrix from */ public ConfusionMatrix(Trial t) { this.trial = t; this.classifications = t; Labeling tempLabeling = ((Classification) classifications.get(0)).getLabeling(); this.numClasses = tempLabeling.getLabelAlphabet().size(); values = new int[numClasses][numClasses]; for (int i=0; i < classifications.size(); i++) { LabelVector lv = ((Classification)classifications.get(i)).getLabelVector(); Instance inst = ((Classification)classifications.get(i)).getInstance(); int bestIndex = lv.getBestIndex(); int correctIndex = inst.getLabeling().getBestIndex(); assert(correctIndex != -1); //System.out.println("Best index="+bestIndex+". Correct="+correctIndex); values[correctIndex][bestIndex]++; } }
/** * Constructs matrix and calculates values * @param t the trial to build matrix from */ public ConfusionMatrix(Trial t) { this.trial = t; this.classifications = t; Labeling tempLabeling = ((Classification)classifications.get(0)).getLabeling(); this.numClasses = tempLabeling.getLabelAlphabet().size(); values = new int[numClasses][numClasses]; for(int i=0; i < classifications.size(); i++) { LabelVector lv = ((Classification)classifications.get(i)).getLabelVector(); Instance inst = ((Classification)classifications.get(i)).getInstance(); int bestIndex = lv.getBestIndex(); int correctIndex = inst.getLabeling().getBestIndex(); assert(correctIndex != -1); //System.out.println("Best index="+bestIndex+". Correct="+correctIndex); values[correctIndex][bestIndex]++; } }
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(); } }
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(); } }
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(); } }
private void writeClassificationToMongo(List<Classification> classify) { classify.forEach( classification -> { Instance instance = classification.getInstance(); documentsCollection.findOneAndUpdate( Filters.eq(new ObjectId((String) instance.getName())), Updates.set( CLASSIFICATION_FIELD, classification.getLabeling().getBestLabel().toString())); }); }
private void writeClassificationToMongo(List<Classification> classify) { classify.forEach( classification -> { Instance instance = classification.getInstance(); documentsCollection.findOneAndUpdate( Filters.eq(new ObjectId((String) instance.getName())), Updates.set( CLASSIFICATION_FIELD, classification.getLabeling().getBestLabel().toString())); }); }
/** 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(); }
/** 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); }
/** 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(); }
/** 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 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); }