• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

out of bounds exception

Hi. I am running the attached code. I am getting

C:\Users\Bill\Desktop\Diamond>java -cp ./lib/xmlParserAPIs-2.2.1.jar;./lib/gdata-fi
nance-2.0.jar;./lib/gdata-core-1.0.jar;./lib/mail.jar;./lib/mysql-connector-java-5.
1.18-bin.jar;./lib/weka.jar;./lib/google-collect-1.0-rc1.jar;./bin CSVSimple
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
        at weka.classifiers.Evaluation.updateMargins(Evaluation.java:3591)
        at weka.classifiers.Evaluation.updateStatsForClassifier(Evaluation.java:341
8)
        at weka.classifiers.Evaluation.evaluationForSingleInstance(Evaluation.java:
1505)
        at weka.classifiers.Evaluation.evaluationForSingleInstance(Evaluation.java:
1560)
        at weka.classifiers.Evaluation.evaluateModelOnceAndRecordPrediction(Evaluat
ion.java:1597)
        at weka.classifiers.Evaluation.evaluateModel(Evaluation.java:1477)
        at CSVSimple.main(CSVSimple.java:62)




when executing:
C:\Users\Bill\Desktop\Diamond>java -cp ./lib/xmlParserAPIs-2.2.1.jar;./lib/gd
nance-2.0.jar;./lib/gdata-core-1.0.jar;./lib/mail.jar;./lib/mysql-connector-j
1.18-bin.jar;./lib/weka.jar;./lib/google-collect-1.0-rc1.jar;./bin CSVSimple


I am trying to run the example at http://weka.wikispaces.com/Use+WEKA+in+your+Java+code

which has this:
Train/test set
In case you have a dedicated test set, you can train the classifier and then evaluate it on this test set. In the following example, a J48 is instantiated, trained and then evaluated. Some statistics are printed to stdout:
 import weka.core.Instances;
 import weka.classifiers.Evaluation;
 import weka.classifiers.trees.J48;
 ...
 Instances train = ...   // from somewhere
 Instances test = ...    // from somewhere
 // train classifier
 Classifier cls = new J48();
 cls.buildClassifier(train);
 // evaluate classifier and print some statistics
 Evaluation eval = new Evaluation(train);
 eval.evaluateModel(cls, test);
 System.out.println(eval.toSummaryString("\nResults\n======\n", false));

Does anyone have any insight there?
thanks.
CSVSimple.java
0
willie108
Asked:
willie108
  • 3
  • 3
1 Solution
 
Amitkumar PSr. ConsultantCommented:
What is the content in "C:\\Users\\Bill\\Desktop\\sampleToTestAndTrain\\SampleTestForDat.csv"?


Can you upload both the files here?
0
 
krakatoaCommented:
java.lang.ArrayIndexOutOfBoundsException: 2

Your array is length 2, and you are trying to read past the end of it.
0
 
willie108Author Commented:
Here is the csv file. Which array would that be? I did not know I have an array.
SampleTestForDat.csv
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
krakatoaCommented:
Well, what does the code do here :

at weka.classifiers.Evaluation.updateStatsForClassifier(Evaluation.java:341
8)
0
 
willie108Author Commented:
krakatoa, thanks! You got it. I search for that and the error and got the answer.
0
 
willie108Author Commented:
Thanks
0
 
krakatoaCommented:
Good to hear.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now