Class Attributes


  • public class Attributes
    extends java.lang.Object
    Stores information for attributes for data sets for machine learning.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ArrayList<Attribute> attributes
      a list of attributes
      private int classIndex
      stores the position of the class label
      private boolean hasNumericAttributes
      a flag indicating that the data set has one or more numeric attributes
    • Constructor Summary

      Constructors 
      Constructor Description
      Attributes()
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Attribute attribute)
      Adds a new attribute to this set of attributes.
      Attribute get​(int i)
      Returns the ith attribute in this set of attributes.
      Attribute getClassAttribute()
      Returns the class attribute.
      int getClassIndex()
      Returns the index of the class label.
      boolean getHasNumericAttributes()
      Returns true if this set of attributes has one or more numeric attributes; returns false otherwise.
      int getIndex​(java.lang.String name)
      Returns the attribute's index.
      void parse​(java.util.Scanner scanner)
      Parses the attribute declarations using the tokens in the specified scanner, which consist of <attributes>.
      void setClassIndex​(int classIndex)
      Sets the class index for this set of attributes.
      int size()
      Returns the number of attributes.
      java.lang.String toString()
      Returns a string representation of this Attributes object.
      • Methods inherited from class java.lang.Object

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

      • attributes

        private java.util.ArrayList<Attribute> attributes
        a list of attributes
      • hasNumericAttributes

        private boolean hasNumericAttributes
        a flag indicating that the data set has one or more numeric attributes
      • classIndex

        private int classIndex
        stores the position of the class label
    • Constructor Detail

      • Attributes

        public Attributes()
        Default constructor.
    • Method Detail

      • add

        public void add​(Attribute attribute)
        Adds a new attribute to this set of attributes. This method does not change the class attribute.
        Parameters:
        attribute - the attribute's name
      • getClassIndex

        public int getClassIndex()
        Returns the index of the class label.
        Returns:
        the index of the class label
      • getHasNumericAttributes

        public boolean getHasNumericAttributes()
        Returns true if this set of attributes has one or more numeric attributes; returns false otherwise.
        Returns:
        true if this set of attributes has numeric attributes
      • get

        public Attribute get​(int i)
        Returns the ith attribute in this set of attributes.
        Parameters:
        i - the index of the specified attribute
        Returns:
        the ith Attribute
      • getClassAttribute

        public Attribute getClassAttribute()
        Returns the class attribute.
        Returns:
        the class attribute
      • getIndex

        public int getIndex​(java.lang.String name)
                     throws java.lang.Exception
        Returns the attribute's index.
        Parameters:
        name - the attribute's name
        Returns:
        the attribute's position in the names array
        Throws:
        java.lang.Exception - if the attribute does not exist
      • size

        public int size()
        Returns the number of attributes.
        Returns:
        the number of attributes
      • parse

        public void parse​(java.util.Scanner scanner)
                   throws java.lang.Exception
        Parses the attribute declarations using the tokens in the specified scanner, which consist of <attributes>. By convention, the last attribute is the class attribute.
        Parameters:
        scanner - a Scanner containing the data set's tokens
        Throws:
        java.lang.Exception - if a parse exception occurs
      • setClassIndex

        public void setClassIndex​(int classIndex)
                           throws java.lang.Exception
        Sets the class index for this set of attributes.
        Parameters:
        classIndex - the new class index
        Throws:
        java.lang.Exception - if the class index is out of of bounds
      • toString

        public java.lang.String toString()
        Returns a string representation of this Attributes object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this Attributes object