Package weka.attributeSelection
Class AttributeSelection
java.lang.Object
weka.attributeSelection.AttributeSelection
- All Implemented Interfaces:
Serializable
,RevisionHandler
Attribute selection class. Takes the name of a search class and an evaluation
class on the command line.
Valid options are:
-h
Display help. -i <name of input file>
Specify the training data file. -c <class index>
The index of the attribute to use as the class. -s <search method>
The full class name of the search method followed by search method options (if any).
Eg. -s "weka.attributeSelection.BestFirst -N 10" -x <number of folds>
Perform a cross validation. -n <random number seed>
Specify a random number seed. Use in conjuction with -x. (Default = 1). ------------------------------------------------------------------------ Example usage as the main of an attribute evaluator (called FunkyEvaluator):
Display help. -i <name of input file>
Specify the training data file. -c <class index>
The index of the attribute to use as the class. -s <search method>
The full class name of the search method followed by search method options (if any).
Eg. -s "weka.attributeSelection.BestFirst -N 10" -x <number of folds>
Perform a cross validation. -n <random number seed>
Specify a random number seed. Use in conjuction with -x. (Default = 1). ------------------------------------------------------------------------ Example usage as the main of an attribute evaluator (called FunkyEvaluator):
public static void main(String[] args) { runEvaluator(new FunkyEvaluator(), args); }------------------------------------------------------------------------
- Version:
- $Revision: 11942 $
- Author:
- Mark Hall (mhall@cs.waikato.ac.nz)
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionPerform a cross validation for attribute selection.returns a string summarizing the results of repeated attribute selection runs on splits of a dataset.Returns the revision string.static void
Main method for testing this class.int
Return the number of attributes selected from the most recent run of attribute selectiondouble[][]
get the final ranking of the attributes.reduce the dimensionality of a single instance to include only those attributes chosen by the last run of attribute selection.reduce the dimensionality of a set of instances to include only those attributes chosen by the last run of attribute selection.static String
SelectAttributes
(ASEvaluation ASEvaluator, String[] options) Perform attribute selection with a particular evaluator and a set of options specifying search method and input file etc.static String
SelectAttributes
(ASEvaluation ASEvaluator, String[] options, Instances train) Perform attribute selection with a particular evaluator and a set of options specifying search method and options for the search method and evaluator.void
SelectAttributes
(Instances data) Perform attribute selection on the supplied training instances.void
selectAttributesCVSplit
(Instances split) Select attributes for a split of the data.int[]
get the final selected set of attributes.void
setEvaluator
(ASEvaluation evaluator) set the attribute/subset evaluatorvoid
setFolds
(int folds) set the number of folds for cross validationvoid
setRanking
(boolean r) produce a ranking (if possible with the set search and evaluator)void
set the search methodvoid
setSeed
(int s) set the seed for use in cross validationvoid
setXval
(boolean x) do a cross validationget a description of the attribute selectionvoid
updateStatsForModelCVSplit
(Instances split, ASEvaluation evaluator, ASSearch search, int[] attributeSet, boolean doRank) Update the attribute selection stats for a cross-validation fold of the data.
-
Constructor Details
-
AttributeSelection
public AttributeSelection()constructor. Sets defaults for each member varaible. Default attribute evaluator is CfsSubsetEval; default search method is BestFirst.
-
-
Method Details
-
numberAttributesSelected
Return the number of attributes selected from the most recent run of attribute selection- Returns:
- the number of attributes selected
- Throws:
Exception
-
selectedAttributes
get the final selected set of attributes.- Returns:
- an array of attribute indexes
- Throws:
Exception
- if attribute selection has not been performed yet
-
rankedAttributes
get the final ranking of the attributes.- Returns:
- a two dimensional array of ranked attribute indexes and their associated merit scores as doubles.
- Throws:
Exception
- if a ranking has not been produced
-
setEvaluator
set the attribute/subset evaluator- Parameters:
evaluator
- the evaluator to use
-
setSearch
set the search method- Parameters:
search
- the search method to use
-
setFolds
public void setFolds(int folds) set the number of folds for cross validation- Parameters:
folds
- the number of folds
-
setRanking
public void setRanking(boolean r) produce a ranking (if possible with the set search and evaluator)- Parameters:
r
- true if a ranking is to be produced
-
setXval
public void setXval(boolean x) do a cross validation- Parameters:
x
- true if a cross validation is to be performed
-
setSeed
public void setSeed(int s) set the seed for use in cross validation- Parameters:
s
- the seed
-
toResultsString
get a description of the attribute selection- Returns:
- a String describing the results of attribute selection
-
reduceDimensionality
reduce the dimensionality of a set of instances to include only those attributes chosen by the last run of attribute selection.- Parameters:
in
- the instances to be reduced- Returns:
- a dimensionality reduced set of instances
- Throws:
Exception
- if the instances can't be reduced
-
reduceDimensionality
reduce the dimensionality of a single instance to include only those attributes chosen by the last run of attribute selection.- Parameters:
in
- the instance to be reduced- Returns:
- a dimensionality reduced instance
- Throws:
Exception
- if the instance can't be reduced
-
SelectAttributes
Perform attribute selection with a particular evaluator and a set of options specifying search method and input file etc.- Parameters:
ASEvaluator
- an evaluator objectoptions
- an array of options, not only for the evaluator but also the search method (if any) and an input data file- Returns:
- the results of attribute selection as a String
- Throws:
Exception
- if no training file is set
-
CVResultsString
returns a string summarizing the results of repeated attribute selection runs on splits of a dataset.- Returns:
- a summary of attribute selection results
- Throws:
Exception
- if no attribute selection has been performed.
-
selectAttributesCVSplit
Select attributes for a split of the data. Calling this function updates the statistics on attribute selection. CVResultsString() returns a string summarizing the results of repeated calls to this function. Assumes that splits are from the same dataset--- ie. have the same number and types of attributes as previous splits.- Parameters:
split
- the instances to select attributes from- Throws:
Exception
- if an error occurs
-
updateStatsForModelCVSplit
public void updateStatsForModelCVSplit(Instances split, ASEvaluation evaluator, ASSearch search, int[] attributeSet, boolean doRank) throws Exception Update the attribute selection stats for a cross-validation fold of the data.- Parameters:
split
- the instances in this split/fold of the dataevaluator
- the evaluator that was usedsearch
- the search that was usedattributeSet
- the final subset produced for the splitdoRank
- whether to produce a ranking- Throws:
Exception
- if a problem occurs
-
CrossValidateAttributes
Perform a cross validation for attribute selection. With subset evaluators the number of times each attribute is selected over the cross validation is reported. For attribute evaluators, the average merit and average ranking + std deviation is reported for each attribute.- Returns:
- the results of cross validation as a String
- Throws:
Exception
- if an error occurs during cross validation
-
SelectAttributes
Perform attribute selection on the supplied training instances.- Parameters:
data
- the instances to select attributes from- Throws:
Exception
- if there is a problem during selection
-
SelectAttributes
public static String SelectAttributes(ASEvaluation ASEvaluator, String[] options, Instances train) throws Exception Perform attribute selection with a particular evaluator and a set of options specifying search method and options for the search method and evaluator.- Parameters:
ASEvaluator
- an evaluator objectoptions
- an array of options, not only for the evaluator but also the search method (if any) and an input data filetrain
- the input instances- Returns:
- the results of attribute selection as a String
- Throws:
Exception
- if incorrect options are supplied
-
main
Main method for testing this class.- Parameters:
args
- the options
-
getRevision
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Returns:
- the revision
-