Class LeaveOneOutByValueGenerator

  • All Implemented Interfaces:
    adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.Randomizable, adams.core.SizeOfHandler, adams.data.splitgenerator.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 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_UniqueValues

        protected transient List<String> m_UniqueValues
        the unique values.
      • 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 dataset
        seed - the seed for randomization
        randomize - whether to randomize the data
        index - the attribute index
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        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 interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class AbstractSplitGenerator
      • 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 class AbstractSplitGenerator
        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 class AbstractSplitGenerator
        Returns:
        true if the iterator has more elements.
      • 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 name
        template - the template for the relation name
        current - the current value
        train - whether train or test set
        Returns:
        the relation name