All Downloads are FREE. Search and download functionalities are using the official Maven repository.

weka.attributeSelection.Ranker Maven / Gradle / Ivy

Go to download

The Waikato Environment for Knowledge Analysis (WEKA), a machine learning workbench. This version represents the developer version, the "bleeding edge" of development, you could say. New functionality gets added to this version.

There is a newer version: 3.9.6
Show newest version
/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see .
 */

/*
 *    Ranker.java
 *    Copyright (C) 1999-2012 University of Waikato, Hamilton, New Zealand
 *
 */

package weka.attributeSelection;

import java.util.Collections;
import java.util.Enumeration;
import java.util.Vector;

import weka.core.Instances;
import weka.core.Option;
import weka.core.OptionHandler;
import weka.core.Range;
import weka.core.RevisionUtils;
import weka.core.Utils;

/**
 *  Ranker : 
*
* Ranks attributes by their individual evaluations. Use in conjunction with * attribute evaluators (ReliefF, GainRatio, Entropy etc).
*

* * * Valid options are: *

* *

 * -P <start set>
 *  Specify a starting set of attributes.
 *  Eg. 1,3,5-7.
 *  Any starting attributes specified are
 *  ignored during the ranking.
 * 
* *
 * -T <threshold>
 *  Specify a theshold by which attributes
 *  may be discarded from the ranking.
 * 
* *
 * -N <num to select>
 *  Specify number of attributes to select
 * 
* * * * @author Mark Hall ([email protected]) * @version $Revision: 15519 $ */ public class Ranker extends ASSearch implements RankedOutputSearch, StartSetHandler, OptionHandler { /** for serialization */ static final long serialVersionUID = -9086714848510751934L; /** Holds the starting set as an array of attributes */ private int[] m_starting; /** Holds the start set for the search as a range */ private Range m_startRange; /** Holds the ordered list of attributes */ private int[] m_attributeList; /** Holds the list of attribute merit scores */ private double[] m_attributeMerit; /** Data has class attribute---if unsupervised evaluator then no class */ private boolean m_hasClass; /** Class index of the data if supervised evaluator */ private int m_classIndex; /** The number of attribtes */ private int m_numAttribs; /** * A threshold by which to discard attributes---used by the AttributeSelection * module */ private double m_threshold; /** * The number of attributes to select. -1 indicates that all attributes are to * be retained. Has precedence over m_threshold */ private int m_numToSelect = -1; /** Used to compute the number to select */ private int m_calculatedNumToSelect = -1; /** * Returns a string describing this search method * * @return a description of the search suitable for displaying in the * explorer/experimenter gui */ public String globalInfo() { return "Ranker : \n\nRanks attributes by their individual evaluations. " + "Use in conjunction with attribute evaluators (ReliefF, GainRatio, " + "Entropy etc).\n"; } /** * Constructor */ public Ranker() { resetOptions(); } /** * Returns the tip text for this property * * @return tip text for this property suitable for displaying in the * explorer/experimenter gui */ public String numToSelectTipText() { return "Specify the number of attributes to retain. The default value " + "(-1) indicates that all attributes are to be retained. Use either " + "this option or a threshold to reduce the attribute set."; } /** * Specify the number of attributes to select from the ranked list. -1 * indicates that all attributes are to be retained. * * @param n the number of attributes to retain */ @Override public void setNumToSelect(int n) { m_numToSelect = n; } /** * Gets the number of attributes to be retained. * * @return the number of attributes to retain */ @Override public int getNumToSelect() { return m_numToSelect; } /** * Gets the calculated number to select. This might be computed from a * threshold, or if < 0 is set as the number to select then it is set to the * number of attributes in the (transformed) data. * * @return the calculated number of attributes to select */ @Override public int getCalculatedNumToSelect() { if (m_numToSelect >= 0) { m_calculatedNumToSelect = m_numToSelect > m_attributeMerit.length ? m_attributeMerit.length : m_numToSelect; } return m_calculatedNumToSelect; } /** * Returns the tip text for this property * * @return tip text for this property suitable for displaying in the * explorer/experimenter gui */ public String thresholdTipText() { return "Set threshold by which attributes can be discarded. Default value " + "results in no attributes being discarded. Use either this option or " + "numToSelect to reduce the attribute set."; } /** * Set the threshold by which the AttributeSelection module can discard * attributes. * * @param threshold the threshold. */ @Override public void setThreshold(double threshold) { m_threshold = threshold; } /** * Returns the threshold so that the AttributeSelection module can discard * attributes from the ranking. */ @Override public double getThreshold() { return m_threshold; } /** * Returns the tip text for this property * * @return tip text for this property suitable for displaying in the * explorer/experimenter gui */ public String generateRankingTipText() { return "A constant option. Ranker is only capable of generating " + " attribute rankings."; } /** * This is a dummy set method---Ranker is ONLY capable of producing a ranked * list of attributes for attribute evaluators. * * @param doRank this parameter is N/A and is ignored */ @Override public void setGenerateRanking(boolean doRank) { } /** * This is a dummy method. Ranker can ONLY be used with attribute evaluators * and as such can only produce a ranked list of attributes * * @return true all the time. */ @Override public boolean getGenerateRanking() { return true; } /** * Returns the tip text for this property * * @return tip text for this property suitable for displaying in the * explorer/experimenter gui */ public String startSetTipText() { return "Specify a set of attributes to ignore. " + " When generating the ranking, Ranker will not evaluate the attributes " + " in this list. " + "This is specified as a comma " + "separated list off attribute indexes starting at 1. It can include " + "ranges. Eg. 1,2,5-9,17."; } /** * Sets a starting set of attributes for the search. It is the search method's * responsibility to report this start set (if any) in its toString() method. * * @param startSet a string containing a list of attributes (and or ranges), * eg. 1,2,6,10-15. * @throws Exception if start set can't be set. */ @Override public void setStartSet(String startSet) throws Exception { m_startRange.setRanges(startSet); } /** * Returns a list of attributes (and or attribute ranges) as a String * * @return a list of attributes (and or attribute ranges) */ @Override public String getStartSet() { return m_startRange.getRanges(); } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. **/ @Override public Enumeration




© 2015 - 2024 Weber Informatics LLC | Privacy Policy