com.rapidminer.example
Class Example

java.lang.Object
  extended by com.rapidminer.example.Example
All Implemented Interfaces:
java.io.Serializable, java.util.Map<java.lang.String,java.lang.Object>

public class Example
extends java.lang.Object
implements java.io.Serializable, java.util.Map<java.lang.String,java.lang.Object>

An example consists of a DataRow and some convenience methods to access the data. Hence, all values are actually doubles, symbolic values are mapped to integers stored in doubles.
Since ExampleSets are only a view on ExampleTables, Examples are generated on the fly by ExampleReaders. Since they only contain the currently selected attributes operators need not to consider attribute selections or example subsets (samplings).

Author:
Ingo Mierswa
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Field Summary
static java.lang.String SEPARATOR
          Separator used in the getAttributesAsString() method (tab).
static java.lang.String SPARSE_SEPARATOR
          Separates indices from values in sparse format (colon).
 
Constructor Summary
Example(DataRow data, ExampleSet parentExampleSet)
          Creates a new Example that uses the data stored in a DataRow.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
           
 boolean equalValue(Attribute first, Attribute second)
          Returns true if both nominal values are the same (if both attributes are nominal) or if both real values are the same (if both attributes are real values) or false otherwise.
 java.lang.Object get(java.lang.Object key)
           
 Attributes getAttributes()
          Delivers the attributes.
 double getConfidence(java.lang.String classValue)
           
 DataRow getDataRow()
          Returns the data row which backs up the example in the example table.
 java.util.Date getDateValue(Attribute a)
          Returns the date value for the given attribute.
 double getId()
           
 double getLabel()
           
 java.lang.String getNominalValue(Attribute a)
          Returns the nominal value for the given attribute.
 double getNumericalValue(Attribute a)
          Returns the numerical value for the given attribute.
 double getPredictedLabel()
           
 double getValue(Attribute a)
          Returns the value of attribute a.
 java.lang.String getValueAsString(Attribute attribute)
          Returns the value of this attribute as string representation, i.e. the number as string for numerical attributes and the correctly mapped categorical value for nominal values.
 java.lang.String getValueAsString(Attribute attribute, int fractionDigits, boolean quoteNominal)
          Returns the value of this attribute as string representation, i.e. the number as string for numerical attributes and the correctly mapped categorical value for nominal values.
 double getWeight()
           
 boolean isEmpty()
           
 java.util.Set<java.lang.String> keySet()
           
 java.lang.Object put(java.lang.String attributeName, java.lang.Object value)
           
 void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
           
 java.lang.String remove(java.lang.Object key)
           
 void setConfidence(java.lang.String classValue, double confidence)
           
 void setId(double value)
           
 void setLabel(double value)
           
 void setPredictedLabel(double value)
           
 void setValue(Attribute a, double value)
          Sets the value of attribute a.
 void setValue(Attribute a, java.lang.String str)
          Sets the value of attribute a which must be a nominal attribute.
 void setWeight(double value)
           
 int size()
           
 java.lang.String toDenseString(int fractionDigits, boolean quoteNominal)
          This method returns a dense string representation of the example.
 java.lang.String toSparseString(int format, int fractionDigits, boolean quoteNominal)
          Returns regular and some special attributes (label, id, and example weight) in sparse format.
 java.lang.String toString()
          Returns a dense string representation with all possible fraction digits.
 java.util.Collection<java.lang.Object> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

SEPARATOR

public static final java.lang.String SEPARATOR
Separator used in the getAttributesAsString() method (tab).

See Also:
Constant Field Values

SPARSE_SEPARATOR

public static final java.lang.String SPARSE_SEPARATOR
Separates indices from values in sparse format (colon).

See Also:
Constant Field Values
Constructor Detail

Example

public Example(DataRow data,
               ExampleSet parentExampleSet)
Creates a new Example that uses the data stored in a DataRow. The attributes correspond to the regular and special attributes.

Method Detail

getDataRow

public DataRow getDataRow()
Returns the data row which backs up the example in the example table.


getAttributes

public Attributes getAttributes()
Delivers the attributes.


getValue

public double getValue(Attribute a)
Returns the value of attribute a. In the case of nominal attributes, the delivered double value corresponds to an internal index


getNominalValue

public java.lang.String getNominalValue(Attribute a)
Returns the nominal value for the given attribute.

