willie108
asked on
out of bounds exception
Hi. I am running the attached code. I am getting
C:\Users\Bill\Desktop\Diam ond>java -cp ./lib/xmlParserAPIs-2.2.1. jar;./lib/ gdata-fi
nance-2.0.jar;./lib/gdata- core-1.0.j ar;./lib/m ail.jar;./ lib/mysql- connector- java-5.
1.18-bin.jar;./lib/weka.ja r;./lib/go ogle-colle ct-1.0-rc1 .jar;./bin CSVSimple
Exception in thread "main" java.lang.ArrayIndexOutOfB oundsExcep tion: 2
at weka.classifiers.Evaluatio n.updateMa rgins(Eval uation.jav a:3591)
at weka.classifiers.Evaluatio n.updateSt atsForClas sifier(Eva luation.ja va:341
8)
at weka.classifiers.Evaluatio n.evaluati onForSingl eInstance( Evaluation .java:
1505)
at weka.classifiers.Evaluatio n.evaluati onForSingl eInstance( Evaluation .java:
1560)
at weka.classifiers.Evaluatio n.evaluate ModelOnceA ndRecordPr ediction(E valuat
ion.java:1597)
at weka.classifiers.Evaluatio n.evaluate Model(Eval uation.jav a:1477)
at CSVSimple.main(CSVSimple.j ava:62)
when executing:
C:\Users\Bill\Desktop\Diam ond>java -cp ./lib/xmlParserAPIs-2.2.1. jar;./lib/ gd
nance-2.0.jar;./lib/gdata- core-1.0.j ar;./lib/m ail.jar;./ lib/mysql- connector- j
1.18-bin.jar;./lib/weka.ja r;./lib/go ogle-colle ct-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.Evaluatio n;
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.to SummaryStr ing("\nRes ults\n==== ==\n", false));
Does anyone have any insight there?
thanks.
CSVSimple.java
C:\Users\Bill\Desktop\Diam
nance-2.0.jar;./lib/gdata-
1.18-bin.jar;./lib/weka.ja
Exception in thread "main" java.lang.ArrayIndexOutOfB
at weka.classifiers.Evaluatio
at weka.classifiers.Evaluatio
8)
at weka.classifiers.Evaluatio
1505)
at weka.classifiers.Evaluatio
1560)
at weka.classifiers.Evaluatio
ion.java:1597)
at weka.classifiers.Evaluatio
at CSVSimple.main(CSVSimple.j
when executing:
C:\Users\Bill\Desktop\Diam
nance-2.0.jar;./lib/gdata-
1.18-bin.jar;./lib/weka.ja
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.Evaluatio
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.to
Does anyone have any insight there?
thanks.
CSVSimple.java
java.lang.ArrayIndexOutOfB oundsExcep tion: 2
Your array is length 2, and you are trying to read past the end of it.
Your array is length 2, and you are trying to read past the end of it.
ASKER
Here is the csv file. Which array would that be? I did not know I have an array.
SampleTestForDat.csv
SampleTestForDat.csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
krakatoa, thanks! You got it. I search for that and the error and got the answer.
ASKER
Thanks
Good to hear.
Can you upload both the files here?