public NaiveBayesTrainer newClassifierTrainer(Classifier initialClassifier) { return new NaiveBayesTrainer ((NaiveBayes)initialClassifier); } public NaiveBayesTrainer.Factory setDocLengthNormalization (double docLengthNormalization) {
public NaiveBayesTrainer newClassifierTrainer(Classifier initialClassifier) { return new NaiveBayesTrainer ((NaiveBayes)initialClassifier); } public NaiveBayesTrainer.Factory setDocLengthNormalization (double docLengthNormalization) {
public NaiveBayesTrainer newClassifierTrainer(Classifier initialClassifier) { return new NaiveBayesTrainer ((NaiveBayes)initialClassifier); } public NaiveBayesTrainer.Factory setDocLengthNormalization (double docLengthNormalization) {
public ClassifierTrainer<NaiveBayes> createTrainer(String... args) { NaiveBayesTrainer trainer = new NaiveBayesTrainer(); if (args != null) { if (args.length % 2 != 0) { throw new IllegalArgumentException("each argument must be supplied with a value: " + getUsageMessage()); } for (int i = 0; i < args.length; i += 2) { String optionName = args[i]; String optionValue = args[i + 1]; if (optionName.equals("--docLengthNormalization")) trainer.setDocLengthNormalization(Double.parseDouble(optionValue)); else throw new IllegalArgumentException(String.format( "the argument %1$s is invalid.", optionName) + getUsageMessage()); } } return trainer; }
public ClassifierTrainer<NaiveBayes> createTrainer(String... args) { NaiveBayesTrainer trainer = new NaiveBayesTrainer(); if (args != null) { if (args.length % 2 != 0) { throw new IllegalArgumentException("each argument must be supplied with a value: " + getUsageMessage()); } for (int i = 0; i < args.length; i += 2) { String optionName = args[i]; String optionValue = args[i + 1]; if (optionName.equals("--docLengthNormalization")) trainer.setDocLengthNormalization(Double.parseDouble(optionValue)); else throw new IllegalArgumentException(String.format( "the argument %1$s is invalid.", optionName) + getUsageMessage()); } } return trainer; }
classifierTrainers.add (new NaiveBayesTrainer());
public void reset() { switch (type) { case NaiveBayes: this.trainer = new NaiveBayesTrainer(); this.classifier = null; break;
NaiveBayesTrainer trainer = new NaiveBayesTrainer(); NaiveBayes classifier = trainer.trainIncremental(instList);
NaiveBayesTrainer trainer = new NaiveBayesTrainer(); NaiveBayes classifier = trainer.trainIncremental(instList);
public void testRandomTrained () { InstanceList ilist = new InstanceList (new Randoms(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.get(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()); }
NaiveBayesTrainer trainer = new NaiveBayesTrainer(); NaiveBayes classifier = (NaiveBayes) trainer.trainIncremental(instList);
NaiveBayesTrainer trainer = new NaiveBayesTrainer(); NaiveBayes classifier = (NaiveBayes) trainer.trainIncremental(instList);
public void testRandomTrained () { InstanceList ilist = new InstanceList (new Randoms(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.get(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()); }
NaiveBayesTrainer trainer = new NaiveBayesTrainer(); NaiveBayes classifier = (NaiveBayes) trainer.trainIncremental(instList);
NaiveBayesTrainer trainer = new NaiveBayesTrainer(); NaiveBayes classifier = (NaiveBayes) trainer.trainIncremental(instList);
ClassifierTrainer naiveBayesTrainer = new NaiveBayesTrainer (); Classifier classifier = naiveBayesTrainer.train (ilists[0]);
ClassifierTrainer naiveBayesTrainer = new NaiveBayesTrainer (); Classifier classifier = naiveBayesTrainer.train (ilists[0]);
ClassifierTrainer naiveBayesTrainer = new NaiveBayesTrainer (); Classifier classifier = naiveBayesTrainer.train (ilists[0]);
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.addThruPipe (new ArrayIterator (africaTraining, "africa")); instances.addThruPipe (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")); }
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.addThruPipe (new ArrayIterator (africaTraining, "africa")); instances.addThruPipe (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")); }