Class Attributes
- java.lang.Object
-
- Attributes
-
public class Attributes extends java.lang.ObjectStores information for attributes for data sets for machine learning.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<Attribute>attributesa list of attributesprivate intclassIndexstores the position of the class labelprivate booleanhasNumericAttributesa flag indicating that the data set has one or more numeric attributes
-
Constructor Summary
Constructors Constructor Description Attributes()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Attribute attribute)Adds a new attribute to this set of attributes.Attributeget(int i)Returns the ith attribute in this set of attributes.AttributegetClassAttribute()Returns the class attribute.intgetClassIndex()Returns the index of the class label.booleangetHasNumericAttributes()Returns true if this set of attributes has one or more numeric attributes; returns false otherwise.intgetIndex(java.lang.String name)Returns the attribute's index.static voidmain(java.lang.String[] args)A main method for testing.voidparse(java.util.Scanner scanner)Parses the attribute declarations in the specified scanner.voidsetClassIndex(int classIndex)Sets the class index for this set of attributes.intsize()Returns the number of attributes.java.lang.StringtoString()Returns a string representation of this Attributes object.
-
-
-
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
-
-
Method Detail
-
add
public void add(Attribute attribute)
Adds a new attribute to this set of attributes.- 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.ExceptionReturns 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.ExceptionParses the attribute declarations in the specified scanner. By convention, the last attribute is the class label after parsing.- 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.ExceptionSets 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:
toStringin classjava.lang.Object- Returns:
- a string representation of this Attributes object
-
main
public static void main(java.lang.String[] args)
A main method for testing.- Parameters:
args- command-line arguments
-
-