Weka Development [4]-Feature Selection

Source: Internet
Author: User

 Feature selection, I am not familiar with this part, probably say, withattributeselection for feature selection, it needs to be set 3 Aspects, First: Class for attribute evaluation (self to attribute Evaluator ), second: the Way to search (self to weka See in the software, English search Method ), Third: It is the data set that you want to perform the feature selection. Finally call filter static method < Span style= "font-family: ' Times New Roman ';" >userfilter , feel the writing is nonsense, a look at the code will understand. The only thing worth saying is don't put attributeselection 's package was added incorrectly, There is a comment next to the code.

Another function lazy explanation (it is not I write), is basically self-explanatory, it is unlikely to read.

Package instancetest;

Import Java.io.FileReader;

Import Java.util.Random;

Import Weka.attributeSelection.CfsSubsetEval;

Import weka.attributeSelection.GreedyStepwise;

Import weka.classifiers.Evaluation;

Import Weka.classifiers.meta.AttributeSelectedClassifier;

Import weka.classifiers.trees.J48;

Import weka.core.Instances;

Import Weka.filters.Filter;

Import weka.filters.supervised.attribute.AttributeSelection;

Public class filtertest

{

Private Instances m_instances = null;

Public void getfileinstances (String fileName) throws Exception

{

FileReader frdata = new FileReader (fileName);

m_instances = new instances (frdata);

m_instances. Setclassindex ( m_instances. Numattributes ()-1);

}

Public void selectattusefilter () throws Exception

{

Attributeselection filter = new attributeselection (); //Package weka.filters.supervised.attribute!

Cfssubseteval eval = new cfssubseteval ();

Greedystepwise search = new greedystepwise ();

Filter.setevaluator (eval);

Filter.setsearch (search);

Filter.setinputformat ( m_instances );

System. out . println ( "number of instance attribute =" +m_instances. numattributes ());

Instances selectedins = Filter. Usefilter ( m_instances, filter);

System. out . println ( "Number of Selected instance attribute =" + selectedins.numattributes ());

}

Public void selectattusemc () throws Exception

{

Attributeselectedclassifier classifier = newattributeselectedclassifier ();

Cfssubseteval eval = new cfssubseteval ();

Greedystepwise search = new greedystepwise ();

J48 base = new J48 ();

Classifier.setclassifier (base);

Classifier.setevaluator (eval);

Classifier.setsearch (search);

//10-fold cross-validation

Evaluation Evaluation = new Evaluation ( m_instances );

Evaluation.crossvalidatemodel (classifier, m_instances, newRandom (1));

System. out . println (Evaluation.tosummarystring ());

}

Public static void main (string[] args) throws Exception

{

Filtertest filter = new filtertest ();

Filter.getfileinstances ( "F://program Files//weka-3-4//data//soybean.arff");

Filter.selectattusefilter ();

FILTER.SELECTATTUSEMC ();

}

}

Weka Development [4]-Feature Selection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.