I am trying to run Support Vector Machine(SVM) classifier using Weka API in my java code. I am getting following error "Src and Dest differ in # of attributes:" on line 13. Please guide me how can I resolve this problem and run classifier successfully(THIS IS MY TIME CRITICAL ACADEMIC PROJECT). If possible, kindly mention the solution with example.
ERROR:
java.lang.IllegalArgumentException: Src and Dest differ in # of attributes: 22 != 31
at weka.core.RelationalLocator.copyRelationalValues(RelationalLocator.java:88)
at weka.filters.Filter.copyValues(Filter.java:359)
at weka.filters.Filter.push(Filter.java:276)
at weka.filters.unsupervised.attribute.Standardize.convertInstance(Standardize.java:260)
at weka.filters.unsupervised.attribute.Standardize.input(Standardize.java:142)
at weka.filters.Filter.useFilter(Filter.java:661)
at ClassifierJan12Pure.main(ClassifierJan12Pure.java:139)
JAVA CODE:
1. filteredData = new Instances(new BufferedReader(new FileReader("training.arff")));
2. filteredData.setClassIndex(0);
3. Classifier classifier=new SMO();
4. classifier.buildClassifier(filteredData);
5. FilteredClassifier filteredClassifier=new FilteredClassifier();
6. filteredClassifier.setClassifier(classifier);
7. Filter filter = new StringToWordVector(1000);
8. filteredClassifier.setFilter(filter);
9. Instances filteredTests= new Instances(new BufferedReader(new FileReader("testing.arff")));
10. Standardize sfilter = new Standardize();
11. sfilter.setInputFormat(filteredData); // initializing the filter once with training set
12. Instances newTrain = Filter.useFilter(filteredData, sfilter); // configures the Filter based on train instances and returns filtered instances
**13. Instances testsF = Filter.useFilter(filteredTests, sfilter); // create new test set ///<<<<<<< Error line.**
14. Evaluation eval = new Evaluation(filteredData);
15. eval.evaluateModel(filteredClassifier, filteredTests);
16. System.out.println(eval.toSummaryString("\nResults\n", false));
training.arff
@relation '_Users_Passionate_Desktop_Training_Text-weka.filters.unsupervised.attribute.StringToWordVector-R1-W1000-prune-rate-1.0-N0-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer -delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\"'
@attribute @@class@@ {dummy,ham,spam}
@attribute about numeric
@attribute and numeric
@attribute be numeric
@attribute construction numeric
@attribute discussion numeric
@attribute me numeric
@attribute much numeric
@attribute np numeric
@attribute of numeric
@attribute reminds numeric
@attribute s numeric
@attribute said numeric
@attribute second numeric
@attribute that numeric
@attribute the numeric
@attribute to numeric
@attribute very numeric
@attribute agree numeric
@attribute auto numeric
@attribute boxes numeric
@attribute credit numeric
@attribute dear numeric
@attribute display numeric
@attribute have numeric
@attribute ll numeric
@attribute nlpeople numeric
@attribute sure numeric
@attribute we numeric
@attribute with numeric
@attribute you numeric
@data
{0 ham,1 1,2 1,3 1,4 1,7 1,8 1,12 1,13 1,15 1,16 1,17 1}
{0 ham,5 1,6 1,8 1,9 1,10 1,11 1,14 1,15 1}
{0 spam,18 1,19 1,22 1,25 1,26 1,27 1,30 1}
{0 spam,20 1,21 1,23 1,24 1,28 1,29 1}
Testing.arff
@relation '_Users_Passionate_Desktop_TestingDiffThanTesting_Text-weka.filters.unsupervised.attribute.StringToWordVector-R1-W1000-prune-rate-1.0-N0-stemmerweka.core.stemmers.NullStemmer-M1-tokenizerweka.core.tokenizers.WordTokenizer -delimiters \" \\r\\n\\t.,;:\\\'\\\"()?!\"'
@attribute @@class@@ {dummy,ham,spam}
@attribute brazilian numeric
@attribute do numeric
@attribute in numeric
@attribute indigenous numeric
@attribute languages numeric
@attribute linguists numeric
@attribute on numeric
@attribute prepare numeric
@attribute research numeric
@attribute specialization numeric
@attribute to numeric
@attribute and numeric
@attribute be numeric
@attribute developed numeric
@attribute evaluation numeric
@attribute of numeric
@attribute program numeric
@attribute published numeric
@attribute reanalysis numeric
@attribute the numeric
@attribute will numeric
@data
{0 ham,1 1,3 1,4 1,5 1,10 1}
{0 ham,2 1,4 1,6 1,7 1,8 1,9 1,11 1}
{0 spam,12 1,15 1,16 1,18 1,19 1}
{0 spam,5 1,13 1,14 1,17 1,20 1,21 1}