Link to home
Start Free TrialLog in
Avatar of willie108
willie108

asked on

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
Avatar of Am P
Am P
Flag of India image

What is the content in "C:\\Users\\Bill\\Desktop\\sampleToTestAndTrain\\SampleTestForDat.csv"?


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

Your array is length 2, and you are trying to read past the end of it.
Avatar of willie108
willie108

ASKER

Here is the csv file. Which array would that be? I did not know I have an array.
SampleTestForDat.csv
ASKER CERTIFIED SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
krakatoa, thanks! You got it. I search for that and the error and got the answer.
Thanks
Good to hear.