Class DataSet


  • public class DataSet
    extends java.lang.Object
    Implements a class for a data set for machine-learning methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Attributes attributes
      the attributes of this data set
      protected Examples examples
      the examples of this data set
      protected java.lang.String name
      the name of this data set
      protected java.util.Random random
      a random-number generator
    • Constructor Summary

      Constructors 
      Constructor Description
      DataSet()
      Default constructor.
      DataSet​(Attributes attributes)
      Explicit constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Example example)
      Adds the specified example to this data set.
      Attributes getAttributes()
      Gets the attributes of this DataSet object.
      Examples getExamples()
      Gets the examples of this data set.
      boolean getHasNumericAttributes()
      Returns true if this data set has numeric attributes; returns false otherwise.
      void load​(java.lang.String filename)
      Loads a data set from the specified file.
      static void main​(java.lang.String[] args)
      A main method for testing.
      private void parse​(java.util.Scanner scanner)
      Parses a data set from the specified scanner, which consists of parsing the data set's header, attributes, and examples.
      void setRandom​(java.util.Random random)
      Sets the random-number generator for this data set.
      java.lang.String toString()
      Returns a string representation of the data set in a format identical to that of the file format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • name

        protected java.lang.String name
        the name of this data set
      • attributes

        protected Attributes attributes
        the attributes of this data set
      • examples

        protected Examples examples
        the examples of this data set
      • random

        protected java.util.Random random
        a random-number generator
    • Constructor Detail

      • DataSet

        public DataSet()
        Default constructor.
      • DataSet

        public DataSet​(Attributes attributes)
        Explicit constructor.
        Parameters:
        attributes - the attributes for this data set
    • Method Detail

      • add

        public void add​(Example example)
        Adds the specified example to this data set.
        Parameters:
        example - the example to be added
      • getAttributes

        public Attributes getAttributes()
        Gets the attributes of this DataSet object.
        Returns:
        the attributes of this data set
      • getExamples

        public Examples getExamples()
        Gets the examples of this data set.
        Returns:
        the examples of this data set
      • getHasNumericAttributes

        public boolean getHasNumericAttributes()
        Returns true if this data set has numeric attributes; returns false otherwise.
        Returns:
        true if this data set has numeric attributes
      • load

        public void load​(java.lang.String filename)
                  throws java.lang.Exception
        Loads a data set from the specified file.
        Parameters:
        filename - the file from which to read
        Throws:
        java.lang.Exception - if the file is not found or if a parsing exception occurs
      • parse

        private void parse​(java.util.Scanner scanner)
                    throws java.lang.Exception
        Parses a data set from the specified scanner, which consists of parsing the data set's header, attributes, and examples.
        Parameters:
        scanner - a scanner containing the data set's tokens
        Throws:
        java.lang.Exception - if a parsing exception occurs
      • setRandom

        public void setRandom​(java.util.Random random)
        Sets the random-number generator for this data set.
        Parameters:
        random - the random-number generator
      • toString

        public java.lang.String toString()
        Returns a string representation of the data set in a format identical to that of the file format.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string containing data set
      • main

        public static void main​(java.lang.String[] args)
        A main method for testing.
        Parameters:
        args - command-line arguments