Example usage for weka.filters.unsupervised.attribute RemoveUseless setInputFormat

List of usage examples for weka.filters.unsupervised.attribute RemoveUseless setInputFormat

Introduction

In this page you can find the example usage for weka.filters.unsupervised.attribute RemoveUseless setInputFormat.

Prototype

@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception 

Source Link

Document

Sets the format of the input instances.

Usage

From source file:com.deafgoat.ml.prognosticator.InstancesFilter.java

License:Apache License

/**
 * Applies a filter to remove useless attributes with a variance greater
 * than the specified value//from  ww  w  .  j  av a2 s.  c  om
 * 
 * @param variance
 *            The maximum variance for the attribute
 * @throws Exception
 *             If filter could not be applied
 */
public void removeUselessFilter(String variance) throws Exception {
    if (_logger.isDebugEnabled()) {
        _logger.debug("Applying remove useless filter");
    }
    // Might employ filtered classifier for production
    RemoveUseless ru = new RemoveUseless();
    String[] options = new String[2];
    options[0] = "-M";
    options[1] = variance;
    ru.setOptions(options);
    ru.setInputFormat(_instances);
    _instances = Filter.useFilter(_instances, ru);
}

From source file:graph.clustering.NodeClusterer.java

License:Apache License

private Instances preprocessNodesInfoInstances(Instances clusterTrainingSet) {
    String[] filterOptions = new String[10];
    filterOptions[0] = "-R"; // attribute indices
    filterOptions[1] = "first-last";
    filterOptions[2] = "-W"; // The number of words (per class if there is a
    // class attribute assigned) to attempt to
    // keep.//from  w ww .j  a  v a  2s  .  c  om
    filterOptions[3] = "1000";
    filterOptions[4] = "-prune-rate"; // periodical pruning
    filterOptions[5] = "-1.0";
    filterOptions[6] = "-N"; // 0=not normalize
    filterOptions[7] = "0";
    filterOptions[8] = "-M"; // The minimum term frequency
    filterOptions[9] = "1";

    SnowballStemmer stemmer = new SnowballStemmer();
    stemmer.setStemmer("english");
    WordTokenizer tokenizer = new WordTokenizer();

    StringToWordVector s2wFilterer = new StringToWordVector();
    try {
        s2wFilterer.setOptions(filterOptions);
        s2wFilterer.setStemmer(stemmer);
        s2wFilterer.setTokenizer(tokenizer);
        s2wFilterer.setInputFormat(clusterTrainingSet);
        clusterTrainingSet = Filter.useFilter(clusterTrainingSet, s2wFilterer);
    } catch (Exception e1) {
        System.out.println("Error in converting string into word vectors:");
        e1.printStackTrace();
    }

    RemoveUseless ruFilter = new RemoveUseless();
    try {
        ruFilter.setInputFormat(clusterTrainingSet);
        clusterTrainingSet = Filter.useFilter(clusterTrainingSet, ruFilter);
    } catch (Exception e1) {
        System.out.println("Error in removing useless terms:");
        e1.printStackTrace();
    }

    return clusterTrainingSet;
}

From source file:Helper.CustomFilter.java

public Instances removeAttribute(Instances structure) throws Exception {
    //NORMALIZE AND REMOVE USELESS ATTRIBUTES
    Normalize norm = new Normalize();
    norm.setInputFormat(structure);//from w w  w .  jav  a  2 s. co  m
    structure = Filter.useFilter(structure, norm);

    RemoveUseless ru = new RemoveUseless();
    ru.setInputFormat(structure);
    structure = Filter.useFilter(structure, ru);

    Ranker rank = new Ranker();
    InfoGainAttributeEval eval = new InfoGainAttributeEval();
    eval.buildEvaluator(structure);
    //END OF NORMALIZATION

    return structure;
}