public class GridSearch extends RandomizableSingleClassifierEnhancer implements AdditionalMeasureProducer, Summarizable
-E <CC|RMSE|RRSE|MAE|RAE|COMB|ACC|KAP> Determines the parameter used for evaluation: CC = Correlation coefficient RMSE = Root mean squared error RRSE = Root relative squared error MAE = Mean absolute error RAE = Root absolute error COMB = Combined = (1-abs(CC)) + RRSE + RAE ACC = Accuracy KAP = Kappa (default: CC)
-y-property <option> The Y option to test (without leading dash). (default: classifier.ridge)
-y-min <num> The minimum for Y. (default: -10)
-y-max <num> The maximum for Y. (default: +5)
-y-step <num> The step size for Y. (default: 1)
-y-base <num> The base for Y. (default: 10)
-y-expression <expr> The expression for Y. Available parameters: BASE FROM TO STEP I - the current iteration value (from 'FROM' to 'TO' with stepsize 'STEP') (default: 'pow(BASE,I)')
-filter <filter specification> The filter to use (on X axis). Full classname of filter to include, followed by scheme options. (default: weka.filters.supervised.attribute.PLSFilter)
-x-property <option> The X option to test (without leading dash). (default: filter.numComponents)
-x-min <num> The minimum for X. (default: +5)
-x-max <num> The maximum for X. (default: +20)
-x-step <num> The step size for X. (default: 1)
-x-base <num> The base for X. (default: 10)
-x-expression <expr> The expression for the X value. Available parameters: BASE MIN MAX STEP I - the current iteration value (from 'FROM' to 'TO' with stepsize 'STEP') (default: 'pow(BASE,I)')
-extend-grid Whether the grid can be extended. (default: no)
-max-grid-extensions <num> The maximum number of grid extensions (-1 is unlimited). (default: 3)
-sample-size <num> The size (in percent) of the sample to search the inital grid with. (default: 100)
-traversal <ROW-WISE|COLUMN-WISE> The type of traversal for the grid. (default: COLUMN-WISE)
-log-file <filename> The log file to log the messages to. (default: none)
-S <num> Random number seed. (default 1)
-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.functions.LinearRegression)
Options specific to classifier weka.classifiers.functions.LinearRegression:
-D Produce debugging output. (default no debugging output)
-S <number of selection method> Set the attribute selection method to use. 1 = None, 2 = Greedy. (default 0 = M5' method)
-C Do not try to eliminate colinear attributes.
-R <double> Set ridge parameter (default 1.0e-8).
Options specific to filter weka.filters.supervised.attribute.PLSFilter ('-filter'):
-D Turns on output of debugging information.
-C <num> The number of components to compute. (default: 20)
-U Updates the class attribute as well. (default: off)
-M Turns replacing of missing values on. (default: off)
-A <SIMPLS|PLS1> The algorithm to use. (default: PLS1)
-P <none|center|standardize> The type of preprocessing that is applied to the data. (default: center)Examples:
weka.filters.AllFilter
since we
don't need any special data processing and we don't optimize the
filter in this case (data gets always passed through filter!).weka.classifiers.functions.SMO
as classifier
with weka.classifiers.functions.supportVector.RBFKernel
as kernel.
weka.filters.supervised.attribute.PLSFilter
.weka.classifiers.functions.LinearRegression
as
classifier and use no attribute selection and no elimination of
colinear attributes.PLSFilter
,
LinearRegression
,
NumericCleaner
,
Serialized FormModifier and Type | Class and Description |
---|---|
protected class |
GridSearch.Grid
for generating the parameter pairs in a grid
|
protected class |
GridSearch.Performance
A helper class for storing the performance of a values-pair.
|
protected class |
GridSearch.PerformanceCache
Represents a simple cache for performance objects.
|
protected class |
GridSearch.PerformanceComparator
A concrete Comparator for the Performance class.
|
protected class |
GridSearch.PerformanceTable
Generates a 2-dim array for the performances from a grid for a certain
type.
|
protected class |
GridSearch.PointDouble
a serializable version of Point2D.Double
|
protected class |
GridSearch.PointInt
a serializable version of Point
|
Modifier and Type | Field and Description |
---|---|
static int |
EVALUATION_ACC
evaluation via: Accuracy
|
static int |
EVALUATION_CC
evaluation via: Correlation coefficient
|
static int |
EVALUATION_COMBINED
evaluation via: Combined = (1-CC) + RRSE + RAE
|
static int |
EVALUATION_KAPPA
evaluation via: kappa statistic
|
static int |
EVALUATION_MAE
evaluation via: Mean absolute error
|
static int |
EVALUATION_RAE
evaluation via: Relative absolute error
|
static int |
EVALUATION_RMSE
evaluation via: Root mean squared error
|
static int |
EVALUATION_RRSE
evaluation via: Root relative squared error
|
protected Classifier |
m_BestClassifier
the Classifier with the best setup
|
protected Filter |
m_BestFilter
the Filter with the best setup
|
protected GridSearch.PerformanceCache |
m_Cache
the cache for points in the grid that got calculated
|
protected Instances |
m_Data
the training data
|
protected int |
m_Evaluation
the type of evaluation
|
protected Filter |
m_Filter
the Filter
|
protected GridSearch.Grid |
m_Grid
the value-pairs grid
|
protected int |
m_GridExtensionsPerformed
the number of extensions performed
|
protected boolean |
m_GridIsExtendable
whether the grid can be extended
|
protected File |
m_LogFile
the log file to use
|
protected int |
m_MaxGridExtensions
maximum number of grid extensions (-1 means unlimited)
|
protected double |
m_SampleSize
the sample size to search the initial grid with
|
protected int |
m_Traversal
the traversal
|
protected boolean |
m_UniformPerformance
whether all performances in the grid are the same
|
protected GridSearch.PointDouble |
m_Values
the best values
|
protected double |
m_X_Base
the base for
|
protected String |
m_X_Expression
The expression for the X property.
|
protected double |
m_X_Max
the maximum of X
|
protected double |
m_X_Min
the minimum of X
|
protected String |
m_X_Property
the X option to work on (without leading dash, preceding 'classifier.'
means to set the option for the classifier 'filter.' for the filter)
|
protected double |
m_X_Step
the step size of
|
protected double |
m_Y_Base
the base for Y
|
protected String |
m_Y_Expression
The expression for the Y property.
|
protected double |
m_Y_Max
the maximum of Y
|
protected double |
m_Y_Min
the minimum of Y
|
protected String |
m_Y_Property
the Y option to work on (without leading dash, preceding 'classifier.'
means to set the option for the classifier 'filter.' for the filter)
|
protected double |
m_Y_Step
the step size of Y
|
static String |
PREFIX_CLASSIFIER
the prefix to indicate that the option is for the classifier
|
static String |
PREFIX_FILTER
the prefix to indicate that the option is for the filter
|
static Tag[] |
TAGS_EVALUATION
evaluation
|
static Tag[] |
TAGS_TRAVERSAL
traversal
|
static int |
TRAVERSAL_BY_COLUMN
column-wise grid traversal
|
static int |
TRAVERSAL_BY_ROW
row-wise grid traversal
|
m_Seed
m_Classifier
m_Debug
Constructor and Description |
---|
GridSearch()
the default constructor
|
Modifier and Type | Method and Description |
---|---|
void |
buildClassifier(Instances data)
builds the classifier
|
double |
classifyInstance(Instance instance)
Classifies the given instance.
|
protected String |
defaultClassifierString()
String describing default classifier.
|
protected GridSearch.PointDouble |
determineBestInGrid(GridSearch.Grid grid,
Instances inst,
int cv)
determines the best values-pair for the given grid, using CV with
specified number of folds.
|
Enumeration |
enumerateMeasures()
Returns an enumeration of the measure names.
|
protected double |
evaluate(double value,
boolean isX)
evalutes the expression for the current iteration
|
String |
evaluationTipText()
Returns the tip text for this property
|
String |
filterTipText()
Returns the tip text for this property
|
protected GridSearch.PointDouble |
findBest()
returns the best values-pair in the grid
|
Classifier |
getBestClassifier()
returns the best Classifier setup
|
Filter |
getBestFilter()
returns the best filter setup
|
Capabilities |
getCapabilities()
Returns default capabilities of the classifier.
|
SelectedTag |
getEvaluation()
Gets the criterion used for evaluating the classifier performance.
|
Filter |
getFilter()
Get the kernel filter.
|
int |
getGridExtensionsPerformed()
returns the number of grid extensions that took place during the search
(only applicable if the grid was extendable).
|
boolean |
getGridIsExtendable()
Get whether the grid can be extended dynamically.
|
File |
getLogFile()
Gets current log file.
|
int |
getMaxGridExtensions()
Gets the maximum number of grid extensions, -1 for unlimited.
|
double |
getMeasure(String measureName)
Returns the value of the named measure
|
String[] |
getOptions()
returns the options of the current setup
|
String |
getRevision()
Returns the revision string.
|
double |
getSampleSizePercent()
Gets the sample size for the initial grid search.
|
SelectedTag |
getTraversal()
Gets the type of traversal for the grid.
|
GridSearch.PointDouble |
getValues()
returns the parameter pair that was found to work best
|
double |
getXBase()
Get the value of the base for X.
|
String |
getXExpression()
Get the expression for the X value.
|
double |
getXMax()
Get the value of the Maximum of X.
|
double |
getXMin()
Get the value of the minimum of X.
|
String |
getXProperty()
Get the X property to test (normally the filter).
|
double |
getXStep()
Get the value of the step size for X.
|
double |
getYBase()
Get the value of the base for Y.
|
String |
getYExpression()
Get the expression for the Y value.
|
double |
getYMax()
Get the value of the Maximum of Y.
|
double |
getYMin()
Get the value of the minimum of Y.
|
String |
getYProperty()
Get the Y property (normally the classifier).
|
double |
getYStep()
Get the value of the step size for Y.
|
String |
globalInfo()
Returns a string describing classifier
|
String |
gridIsExtendableTipText()
Returns the tip text for this property
|
Enumeration |
listOptions()
Gets an enumeration describing the available options.
|
protected void |
log(String message)
prints the specified message to stdout if debug is on and can also dump
the message to a log file
|
protected void |
log(String message,
boolean onlyLog)
prints the specified message to stdout if debug is on and can also dump
the message to a log file
|
String |
logFileTipText()
Returns the tip text for this property
|
protected void |
logPerformances(GridSearch.Grid grid,
Vector performances)
aligns all performances in the grid and prints those tables to the log
file.
|
protected String |
logPerformances(GridSearch.Grid grid,
Vector<GridSearch.Performance> performances,
Tag type)
generates a table string for all the performances in the grid and returns
that.
|
static void |
main(String[] args)
Main method for running this classifier from commandline.
|
String |
maxGridExtensionsTipText()
Returns the tip text for this property
|
String |
sampleSizePercentTipText()
Returns the tip text for this property
|
void |
setClassifier(Classifier newClassifier)
Set the base learner.
|
void |
setEvaluation(SelectedTag value)
Sets the criterion to use for evaluating the classifier performance.
|
void |
setFilter(Filter value)
Set the kernel filter (only used for setup).
|
void |
setGridIsExtendable(boolean value)
Set whether the grid can be extended dynamically.
|
void |
setLogFile(File value)
Sets the log file to use.
|
void |
setMaxGridExtensions(int value)
Sets the maximum number of grid extensions, -1 for unlimited.
|
void |
setOptions(String[] options)
Parses the options for this object.
|
void |
setSampleSizePercent(double value)
Sets the sample size for the initial grid search.
|
void |
setTraversal(SelectedTag value)
Sets the type of traversal for the grid.
|
protected Object |
setup(Object original,
double valueX,
double valueY)
returns a fully configures object (a copy of the provided one)
|
protected Object |
setValue(Object o,
String path,
double value)
tries to set the value as double, integer (just casts it to int!) or
boolean (false if 0, otherwise true) in the object according to the
specified path.
|
void |
setXBase(double value)
Set the value of the base for X.
|
void |
setXExpression(String value)
Set the expression for the X value.
|
void |
setXMax(double value)
Set the value of the Maximum of X.
|
void |
setXMin(double value)
Set the value of the minimum of X.
|
void |
setXProperty(String value)
Set the X property.
|
void |
setXStep(double value)
Set the value of the step size for X.
|
void |
setYBase(double value)
Set the value of the base for Y.
|
void |
setYExpression(String value)
Set the expression for the Y value.
|
void |
setYMax(double value)
Set the value of the Maximum of Y.
|
void |
setYMin(double value)
Set the value of the minimum of Y.
|
void |
setYProperty(String value)
Set the Y property (normally the classifier).
|
void |
setYStep(double value)
Set the value of the step size for Y.
|
String |
toString()
returns a string representation of the classifier
|
String |
toSummaryString()
Returns a string that summarizes the object.
|
String |
traversalTipText()
Returns the tip text for this property
|
protected String[] |
updateOption(String[] options,
String option,
String value)
replaces the current option in the options array with a new value
|
String |
XBaseTipText()
Returns the tip text for this property
|
String |
XExpressionTipText()
Returns the tip text for this property
|
String |
XMaxTipText()
Returns the tip text for this property
|
String |
XMinTipText()
Returns the tip text for this property
|
String |
XPropertyTipText()
Returns the tip text for this property
|
String |
XStepTipText()
Returns the tip text for this property
|
String |
YBaseTipText()
Returns the tip text for this property
|
String |
YExpressionTipText()
Returns the tip text for this property
|
String |
YMaxTipText()
Returns the tip text for this property
|
String |
YMinTipText()
Returns the tip text for this property
|
String |
YPropertyTipText()
Returns the tip text for this property
|
String |
YStepTipText()
Returns the tip text for this property
|
getSeed, seedTipText, setSeed
classifierTipText, getClassifier, getClassifierSpec
debugTipText, distributionForInstance, forName, getDebug, makeCopies, makeCopy, runClassifier, setDebug
public static final int EVALUATION_CC
public static final int EVALUATION_RMSE
public static final int EVALUATION_RRSE
public static final int EVALUATION_MAE
public static final int EVALUATION_RAE
public static final int EVALUATION_COMBINED
public static final int EVALUATION_ACC
public static final int EVALUATION_KAPPA
public static final Tag[] TAGS_EVALUATION
public static final int TRAVERSAL_BY_ROW
public static final int TRAVERSAL_BY_COLUMN
public static final Tag[] TAGS_TRAVERSAL
public static final String PREFIX_CLASSIFIER
public static final String PREFIX_FILTER
protected Filter m_Filter
protected Filter m_BestFilter
protected Classifier m_BestClassifier
protected GridSearch.PointDouble m_Values
protected int m_Evaluation
protected String m_Y_Property
protected double m_Y_Min
protected double m_Y_Max
protected double m_Y_Step
protected double m_Y_Base
protected String m_Y_Expression
MathematicalExpression
,
MathExpression
protected String m_X_Property
protected double m_X_Min
protected double m_X_Max
protected double m_X_Step
protected double m_X_Base
protected String m_X_Expression
MathematicalExpression
,
MathExpression
protected boolean m_GridIsExtendable
protected int m_MaxGridExtensions
protected int m_GridExtensionsPerformed
protected double m_SampleSize
protected int m_Traversal
protected File m_LogFile
protected GridSearch.Grid m_Grid
protected Instances m_Data
protected GridSearch.PerformanceCache m_Cache
protected boolean m_UniformPerformance
public String globalInfo()
protected String defaultClassifierString()
defaultClassifierString
in class SingleClassifierEnhancer
public Enumeration listOptions()
listOptions
in interface OptionHandler
listOptions
in class RandomizableSingleClassifierEnhancer
public String[] getOptions()
getOptions
in interface OptionHandler
getOptions
in class RandomizableSingleClassifierEnhancer
public void setOptions(String[] options) throws Exception
-E <CC|RMSE|RRSE|MAE|RAE|COMB|ACC|KAP> Determines the parameter used for evaluation: CC = Correlation coefficient RMSE = Root mean squared error RRSE = Root relative squared error MAE = Mean absolute error RAE = Root absolute error COMB = Combined = (1-abs(CC)) + RRSE + RAE ACC = Accuracy KAP = Kappa (default: CC)
-y-property <option> The Y option to test (without leading dash). (default: classifier.ridge)
-y-min <num> The minimum for Y. (default: -10)
-y-max <num> The maximum for Y. (default: +5)
-y-step <num> The step size for Y. (default: 1)
-y-base <num> The base for Y. (default: 10)
-y-expression <expr> The expression for Y. Available parameters: BASE FROM TO STEP I - the current iteration value (from 'FROM' to 'TO' with stepsize 'STEP') (default: 'pow(BASE,I)')
-filter <filter specification> The filter to use (on X axis). Full classname of filter to include, followed by scheme options. (default: weka.filters.supervised.attribute.PLSFilter)
-x-property <option> The X option to test (without leading dash). (default: filter.numComponents)
-x-min <num> The minimum for X. (default: +5)
-x-max <num> The maximum for X. (default: +20)
-x-step <num> The step size for X. (default: 1)
-x-base <num> The base for X. (default: 10)
-x-expression <expr> The expression for the X value. Available parameters: BASE MIN MAX STEP I - the current iteration value (from 'FROM' to 'TO' with stepsize 'STEP') (default: 'pow(BASE,I)')
-extend-grid Whether the grid can be extended. (default: no)
-max-grid-extensions <num> The maximum number of grid extensions (-1 is unlimited). (default: 3)
-sample-size <num> The size (in percent) of the sample to search the inital grid with. (default: 100)
-traversal <ROW-WISE|COLUMN-WISE> The type of traversal for the grid. (default: COLUMN-WISE)
-log-file <filename> The log file to log the messages to. (default: none)
-S <num> Random number seed. (default 1)
-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.functions.LinearRegression)
Options specific to classifier weka.classifiers.functions.LinearRegression:
-D Produce debugging output. (default no debugging output)
-S <number of selection method> Set the attribute selection method to use. 1 = None, 2 = Greedy. (default 0 = M5' method)
-C Do not try to eliminate colinear attributes.
-R <double> Set ridge parameter (default 1.0e-8).
Options specific to filter weka.filters.supervised.attribute.PLSFilter ('-filter'):
-D Turns on output of debugging information.
-C <num> The number of components to compute. (default: 20)
-U Updates the class attribute as well. (default: off)
-M Turns replacing of missing values on. (default: off)
-A <SIMPLS|PLS1> The algorithm to use. (default: PLS1)
-P <none|center|standardize> The type of preprocessing that is applied to the data. (default: center)
setOptions
in interface OptionHandler
setOptions
in class RandomizableSingleClassifierEnhancer
options
- the options to useException
- if setting of options failspublic void setClassifier(Classifier newClassifier)
setClassifier
in class SingleClassifierEnhancer
newClassifier
- the classifier to use.public String filterTipText()
public void setFilter(Filter value)
value
- the kernel filter.public Filter getFilter()
public String evaluationTipText()
public void setEvaluation(SelectedTag value)
value
- .the evaluation criterionpublic SelectedTag getEvaluation()
public String YPropertyTipText()
public String getYProperty()
public void setYProperty(String value)
value
- the Y property.public String YMinTipText()
public double getYMin()
public void setYMin(double value)
value
- Value to use as minimum of Y.public String YMaxTipText()
public double getYMax()
public void setYMax(double value)
value
- Value to use as Maximum of Y.public String YStepTipText()
public double getYStep()
public void setYStep(double value)
value
- Value to use as the step size for Y.public String YBaseTipText()
public double getYBase()
public void setYBase(double value)
value
- Value to use as the base for Y.public String YExpressionTipText()
public String getYExpression()
public void setYExpression(String value)
value
- Expression for the Y value.public String XPropertyTipText()
public String getXProperty()
public void setXProperty(String value)
value
- the X property.public String XMinTipText()
public double getXMin()
public void setXMin(double value)
value
- Value to use as minimum of X.public String XMaxTipText()
public double getXMax()
public void setXMax(double value)
value
- Value to use as Maximum of X.public String XStepTipText()
public double getXStep()
public void setXStep(double value)
value
- Value to use as the step size for X.public String XBaseTipText()
public double getXBase()
public void setXBase(double value)
value
- Value to use as the base for X.public String XExpressionTipText()
public String getXExpression()
public void setXExpression(String value)
value
- Expression for the X value.public String gridIsExtendableTipText()
public boolean getGridIsExtendable()
public void setGridIsExtendable(boolean value)
value
- whether the grid can be extended dynamically.public String maxGridExtensionsTipText()
public int getMaxGridExtensions()
public void setMaxGridExtensions(int value)
value
- the maximum of grid extensions.public String sampleSizePercentTipText()
public double getSampleSizePercent()
public void setSampleSizePercent(double value)
value
- the sample size for the initial grid search.public String traversalTipText()
public void setTraversal(SelectedTag value)
value
- the traversal typepublic SelectedTag getTraversal()
public String logFileTipText()
public File getLogFile()
public void setLogFile(File value)
value
- the log file.public Filter getBestFilter()
public Classifier getBestClassifier()
public Enumeration enumerateMeasures()
enumerateMeasures
in interface AdditionalMeasureProducer
public double getMeasure(String measureName)
getMeasure
in interface AdditionalMeasureProducer
measureName
- the name of the measure to query for its valuepublic GridSearch.PointDouble getValues()
public int getGridExtensionsPerformed()
getGridIsExtendable()
public Capabilities getCapabilities()
getCapabilities
in interface CapabilitiesHandler
getCapabilities
in class SingleClassifierEnhancer
Capabilities
protected void log(String message)
message
- the message to print or store in a log fileprotected void log(String message, boolean onlyLog)
message
- the message to print or store in a log fileonlyLog
- if true the message will only be put into the log file
but not to stdoutprotected String[] updateOption(String[] options, String option, String value) throws Exception
options
- the current optionsoption
- the option to set a new value forvalue
- the value to setException
- if something goes wrongprotected double evaluate(double value, boolean isX)
value
- the current iteration value (from 'min' to 'max' with
stepsize 'step')isX
- true if X is to be evaluated otherwise Yprotected Object setValue(Object o, String path, double value) throws Exception
o
- the object to modifypath
- the property pathvalue
- the value to setException
- if neither double nor int could be setprotected Object setup(Object original, double valueX, double valueY) throws Exception
original
- the object to create a copy from and set the parametersvalueX
- the current iteration value for XvalueY
- the current iteration value for YException
- if setup failsprotected String logPerformances(GridSearch.Grid grid, Vector<GridSearch.Performance> performances, Tag type)
grid
- the current grid to align the performances toperformances
- the performances to aligntype
- the type of performanceprotected void logPerformances(GridSearch.Grid grid, Vector performances)
grid
- the current grid to align the performances toperformances
- the performances to alignprotected GridSearch.PointDouble determineBestInGrid(GridSearch.Grid grid, Instances inst, int cv) throws Exception
grid
- the grid to work oninst
- the data to work withcv
- the number of folds for the cross-validationException
- if setup or training failsprotected GridSearch.PointDouble findBest() throws Exception
Exception
- if something goes wrongpublic void buildClassifier(Instances data) throws Exception
buildClassifier
in class Classifier
data
- the training instancesException
- if something goes wrongpublic double classifyInstance(Instance instance) throws Exception
classifyInstance
in class Classifier
instance
- the test instanceException
- if classification can't be done successfullypublic String toString()
public String toSummaryString()
toSummaryString
in interface Summarizable
public String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class Classifier
public static void main(String[] args)
args
- the optionsCopyright © 2015 University of Waikato, Hamilton, NZ. All rights reserved.