Package com.yahoo.labs.samoa.instances
Class Instances
- java.lang.Object
-
- com.yahoo.labs.samoa.instances.Instances
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
InstancesHeader
public class Instances extends Object implements Serializable
The Class Instances.- Author:
- abifet
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected ArffLoader
arff
The arff.static String
ARFF_DATA
The keyword used to denote the start of the arff data sectionstatic String
ARFF_RELATION
The keyword used to denote the start of an arff headerprotected HashMap<String,Integer>
hsAttributesIndices
A Hash that stores the indices of features.protected int[]
indicesIrrelevants
Indices of irrelevant features.protected int[]
indicesRelevants
Indices of relevant features.protected InstanceInformation
instanceInformation
The instance information.protected List<Instance>
instances
The instances.
-
Constructor Summary
Constructors Constructor Description Instances()
Instantiates a new instances.Instances(Instances chunk)
Instantiates a new instances.Instances(Instances chunk, int capacity)
Instantiates a new instances.Instances(Instances chunk, int first, int toCopy)
Instantiates a new instances.Instances(Reader reader, int size, int classAttribute)
Instantiates a new instances.Instances(Reader reader, Range range)
Instantiates a new instances.Instances(StringReader st, int capacity)
Instantiates a new instances.Instances(String st, Attribute[] v, int capacity)
Instantiates a new instances.Instances(String st, List<Attribute> v, int capacity)
Instantiates a new instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Instance inst)
Adds the.Attribute
attribute(int w)
Attribute.Attribute
attribute(String name)
Attribute
classAttribute()
Class attribute.int
classIndex()
Class index.protected void
copyInstances(int from, Instances dest, int num)
void
delete()
Delete.void
delete(int index)
Delete.void
deleteAttributeAt(Integer integer)
Delete attribute at.Instance
get(int k)
int[]
getIndicesIrrelevants()
Returns the indices of the irrelevant features indicesIrrelevants.int[]
getIndicesRelevants()
Returns the indices of the relevant features indicesRelevants.String
getRelationName()
Gets the relation name.protected int
indexOf(Attribute att)
Returns the index of an Attribute.void
insertAttributeAt(Attribute attribute, int position)
Insert attribute at.Instance
instance(int num)
Instance.double
meanOrMode(int j)
Mean or mode.int
numAttributes()
Num attributes.int
numClasses()
Num classes.int
numInstances()
Num instances.void
randomize(Random random)
Randomize.boolean
readInstance(Reader fileReader)
Read instance.void
set(int i, Instance inst)
void
setAttributes(Attribute[] v)
void
setAttributes(Attribute[] v, int[] indexValues)
void
setAttributes(List<Attribute> v, List<Integer> indexValues)
void
setClassIndex(int classIndex)
Sets the class index.void
setIndicesRelevants(int[] indicesRelevants)
Sets the indices of relevant features.void
setRangeOutputIndices(Range range)
void
setRelationName(String string)
Sets the relation name.int
size()
void
stratify(int numFolds)
Stratify.protected void
stratStep(int numFolds)
protected String
stringWithoutHeader()
Returns the instances in the dataset as a string in ARFF format.void
swap(int i, int j)
Swap.Instances
testCV(int numFolds, int numFold)
Test cv.String
toString()
Returns the dataset as a string in ARFF format.Instances
trainCV(int numFolds, int numFold)
Instances
trainCV(int numFolds, int numFold, Random random)
Train cv.
-
-
-
Field Detail
-
ARFF_RELATION
public static final String ARFF_RELATION
The keyword used to denote the start of an arff header- See Also:
- Constant Field Values
-
ARFF_DATA
public static final String ARFF_DATA
The keyword used to denote the start of the arff data section- See Also:
- Constant Field Values
-
instanceInformation
protected InstanceInformation instanceInformation
The instance information.
-
arff
protected ArffLoader arff
The arff.
-
hsAttributesIndices
protected HashMap<String,Integer> hsAttributesIndices
A Hash that stores the indices of features.
-
indicesRelevants
protected int[] indicesRelevants
Indices of relevant features.
-
indicesIrrelevants
protected int[] indicesIrrelevants
Indices of irrelevant features.
-
-
Constructor Detail
-
Instances
public Instances(Instances chunk)
Instantiates a new instances.- Parameters:
chunk
- the chunk
-
Instances
public Instances()
Instantiates a new instances.
-
Instances
public Instances(Reader reader, int size, int classAttribute)
Instantiates a new instances.- Parameters:
reader
- the readersize
- the sizeclassAttribute
- the class attribute
-
Instances
public Instances(Reader reader, Range range)
Instantiates a new instances.- Parameters:
reader
- the readerrange
-
-
Instances
public Instances(Instances chunk, int capacity)
Instantiates a new instances.- Parameters:
chunk
- the chunkcapacity
- the capacity
-
Instances
public Instances(String st, Attribute[] v, int capacity)
Instantiates a new instances.- Parameters:
st
- the stv
- the vcapacity
- the capacity
-
Instances
public Instances(String st, List<Attribute> v, int capacity)
Instantiates a new instances.- Parameters:
st
- the stv
- the vcapacity
- the capacity
-
Instances
public Instances(Instances chunk, int first, int toCopy)
Instantiates a new instances.- Parameters:
chunk
- the chunkfirst
- the first instancetoCopy
- the j
-
Instances
public Instances(StringReader st, int capacity)
Instantiates a new instances.- Parameters:
st
- the stcapacity
- the capacity
-
-
Method Detail
-
setRelationName
public void setRelationName(String string)
Sets the relation name.- Parameters:
string
- the new relation name
-
getRelationName
public String getRelationName()
Gets the relation name.- Returns:
- the relation name
-
classIndex
public int classIndex()
Class index.- Returns:
- the int
-
setClassIndex
public void setClassIndex(int classIndex)
Sets the class index.- Parameters:
classIndex
- the new class index
-
classAttribute
public Attribute classAttribute()
Class attribute.- Returns:
- the attribute
-
numAttributes
public int numAttributes()
Num attributes.- Returns:
- the int
-
attribute
public Attribute attribute(int w)
Attribute.- Parameters:
w
- the w- Returns:
- the attribute
-
numClasses
public int numClasses()
Num classes.- Returns:
- the int
-
deleteAttributeAt
public void deleteAttributeAt(Integer integer)
Delete attribute at.- Parameters:
integer
- the integer
-
insertAttributeAt
public void insertAttributeAt(Attribute attribute, int position)
Insert attribute at.- Parameters:
attribute
- the attributeposition
- the position
-
instance
public Instance instance(int num)
Instance.- Parameters:
num
- the num- Returns:
- the instance
-
numInstances
public int numInstances()
Num instances.- Returns:
- the int
-
add
public void add(Instance inst)
Adds the.- Parameters:
inst
- the inst
-
randomize
public void randomize(Random random)
Randomize.- Parameters:
random
- the random
-
stratify
public void stratify(int numFolds)
Stratify.- Parameters:
numFolds
- the num folds
-
stratStep
protected void stratStep(int numFolds)
-
trainCV
public Instances trainCV(int numFolds, int numFold, Random random)
Train cv.- Parameters:
numFolds
- the num foldsnumFold
-random
- the random- Returns:
- the instances
-
trainCV
public Instances trainCV(int numFolds, int numFold)
-
copyInstances
protected void copyInstances(int from, Instances dest, int num)
-
testCV
public Instances testCV(int numFolds, int numFold)
Test cv.- Parameters:
numFolds
- the num foldsnumFold
- the num fold- Returns:
- the instances
-
meanOrMode
public double meanOrMode(int j)
Mean or mode.- Parameters:
j
- the j- Returns:
- the double
-
readInstance
public boolean readInstance(Reader fileReader)
Read instance.- Parameters:
fileReader
- the file reader- Returns:
- true, if successful
-
delete
public void delete()
Delete.
-
delete
public void delete(int index)
Delete.
-
swap
public void swap(int i, int j)
Swap.- Parameters:
i
- the ij
- the j
-
size
public int size()
-
set
public void set(int i, Instance inst)
-
get
public Instance get(int k)
-
setRangeOutputIndices
public void setRangeOutputIndices(Range range)
-
setAttributes
public void setAttributes(Attribute[] v)
-
setAttributes
public void setAttributes(Attribute[] v, int[] indexValues)
-
toString
public String toString()
Returns the dataset as a string in ARFF format. Strings are quoted if they contain whitespace characters, or if they are a question mark.
-
stringWithoutHeader
protected String stringWithoutHeader()
Returns the instances in the dataset as a string in ARFF format. Strings are quoted if they contain whitespace characters, or if they are a question mark.- Returns:
- the dataset in ARFF format as a string
-
indexOf
protected int indexOf(Attribute att)
Returns the index of an Attribute.- Parameters:
att
- , the attribute.
-
getIndicesRelevants
public int[] getIndicesRelevants()
Returns the indices of the relevant features indicesRelevants.- Returns:
- indicesRelevants
-
getIndicesIrrelevants
public int[] getIndicesIrrelevants()
Returns the indices of the irrelevant features indicesIrrelevants.- Returns:
- indicesIrrelevants
-
setIndicesRelevants
public void setIndicesRelevants(int[] indicesRelevants)
Sets the indices of relevant features. This method also sets the irrelevant ones since it is the set complement.- Parameters:
indicesRelevants
-
-
-