using weka Filter in java code -


I have a problem in using weka api in java There are 41 features (or attributes) in my training and test dataset. I want to take only 25 specialties (for example 1,3,5,7,8,10 .....) and removing classifier and other features during training and testing. I have read the VICA's filter manual available here, but I did not understand how to use the filter in my problem. Can you please help me? How to write code for this situation Your suggestion / assistance will be highly appreciated.

My code is such ....

  import weka.classifiers.meta.filteredClassifier; Import weka.classifiers.trees.J48; Import weka.core.Instances; Import weka.filters.filter; Import weka.filters.unsupervised.attribute.Remove; Example train = ... example test = ... here I want to take only 25 out of 41 (i.e. column values). Classifier CFLs = New J48 (); Cls.buildClassifier (train); // Classification evaluation and print some statistics Evaluation Eval = new evaluation (train); Eval.evaluate model (CLS, exam); ......... <.....    

assume That's it, as you said:

  import weka.classifiers.meta.filteredClassifier; Import weka.classifiers.trees.J48; Import weka.core.Instances; Import weka.filters.filter; Import weka.filters.unsupervised.attribute.Remove; Instance train = ... instance test = ...   

Then you want to set the array of column indexes I'm assuming you are looping it or for some things , But I've manually added 6 indexes manually. So that you can get ideas.

  int [] indicesOfColumnsToUse = [1, 3,5,7,8,10];   

Then start and set up your removal filter (initialize it, then set column indices, then reverse your selection so that you delete those people you do not want , Then "Input" format "depending on your training data) Remove = Remove Remove (); remove.setAttributeIndices (indicesOfColumnsToUse); remove.setInvertSelection (correct); remove.setInputFormat (train) );

Then apply your removal to the training set < Pre> Instance Training Subset = Filter.useFilter (train, remove);

And then as you said, besides training the classifier on the subset that you just created :

  classifierfile cls = new J48 (); cls.buildClassifier (trainingSubset); // classification evaluation and print some statistics Evaluation Eval = new evaluation (train); Eval.evaluate model ( CLS, Examination);    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -