Re: [Java-ML-support] NullPointerException during NaiveBayesClassifier.buildClassifier()
Status: Beta
Brought to you by:
thomasabeel
From: Thomas A. <th...@ab...> - 2012-11-12 17:33:26
|
Hi Tom, Did you set class labels in the method buildTrainingDataset? Training data needs class labels. You'll need to provide a fully contained working code sample to get more help. We can't help you if the two methods that create the objects that are responsible for the exception are not provided. cheers, Thomas On 11/11/2012 4:29 PM, Tom Deering wrote: > I am new to Java-ML, so I apologize if the answer to this is trivial: > > I'm trying to construct and use a Classifier in the following way: > > // Construct an instance of the selected classifier > Classifier c = constructClassifier(classifier); // This > returns a NaiveBayesClassifier > ... > // Build a training Dataset for the symbol using the > historical data > Dataset trainingData = buildTrainingDataset(dataArr, > sampleIntervalWidth, futureDays); > ... > // Train the classifier > c.buildClassifier(trainingData); // NullPointerException happens here > ... > // Now, classify against the latest sample > DenseInstance latestSample = new > DenseInstance(buildSampleDoubleArr(dataArr, dataArr.length - > sampleIntervalWidth - 1, sampleIntervalWidth)); > ... > // Store the result > results.put(s, (Double)c.classify(latestSample)); > > Each time I try this, I seem to be getting a NullPointerException from > the innards of AbstractBayesianClassifier with the following stack trace: > > Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException > at > net.sf.javaml.classification.bayes.AbstractBayesianClassifier.calculateClassFreqs(AbstractBayesianClassifier.java:207) > at > net.sf.javaml.classification.bayes.AbstractBayesianClassifier.buildClassifier(AbstractBayesianClassifier.java:103) > at > net.sf.javaml.classification.bayes.NaiveBayesClassifier.buildClassifier(NaiveBayesClassifier.java:42) > at tdeering.iastate.cs572.ainvestor.engine.Engine.rank(Engine.java:106) > > Can anyone tell me what I am doing wrong? Am I missing a step where I > tell my Classfier about all possible classes? > > Thanks, > > Tom > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_d2d_nov > > > _______________________________________________ > Java-ml-support mailing list > Jav...@li... > https://lists.sourceforge.net/lists/listinfo/java-ml-support |