Re: [Java-ML-support] NullPointerException during NaiveBayesClassifier.buildClassifier()
Status: Beta
Brought to you by:
thomasabeel
From: Tom D. <tom...@gm...> - 2012-11-12 18:24:57
|
Thanks for the reply. The way in which I'm constructing training data is the following: private Dataset buildTrainingDataset(Object[][] data, int sampleIntervalWidth, int futureDays) throws StorageException{ Log.logMessage(LogLevel.DEBUG, "Engine.buildDataset(",data,sampleIntervalWidth,")"); // The data set we are building up. Dataset ds = new DefaultDataset(); // Create all samples for(int i = 0; i + sampleIntervalWidth <= data.length - futureDays; i++){ // Add the sample domain data DenseInstance di = new DenseInstance(buildSampleDoubleArr(data, i, sampleIntervalWidth)); // Get the "current" and future price for this sample double original = Double.valueOf(data[i+sampleIntervalWidth-1][data[0].length-1].toString()); double future = Double.valueOf(data[i+sampleIntervalWidth+futureDays-1][data[0].length-1].toString()); // Find the relative growth or decline Double classification = (future - original) / original; // Round the growth or decline to the nearest hundredth classification = ((int) ((classification * 100.0)+0.5)) / 100.0; // Convert to percentage classification = classification * 100; // Use the percentage growth di.setClassValue(classification); // Add the sample to the data set ds.add(di); } return ds; } Summary: I am indeed setting a class value for each Instance in the training Dataset, and the values are of type Double. Please let me know if you need to see anything else. Thanks, Tom On Mon, Nov 12, 2012 at 11:16 AM, Thomas Abeel <th...@ab...> wrote: > 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 lis...@li...https://lists.sourceforge.net/lists/listinfo/java-ml-support > > > |