Throws:
AttributeTypeException - if the given attribute has the wrong value type

getNumericalValue

public double getNumericalValue(Attribute a)
Returns the numerical value for the given attribute.

Throws:
AttributeTypeException - if the given attribute has the wrong value type

getDateValue

public java.util.Date getDateValue(Attribute a)
Returns the date value for the given attribute.

Throws:
AttributeTypeException - if the given attribute has the wrong value type

setValue

public void setValue(Attribute a,
                     double value)
Sets the value of attribute a. The attribute a need not necessarily be part of the example set the example is taken from, although this is no good style.


setValue

public void setValue(Attribute a,
                     java.lang.String str)
Sets the value of attribute a which must be a nominal attribute. The attribute a need not necessarily be part of the example set the example is taken from, although this is no good style.


equalValue

public boolean equalValue(Attribute first,
                          Attribute second)
Returns true if both nominal values are the same (if both attributes are nominal) or if both real values are the same (if both attributes are real values) or false otherwise.


getLabel

public double getLabel()

setLabel

public void setLabel(double value)

getPredictedLabel

public double getPredictedLabel()

setPredictedLabel

public void setPredictedLabel(double value)

getId

public double getId()

setId

public void setId(double value)

getWeight

public double getWeight()

setWeight

public void setWeight(double value)

getConfidence

public double getConfidence(java.lang.String classValue)

setConfidence

public void setConfidence(java.lang.String classValue,
                          double confidence)

getValueAsString

public java.lang.String getValueAsString(Attribute attribute)

Returns the value of this attribute as string representation, i.e. the number as string for numerical attributes and the correctly mapped categorical value for nominal values. The used number of fraction digits is unlimited (see NumericalAttribute.DEFAULT_NUMBER_OF_DIGITS). Nominal values containing whitespaces will not be quoted.

Please note that this method should not be used in order to get the nominal values, please use getNominalValue(Attribute) instead.


getValueAsString

public java.lang.String getValueAsString(Attribute attribute,
                                         int fractionDigits,
                                         boolean quoteNominal)

Returns the value of this attribute as string representation, i.e. the number as string for numerical attributes and the correctly mapped categorical value for nominal values. If the value is numerical the given number of fraction digits is used. If the value is numerical, the given number of fraction digits is used. This value must be either one out of NumericalAttribute.DEFAULT_NUMBER_OF_DIGITS or NumericalAttribute.UNLIMITED_NUMBER_OF_DIGITS or a number greater or equal to 0. The boolean flag indicates if nominal values containing whitespaces should be quoted with double quotes.

Please note that this method should not be used in order to get the nominal values, please use getNominalValue(Attribute) instead.


toString

public java.lang.String toString()
Returns a dense string representation with all possible fraction digits. Nominal values will be quoted with double quotes.

Overrides:
toString in class java.lang.Object

toDenseString

public java.lang.String toDenseString(int fractionDigits,
                                      boolean quoteNominal)
This method returns a dense string representation of the example. It first returns the values of all special attributes and then the values of all regular attributes.


toSparseString

public java.lang.String toSparseString(int format,
                                       int fractionDigits,
                                       boolean quoteNominal)
Returns regular and some special attributes (label, id, and example weight) in sparse format.

Parameters:
format - one of the formats specified in SparseFormatDataRowReader

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map<java.lang.String,java.lang.Object>

put

public java.lang.Object put(java.lang.String attributeName,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map<java.lang.String,java.lang.Object>

clear

public void clear()
Specified by:
clear in interface java.util.Map<java.lang.String,java.lang.Object>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<java.lang.String,java.lang.Object>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<java.lang.String,java.lang.Object>

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.String,java.lang.Object>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<java.lang.String,java.lang.Object>

keySet

public java.util.Set<java.lang.String> keySet()
Specified by:
keySet in interface java.util.Map<java.lang.String,java.lang.Object>

putAll

public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.Object> m)
Specified by:
putAll in interface java.util.Map<java.lang.String,java.lang.Object>

remove

public java.lang.String remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<java.lang.String,java.lang.Object>

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.String,java.lang.Object>

values

public java.util.Collection<java.lang.Object> values()
Specified by:
values in interface java.util.Map<java.lang.String,java.lang.Object>


Copyright © 2001-2009 by Rapid-I