Weka Attribute Selected Classifier - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

Weka Attribute Selected Classifier

Demo Code



import weka.attributeSelection.CfsSubsetEval;
import weka.attributeSelection.GreedyStepwise;
import weka.classifiers.evaluation.Evaluation;
import weka.classifiers.meta.AttributeSelectedClassifier;
import weka.classifiers.trees.J48;
import weka.core.Instances;
import weka.core.Debug.Random;
import weka.core.converters.ConverterUtils.DataSource;


public class WekaAttributeSelectedClassifier {
    public static void main(String[] args) throws Exception {
        DataSource source = new DataSource(
                "bank-train.arff");
        Instances data = source.getDataSet(); 
        AttributeSelectedClassifier classifier = new AttributeSelectedClassifier();

        CfsSubsetEval eval = new CfsSubsetEval();
        GreedyStepwise search = new GreedyStepwise();
        search.setSearchBackwards(true);

        J48 base = new J48();
        classifier.setClassifier(base);//ww  w  .ja va  2 s .c o  m
        classifier.setEvaluator(eval);
        classifier.setSearch(search);

        // 10-fold cross-validation
        Evaluation evaluation = new Evaluation(data);
        evaluation.crossValidateModel(classifier, data, 10, new Random(1));
        System.out.println(evaluation.toSummaryString());
    }
}

Related Tutorials