public boolean bestLabelIsCorrect () { Labeling correctLabeling = instance.getLabeling(); if (correctLabeling == null) throw new IllegalStateException ("Instance has no label."); return (labeling.getBestLabel().equals (correctLabeling.getBestLabel())); }
public void print () { if (child0 == null) System.out.println (getName() + ": " + labeling.getBestLabel()); else { child0.print(); child1.print(); } }
public PipedInstanceWithConfidence[] rankPipedInstancesByConfidence (InstanceList ilist, Object[] startTags, Object[] continueTags) { ArrayList confidenceList = new ArrayList (); for (int i=0; i < ilist.size(); i++) { Instance instance = ilist.getInstance (i); boolean correctInstance = ((Labeling)instance.getTarget()).getBestLabel().toString().equals (this.correct); System.err.println ("Instance is " + (correctInstance ? "correct" : "incorrect")); confidenceList.add (new PipedInstanceWithConfidence (instance, estimateConfidenceFor (instance, startTags, continueTags), correctInstance)); } Collections.sort (confidenceList); PipedInstanceWithConfidence[] ret = new PipedInstanceWithConfidence[1]; ret = (PipedInstanceWithConfidence[]) confidenceList.toArray (ret); return ret; }
Citation c1 = (Citation)pair.getObject1(); Citation c2 = (Citation)pair.getObject2(); if (labeling.getBestLabel().toString().equals("yes") && labeling.getBestValue() > 0.8) { boolean newCluster = true; for (int j=0; j<clustering.size(); j++) {
if (getClassification(i).getLabeling().getBestLabel().toString().equals(label)) { if (getClassification(i).bestLabelIsCorrect()) { numCorrect++; if (getClassification(i).getInstance().getLabeling().getBestLabel().toString().equals(label)) numInLabel++;
public void testRandomTrained () { InstanceList ilist = new InstanceList (new Random(1), 10, 2); Classifier c = new NaiveBayesTrainer ().train (ilist); // test on the training data int numCorrect = 0; for (int i = 0; i < ilist.size(); i++) { Instance inst = ilist.getInstance(i); Classification cf = c.classify (inst); cf.print (); if (cf.getLabeling().getBestLabel() == inst.getLabeling().getBestLabel()) numCorrect++; } System.out.println ("Accuracy on training set = " + ((double)numCorrect)/ilist.size()); }
public void testClassifier (InstanceList tlist, MaxEnt classifier) { Trial t = new Trial(classifier, tlist); System.out.println("test accuracy: " + t.labelF1("yes")); for (Iterator it = tlist.iterator(); it.hasNext();) { Instance inst = (Instance)it.next(); Classification classification = (Classification)classifier.classify(inst); Labeling l = classification.getLabeling(); //System.out.println("Best label: " + l.getBestLabel().toString() + " " // + inst.getTarget().toString()); if (!l.getBestLabel().toString().equals(inst.getTarget().toString())) { Citation c1 = (Citation)((NodePair)inst.getSource()).getObject1(); Citation c2 = (Citation)((NodePair)inst.getSource()).getObject2(); if (inst.getLabeling().getBestLabel().toString().equals("yes")) { System.out.println("FN: " + c1.print() + " " + c1.getString() + "\n " + c2.print() + " " + c2.getString()); System.out.println("Citation venue: " + c1.getField("venue") + " --> " + c2.getField("venue")); } else if (inst.getLabeling().getBestLabel().toString().equals("no")) { System.out.println("FP: " + c1.print() + " " + c1.getString() + "\n " + c2.print() + " " + c2.getString()); System.out.println("Citation venue: " + c1.getField("venue") + " --> " + c2.getField("venue")); } System.out.println(printParamDetails((FeatureVector)inst.getData(), classification, classifier)); } } }
assertTrue (cf.getLabeling().getBestLabel() == ldict.lookupLabel("politics")); assertTrue (cf.getLabeling().getBestValue() > 0.6);
public void testStringTrained () { String[] africaTraining = new String[] { "on the plains of africa the lions roar", "in swahili ngoma means to dance", "nelson mandela became president of south africa", "the saraha dessert is expanding"}; String[] asiaTraining = new String[] { "panda bears eat bamboo", "china's one child policy has resulted in a surplus of boys", "tigers live in the jungle"}; InstanceList instances = new InstanceList ( new SerialPipes (new Pipe[] { new Target2Label (), new CharSequence2TokenSequence (), new TokenSequence2FeatureSequence (), new FeatureSequence2FeatureVector ()})); instances.add (new ArrayIterator (africaTraining, "africa")); instances.add (new ArrayIterator (asiaTraining, "asia")); Classifier c = new NaiveBayesTrainer ().train (instances); Classification cf = c.classify ("nelson mandela never eats lions"); assertTrue (cf.getLabeling().getBestLabel() == ((LabelAlphabet)instances.getTargetAlphabet()).lookupLabel("africa")); }