cosc575.p1
Class DataSet

java.lang.Object
  extended by cosc575.p1.DataSet
All Implemented Interfaces:
OptionHandler

public class DataSet
extends java.lang.Object
implements OptionHandler

Implements a class for storing examples for machine-learning methods.


Field Summary
protected  Attributes attributes
          the Attributes object for attribute attributes, types, and domains
protected  Examples examples
          the examples
protected  java.lang.String name
          the name of this data set
protected  java.util.Random random
          a random number generator
protected  long seed
          default random seed
 
Constructor Summary
DataSet()
          Default constructor.
DataSet(Attributes attributes)
          Explicit constructor.
DataSet(Attributes attributes, java.lang.String filename)
          Explicit constructor.
DataSet(java.lang.String filename)
          Explicit constructor.
 
Method Summary
 void add(DataSet dataset)
          Adds the examples of the data set to this data set.
 void add(Example example)
          Adds an example to this data set.
 Attributes getAttributes()
          Gets the attributes of this DataSet object.
 Examples getExamples()
          Gets the examples of this data set.
 boolean getHasDiscreteAttributes()
          Returns true if this data set has discrete attributes; returns false otherwise.
 boolean getHasNominalAttributes()
          Returns true if this data set has nominal attributes; returns false otherwise.
 boolean getHasNumericAttributes()
          Returns true if this data set has numeric attributes; returns false otherwise.
 long getSeed()
          Gets the seed for this data set.
 void load(java.lang.String filename)
          Loads examples from the specified file.
static void main(java.lang.String[] args)
           
private  void parse(java.util.Scanner scanner)
          Parses the header for a data set.
 void setOptions(java.lang.String[] args)
          Sets the options for this data set.
 void setRandom(java.util.Random random)
          Sets the random number generator for this data set.
 void setSeed(long seed)
          Sets the random number seed for this data set.
 java.lang.String toString()
          Returns a string representation of the data set in a format similar 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 object for attribute attributes, types, and domains


examples

protected Examples examples
the examples


seed

protected long seed
default random seed


random

protected java.util.Random random
a random number generator

Constructor Detail

DataSet

public DataSet()
Default constructor.


DataSet

public DataSet(java.lang.String filename)
        throws java.lang.Exception
Explicit constructor. Reads the attribute information and the training examples from the specified file.

Parameters:
filename - the name of the file containing this data's information
Throws:
java.lang.Exception - if an exception occurs

DataSet

public DataSet(Attributes attributes)
        throws java.lang.Exception
Explicit constructor.

Parameters:
attributes - the attributes for this data set
Throws:
java.lang.Exception - if an exception occurs

DataSet

public DataSet(Attributes attributes,
               java.lang.String filename)
        throws java.lang.Exception
Explicit constructor. Constructs a DataSet object from attributes and the filename.

Parameters:
attributes - the attributes for this data set
filename - the name of the file containing this data set's examples
Throws:
java.lang.Exception - if an exception occurs
Method Detail

setOptions

public void setOptions(java.lang.String[] args)
                throws java.lang.Exception
Sets the options for this data set.

Specified by:
setOptions in interface OptionHandler
Parameters:
args - the arguments
Throws:
java.lang.Exception - if an exception occurs

setRandom

public void setRandom(java.util.Random random)
Sets the random number generator for this data set.

Parameters:
random - the specified random number generator

setSeed

public void setSeed(long seed)
Sets the random number seed for this data set. This also seeds the random number generator.

Parameters:
seed - the seed

getSeed

public long getSeed()
Gets the seed for this data set.

Returns:
the seed for this data set

getAttributes

public Attributes getAttributes()
Gets the attributes of this DataSet object.

Returns:
the attributes 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

getHasDiscreteAttributes

public boolean getHasDiscreteAttributes()
Returns true if this data set has discrete attributes; returns false otherwise.

Returns:
true if this data set has discrete attributes

getHasNominalAttributes

public boolean getHasNominalAttributes()
Returns true if this data set has nominal attributes; returns false otherwise.

Returns:
true if this data set has nominal attributes

load

public void load(java.lang.String filename)
          throws java.lang.Exception
Loads examples from the specified file. Does some checking by reading the attributes information from the file, but presently, does not compare attributes information to make sure they're compatible.

Parameters:
filename - the file from which to read
Throws:
java.lang.Exception - if an exception occurs

add

public void add(Example example)
         throws java.lang.Exception
Adds an example to this data set.

Parameters:
example - the example to be added
Throws:
java.lang.Exception - if an exception occurs

add

public void add(DataSet dataset)
         throws java.lang.Exception
Adds the examples of the data set to this data set.

Parameters:
dataset - the data set to be added
Throws:
java.lang.Exception - if an exception occurs

getExamples

public Examples getExamples()
Gets the examples of this data set.

Returns:
the examples of this data set

parse

private void parse(java.util.Scanner scanner)
            throws java.lang.Exception
Parses the header for a data set.

Parameters:
scanner - a scanner containing the data set's tokens
Throws:
java.lang.Exception - if an exception occurs

toString

public java.lang.String toString()
Returns a string representation of the data set in a format similar to that of the file format. Includes the testing examples if present.

Overrides:
toString in class java.lang.Object
Returns:
a string containing the attributes information and examples

main

public static void main(java.lang.String[] args)