Example usage for weka.attributeSelection AttributeSelection setRanking

List of usage examples for weka.attributeSelection AttributeSelection setRanking

Introduction

In this page you can find the example usage for weka.attributeSelection AttributeSelection setRanking.

Prototype

public void setRanking(boolean r) 

Source Link

Document

produce a ranking (if possible with the set search and evaluator)

Usage

From source file:mlflex.WekaInMemoryLearner.java

License:Open Source License

@Override
protected ArrayList<String> SelectOrRankFeatures(ArrayList<String> algorithmParameters,
        DataInstanceCollection trainData, DataInstanceCollection dependentVariableInstances) throws Exception {
    ArrayList<String> dataPointNames = Lists.SortStringList(trainData.GetDataPointNames());

    FastVector attVector = GetAttributeVector(dependentVariableInstances, dataPointNames, trainData);
    Instances instances = GetInstances(dependentVariableInstances, attVector, trainData);

    AttributeSelection attsel = new AttributeSelection();
    ASEvaluation eval = GetAttributeEvaluator(algorithmParameters);
    ASSearch search = GetSearchMethod(algorithmParameters);
    attsel.setEvaluator(eval);// www .j  a  va 2 s . c  om
    attsel.setSearch(search);

    boolean isRanker = algorithmParameters.get(2).equals(Ranker.class.getName());

    if (isRanker)
        attsel.setRanking(true);

    attsel.SelectAttributes(instances);

    ArrayList<String> features = new ArrayList<String>();

    if (isRanker) {
        for (double[] rank : attsel.rankedAttributes())
            features.add(instances.attribute((int) rank[0]).name());
    } else {
        for (int i : attsel.selectedAttributes())
            features.add(instances.attribute(i).name());
    }

    instances = null;

    return features;
}