nB.buildClassifier(train);
m_NB.buildClassifier(m_theInstances);
@Test public void testScoreWithClassifier() throws Exception { Instances train = new Instances(new BufferedReader(new StringReader( CorrelationMatrixMapTaskTest.IRIS))); train.setClassIndex(train.numAttributes() - 1); NaiveBayes bayes = new NaiveBayes(); bayes.buildClassifier(train); WekaScoringMapTask task = new WekaScoringMapTask(); task.setModel(bayes, train, train); assertEquals(0, task.getMissingMismatchAttributeInfo().length()); assertEquals(3, task.getPredictionLabels().size()); for (int i = 0; i < train.numInstances(); i++) { assertEquals(3, task.processInstance(train.instance(i)).length); } }
trainingData = Filter.useFilter(instances, m_remove); m_estimator.buildClassifier(trainingData);
trainingData = Filter.useFilter(instances, m_remove); m_estimator.buildClassifier(trainingData);
public class Run { public static void main(String[] args) throws Exception { ConverterUtils.DataSource source1 = new ConverterUtils.DataSource("./data/train.arff"); Instances train = source1.getDataSet(); // setting class attribute if the data format does not provide this information // For example, the XRFF format saves the class attribute information as well if (train.classIndex() == -1) train.setClassIndex(train.numAttributes() - 1); ConverterUtils.DataSource source2 = new ConverterUtils.DataSource("./data/test.arff"); Instances test = source2.getDataSet(); // setting class attribute if the data format does not provide this information // For example, the XRFF format saves the class attribute information as well if (test.classIndex() == -1) test.setClassIndex(train.numAttributes() - 1); // model NaiveBayes naiveBayes = new NaiveBayes(); naiveBayes.buildClassifier(train); // this does the trick double label = naiveBayes.classifyInstance(test.instance(0)); test.instance(0).setClassValue(label); System.out.println(test.instance(0).stringValue(4)); } }
@Test public void testScoreWithClassifierSomeMissingFields() throws Exception { Instances train = new Instances(new BufferedReader(new StringReader( CorrelationMatrixMapTaskTest.IRIS))); train.setClassIndex(train.numAttributes() - 1); NaiveBayes bayes = new NaiveBayes(); bayes.buildClassifier(train); WekaScoringMapTask task = new WekaScoringMapTask(); Remove r = new Remove(); r.setAttributeIndices("1"); r.setInputFormat(train); Instances test = Filter.useFilter(train, r); task.setModel(bayes, train, test); assertTrue(task.getMissingMismatchAttributeInfo().length() > 0); assertTrue(task.getMissingMismatchAttributeInfo().equals( "sepallength missing from incoming data\n")); assertEquals(3, task.getPredictionLabels().size()); for (int i = 0; i < test.numInstances(); i++) { assertEquals(3, task.processInstance(test.instance(i)).length); } }
m_NB.buildClassifier(m_theInstances);