Package weka.classifiers
Class GroupedBinnedNumericClassCrossValidationFoldGenerator
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- weka.classifiers.AbstractSplitGenerator
-
- weka.classifiers.GroupedBinnedNumericClassCrossValidationFoldGenerator
-
- All Implemented Interfaces:
Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,Randomizable,SizeOfHandler,BinningAlgorithmUser,CrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>,PerFoldCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>,SplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>,StratifiableSplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>,InstancesViewSupporter,Serializable,Iterator<WekaTrainTestSetContainer>,CrossValidationFoldGenerator,PerFoldCrossValidationFoldGenerator,SplitGenerator
public class GroupedBinnedNumericClassCrossValidationFoldGenerator extends AbstractSplitGenerator implements CrossValidationFoldGenerator, BinningAlgorithmUser, PerFoldCrossValidationFoldGenerator
Helper class for generating cross-validation folds.
The template for the relation name accepts the following placeholders:- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected BinningAlgorithmm_Algorithmthe binning algorithm.protected intm_CurrentFoldthe current fold.protected List<FoldPair<Binnable<weka.core.Instance>>>m_FoldPairsthe temporary pairs.protected Stringm_Groupthe group expression.protected WekaAttributeIndexm_Indexthe index to use for grouping.protected intm_NumFoldsthe number of folds.protected booleanm_Randomizewhether to randomize the data.protected BaseRegExpm_RegExpthe regular expression for the nominal/string attribute.protected Stringm_RelationNamethe template for the relation name.protected booleanm_Stratifywhether to stratify the data (in case of nominal class).-
Fields inherited from class weka.classifiers.AbstractSplitGenerator
m_Data, m_Initialized, m_OriginalIndices, m_OriginalIndicesPerFold, m_Seed, m_UseViews
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description GroupedBinnedNumericClassCrossValidationFoldGenerator()Initializes the generator.GroupedBinnedNumericClassCrossValidationFoldGenerator(weka.core.Instances data, BinningAlgorithm algorithm, int numFolds, long seed, boolean randomize, boolean stratify, BaseRegExp regExp, String group, String relName)Initializes the generator.GroupedBinnedNumericClassCrossValidationFoldGenerator(weka.core.Instances data, BinningAlgorithm algorithm, int numFolds, long seed, boolean stratify, BaseRegExp regExp, String group)Initializes the generator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringalgorithmTipText()Returns the tip text for this property.protected booleancanRandomize()Returns whether randomization is enabled.protected booleancheckNext()Returns true if the iteration has more elements.protected WekaTrainTestSetContainercreateNext()Returns the next element in the iteration.int[]crossValidationIndices()Returns the cross-validation indices.int[][]crossValidationIndicesPerFold()Returns the cross-validation indices per fold.voiddefineOptions()Adds options to the internal list of options.protected voiddoInitializeIterator()Initializes the iterator, randomizes the data if required.intgetActualNumFolds()Returns the actual number of folds used (eg when using LOO).BinningAlgorithmgetAlgorithm()Returns the binning algorithm.StringgetGroup()Returns the replacement string to use as group (eg '$2').WekaAttributeIndexgetIndex()Returns the attribute index to use for grouping.intgetNumFolds()Returns the number of folds.booleangetRandomize()Returns whether to randomize the data.BaseRegExpgetRegExp()Returns the regular expression for identifying the group (eg '^(.*)-([0-9]+)-(.*)$').StringgetRelationName()Returns the relation name template.booleangetStratify()Returns whether to stratify the data (in case of nominal class).StringglobalInfo()Returns a string describing the object.StringgroupTipText()Returns the tip text for this property.StringindexTipText()Returns the tip text for this property.StringnumFoldsTipText()Returns the tip text for this property.StringrandomizeTipText()Returns the tip text for this property.StringregExpTipText()Returns the tip text for this property.StringrelationNameTipText()Returns the tip text for this property.protected voidreset()Resets the generator.voidsetAlgorithm(BinningAlgorithm value)Sets the binning algorithm.voidsetData(weka.core.Instances value)Sets the original data.voidsetGroup(String value)Sets the replacement string to use as group (eg '$2').voidsetIndex(WekaAttributeIndex value)Sets the attribute index to use for grouping.voidsetNumFolds(int value)Sets the number of folds to use.voidsetRandomize(boolean value)Sets whether to randomize the data.voidsetRegExp(BaseRegExp value)Sets the regular expression for identifying the group (eg '^(.*)-([0-9]+)-(.*)$').voidsetRelationName(String value)Sets the template for the relation name.voidsetStratify(boolean value)Sets whether to stratify the data (nominal class).StringstratifyTipText()Returns the tip text for this property.StringtoString()Returns a short description of the generator.-
Methods inherited from class weka.classifiers.AbstractSplitGenerator
getData, getSeed, getUseViews, hasNext, initialize, initializeIterator, next, randomize, remove, seedTipText, setSeed, setUseViews, useViewsTipText
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.Destroyable
destroy
-
Methods inherited from interface adams.data.weka.InstancesViewSupporter
getUseViews, setUseViews
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
Methods inherited from interface adams.core.Randomizable
getSeed, seedTipText, setSeed
-
Methods inherited from interface weka.classifiers.SplitGenerator
getData, hasNext, initializeIterator, next, remove
-
-
-
-
Field Detail
-
m_NumFolds
protected int m_NumFolds
the number of folds.
-
m_Stratify
protected boolean m_Stratify
whether to stratify the data (in case of nominal class).
-
m_CurrentFold
protected transient int m_CurrentFold
the current fold.
-
m_RelationName
protected String m_RelationName
the template for the relation name.
-
m_Randomize
protected boolean m_Randomize
whether to randomize the data.
-
m_Index
protected WekaAttributeIndex m_Index
the index to use for grouping.
-
m_RegExp
protected BaseRegExp m_RegExp
the regular expression for the nominal/string attribute.
-
m_Group
protected String m_Group
the group expression.
-
m_Algorithm
protected BinningAlgorithm m_Algorithm
the binning algorithm.
-
-
Constructor Detail
-
GroupedBinnedNumericClassCrossValidationFoldGenerator
public GroupedBinnedNumericClassCrossValidationFoldGenerator()
Initializes the generator.
-
GroupedBinnedNumericClassCrossValidationFoldGenerator
public GroupedBinnedNumericClassCrossValidationFoldGenerator(weka.core.Instances data, BinningAlgorithm algorithm, int numFolds, long seed, boolean stratify, BaseRegExp regExp, String group)Initializes the generator.- Parameters:
data- the full datasetalgorithm- the algorithm to usenumFolds- the number of folds, leave-one-out if less than 2seed- the seed for randomizationstratify- whether to perform stratified CVregExp- the regular expression to apply to the attribute valuesgroup- the regexp group to use as group
-
GroupedBinnedNumericClassCrossValidationFoldGenerator
public GroupedBinnedNumericClassCrossValidationFoldGenerator(weka.core.Instances data, BinningAlgorithm algorithm, int numFolds, long seed, boolean randomize, boolean stratify, BaseRegExp regExp, String group, String relName)Initializes the generator.- Parameters:
data- the full datasetalgorithm- the algorithm to usenumFolds- the number of folds, leave-one-out if less than 2seed- the seed valuerandomize- whether to randomize the datastratify- whether to perform stratified CVregExp- the regular expression to apply to the attribute valuesgroup- the regexp group to use as grouprelName- the relation name template, use null to ignore
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractSplitGenerator
-
reset
protected void reset()
Resets the generator.- Overrides:
resetin classAbstractSplitGenerator
-
setData
public void setData(weka.core.Instances value)
Sets the original data.- Specified by:
setDatain interfaceSplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
setDatain interfaceSplitGenerator- Overrides:
setDatain classAbstractSplitGenerator- Parameters:
value- the data
-
setNumFolds
public void setNumFolds(int value)
Sets the number of folds to use.- Specified by:
setNumFoldsin interfaceCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
setNumFoldsin interfaceCrossValidationFoldGenerator- Parameters:
value- the number of folds, less than 2 for LOO
-
getNumFolds
public int getNumFolds()
Returns the number of folds.- Specified by:
getNumFoldsin interfaceCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
getNumFoldsin interfaceCrossValidationFoldGenerator- Returns:
- the number of folds
-
numFoldsTipText
public String numFoldsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
getActualNumFolds
public int getActualNumFolds()
Returns the actual number of folds used (eg when using LOO).- Specified by:
getActualNumFoldsin interfaceCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
getActualNumFoldsin interfaceCrossValidationFoldGenerator- Returns:
- the actual number of folds, -1 if not yet calculated
- See Also:
AbstractSplitGenerator.initializeIterator()
-
setRandomize
public void setRandomize(boolean value)
Sets whether to randomize the data.- Specified by:
setRandomizein interfaceCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
setRandomizein interfaceCrossValidationFoldGenerator- Parameters:
value- true if to randomize the data
-
getRandomize
public boolean getRandomize()
Returns whether to randomize the data.- Specified by:
getRandomizein interfaceCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
getRandomizein interfaceCrossValidationFoldGenerator- Returns:
- true if to randomize the data
-
randomizeTipText
public String randomizeTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setStratify
public void setStratify(boolean value)
Sets whether to stratify the data (nominal class).- Specified by:
setStratifyin interfaceCrossValidationFoldGenerator- Specified by:
setStratifyin interfaceStratifiableSplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Parameters:
value- whether to stratify the data (nominal class)
-
getStratify
public boolean getStratify()
Returns whether to stratify the data (in case of nominal class).- Specified by:
getStratifyin interfaceCrossValidationFoldGenerator- Specified by:
getStratifyin interfaceStratifiableSplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Returns:
- true if to stratify
-
stratifyTipText
public String stratifyTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setRelationName
public void setRelationName(String value)
Sets the template for the relation name.- Specified by:
setRelationNamein interfaceCrossValidationFoldGenerator- Parameters:
value- the template
-
getRelationName
public String getRelationName()
Returns the relation name template.- Specified by:
getRelationNamein interfaceCrossValidationFoldGenerator- Returns:
- the template
-
relationNameTipText
public String relationNameTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setIndex
public void setIndex(WekaAttributeIndex value)
Sets the attribute index to use for grouping.- Parameters:
value- the index
-
getIndex
public WekaAttributeIndex getIndex()
Returns the attribute index to use for grouping.- Returns:
- the index
-
indexTipText
public String indexTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setRegExp
public void setRegExp(BaseRegExp value)
Sets the regular expression for identifying the group (eg '^(.*)-([0-9]+)-(.*)$').- Parameters:
value- the expression
-
getRegExp
public BaseRegExp getRegExp()
Returns the regular expression for identifying the group (eg '^(.*)-([0-9]+)-(.*)$').- Returns:
- the expression
-
regExpTipText
public String regExpTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setGroup
public void setGroup(String value)
Sets the replacement string to use as group (eg '$2').- Parameters:
value- the group
-
getGroup
public String getGroup()
Returns the replacement string to use as group (eg '$2').- Returns:
- the group
-
groupTipText
public String groupTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setAlgorithm
public void setAlgorithm(BinningAlgorithm value)
Sets the binning algorithm.- Specified by:
setAlgorithmin interfaceBinningAlgorithmUser- Parameters:
value- the algorithm
-
getAlgorithm
public BinningAlgorithm getAlgorithm()
Returns the binning algorithm.- Specified by:
getAlgorithmin interfaceBinningAlgorithmUser- Returns:
- the algorithm
-
algorithmTipText
public String algorithmTipText()
Returns the tip text for this property.- Specified by:
algorithmTipTextin interfaceBinningAlgorithmUser- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
canRandomize
protected boolean canRandomize()
Returns whether randomization is enabled.- Specified by:
canRandomizein classAbstractSplitGenerator- Returns:
- true if to randomize
-
checkNext
protected boolean checkNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)- Specified by:
checkNextin classAbstractSplitGenerator- Returns:
- true if the iterator has more elements.
-
doInitializeIterator
protected void doInitializeIterator()
Initializes the iterator, randomizes the data if required.- Specified by:
doInitializeIteratorin classAbstractSplitGenerator- See Also:
AbstractSplitGenerator.canRandomize()
-
createNext
protected WekaTrainTestSetContainer createNext()
Returns the next element in the iteration.- Specified by:
createNextin classAbstractSplitGenerator- Returns:
- the next element in the iteration.
- Throws:
NoSuchElementException- iteration has no more elements.
-
crossValidationIndices
public int[] crossValidationIndices()
Returns the cross-validation indices.- Specified by:
crossValidationIndicesin interfaceCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
crossValidationIndicesin interfaceCrossValidationFoldGenerator- Returns:
- the indices
-
crossValidationIndicesPerFold
public int[][] crossValidationIndicesPerFold()
Returns the cross-validation indices per fold.- Specified by:
crossValidationIndicesPerFoldin interfacePerFoldCrossValidationFoldGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Returns:
- the indices
-
toString
public String toString()
Returns a short description of the generator.- Specified by:
toStringin interfaceSplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>- Specified by:
toStringin interfaceSplitGenerator- Overrides:
toStringin classAbstractSplitGenerator- Returns:
- a short description
-
-