Package weka.classifiers
Class LeaveOneOutByValueGenerator
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- weka.classifiers.AbstractSplitGenerator
-
- weka.classifiers.LeaveOneOutByValueGenerator
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,Randomizable
,SizeOfHandler
,SplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>
,InstancesViewSupporter
,Serializable
,Iterator<WekaTrainTestSetContainer>
,SplitGenerator
public class LeaveOneOutByValueGenerator extends AbstractSplitGenerator
Generates train/test split pairs using the unique values from the specified attribute. All values apart from one will be part of the training data and the remainder the test set. This is repeated for each unique value.
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 int
m_CurrentPair
the current train/test pair to generate.protected WekaAttributeIndex
m_Index
the index to get the unique values from.protected boolean
m_Randomize
whether to randomize the data.protected String
m_RelationName
the template for the relation name.protected List<String>
m_UniqueValues
the unique values.static String
PLACEHOLDER_CURRENTVALUE
the placeholder for the current value in the test set.static String
PLACEHOLDER_ORIGINAL
the placeholder for the (original) relation name.static String
PLACEHOLDER_TYPE
the placeholder for "train" or "test" type.-
Fields inherited from class weka.classifiers.AbstractSplitGenerator
m_Data, m_Initialized, m_OriginalIndices, 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 LeaveOneOutByValueGenerator()
Initializes the generator.LeaveOneOutByValueGenerator(weka.core.Instances data, long seed, boolean randomize, WekaAttributeIndex index)
Initializes the generator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canRandomize()
Returns whether randomization is enabled.protected boolean
checkNext()
Returns true if the iteration has more elements.protected WekaTrainTestSetContainer
createNext()
Returns the next element in the iteration.protected String
createRelationName(String relation, String template, String current, boolean train)
Generates a relation name for the current value.void
defineOptions()
Adds options to the internal list of options.protected void
doInitializeIterator()
Initializes the iterator, randomizes the data if required.WekaAttributeIndex
getIndex()
Returns the attribute index to use for grouping.boolean
getRandomize()
Returns whether to randomize the data.String
getRelationName()
Returns the relation name template.String
globalInfo()
Returns a string describing the object.String
indexTipText()
Returns the tip text for this property.String
randomizeTipText()
Returns the tip text for this property.static String
relationNameTipText()
Returns the tiptext for the relation name template.protected void
reset()
Resets the generator.void
setIndex(WekaAttributeIndex value)
Sets the attribute index to use for grouping.void
setRandomize(boolean value)
Sets whether to randomize the data.void
setRelationName(String value)
Sets the template for the relation name.String
toString()
Returns a short description of the generator.-
Methods inherited from class weka.classifiers.AbstractSplitGenerator
getData, getSeed, getUseViews, hasNext, initialize, initializeIterator, next, randomize, remove, seedTipText, setData, 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 java.util.Iterator
forEachRemaining
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager, toCommandLine
-
-
-
-
Field Detail
-
PLACEHOLDER_ORIGINAL
public static final String PLACEHOLDER_ORIGINAL
the placeholder for the (original) relation name.- See Also:
- Constant Field Values
-
PLACEHOLDER_TYPE
public static final String PLACEHOLDER_TYPE
the placeholder for "train" or "test" type.- See Also:
- Constant Field Values
-
PLACEHOLDER_CURRENTVALUE
public static final String PLACEHOLDER_CURRENTVALUE
the placeholder for the current value in the test set.- See Also:
- Constant Field Values
-
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 get the unique values from.
-
m_CurrentPair
protected transient int m_CurrentPair
the current train/test pair to generate.
-
-
Constructor Detail
-
LeaveOneOutByValueGenerator
public LeaveOneOutByValueGenerator()
Initializes the generator.
-
LeaveOneOutByValueGenerator
public LeaveOneOutByValueGenerator(weka.core.Instances data, long seed, boolean randomize, WekaAttributeIndex index)
Initializes the generator.- Parameters:
data
- the full datasetseed
- the seed for randomizationrandomize
- whether to randomize the dataindex
- the attribute index
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractSplitGenerator
-
reset
protected void reset()
Resets the generator.- Overrides:
reset
in classAbstractSplitGenerator
-
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.
-
setRandomize
public void setRandomize(boolean value)
Sets whether to randomize the data.- Parameters:
value
- true if to randomize the data
-
getRandomize
public boolean getRandomize()
Returns whether to randomize the data.- 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.
-
setRelationName
public void setRelationName(String value)
Sets the template for the relation name.- Parameters:
value
- the template
-
getRelationName
public String getRelationName()
Returns the relation name template.- Returns:
- the template
-
relationNameTipText
public static String relationNameTipText()
Returns the tiptext for the relation name template.- Returns:
- the tiptext
-
canRandomize
protected boolean canRandomize()
Returns whether randomization is enabled.- Specified by:
canRandomize
in 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:
checkNext
in classAbstractSplitGenerator
- Returns:
- true if the iterator has more elements.
-
doInitializeIterator
protected void doInitializeIterator()
Initializes the iterator, randomizes the data if required.- Specified by:
doInitializeIterator
in classAbstractSplitGenerator
- See Also:
AbstractSplitGenerator.canRandomize()
-
createRelationName
protected String createRelationName(String relation, String template, String current, boolean train)
Generates a relation name for the current value.- Parameters:
relation
- the original relation nametemplate
- the template for the relation namecurrent
- the current valuetrain
- whether train or test set- Returns:
- the relation name
-
createNext
protected WekaTrainTestSetContainer createNext()
Returns the next element in the iteration.- Specified by:
createNext
in classAbstractSplitGenerator
- Returns:
- the next element in the iteration.
- Throws:
NoSuchElementException
- iteration has no more elements.
-
toString
public String toString()
Returns a short description of the generator.- Specified by:
toString
in interfaceSplitGenerator<weka.core.Instances,WekaTrainTestSetContainer>
- Specified by:
toString
in interfaceSplitGenerator
- Overrides:
toString
in classAbstractSplitGenerator
- Returns:
- a short description
-
-