com.datumbox.framework.core.common.dataobjects
Class Dataframe
- java.lang.Object
-
- com.datumbox.framework.core.common.dataobjects.Dataframe
-
- All Implemented Interfaces:
- Copyable<Dataframe>, Savable, java.lang.AutoCloseable, java.lang.Iterable<Record>, java.util.Collection<Record>
public class Dataframe extends java.lang.Object implements java.util.Collection<Record>, Copyable<Dataframe>, Savable
The Dataframe class stores a list of Records Objects and several meta-data. All Machine Learning algorithms get as argument Dataframe objects. The class has an internal static Builder class which can be used to generate Dataframe objects from Text or CSV files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classDataframe.BuilderThe Builder is a utility class which can help you build Dataframe from Text files, CSV files or load it from disk.
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringCOLUMN_NAME_CONSTANTInternal name of the constant.static java.lang.StringCOLUMN_NAME_YInternal name of the response variable.
-
Constructor Summary
Constructors Constructor and Description Dataframe(Configuration configuration)Public constructor of Dataframe.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Record_unsafe_set(java.lang.Integer rId, Record r)Sets the record in a particular position in the dataset, WITHOUT updating the internal meta-info and returns the previous value (null if not existed).booleanadd(Record r)Adds a record in the Dataframe and updates the Meta data.booleanaddAll(java.util.Collection<? extends Record> c)java.lang.IntegeraddRecord(Record r)Adds a Record in the Dataframe and returns its id.voidclear()Clears all the internal Records of the Dataframe.voidclose()booleancontains(java.lang.Object o)Checks if the Record exists in the Dataframe.booleancontainsAll(java.util.Collection<?> c)Dataframecopy()Copies itself and returns a new instance of the same type.voiddelete()Deletes the Dataframe and removes all internal variables.voiddropXColumns(java.util.Set<java.lang.Object> columnSet)Removes completely a list of columns from the dataset.java.lang.Iterable<java.util.Map.Entry<java.lang.Integer,Record>>entries()Returns a read-only Iterable on the keys and Records of the Dataframe.Recordget(java.lang.Integer id)Returns a particular Record using its id.DataframegetSubset(FlatDataList idsCollection)It generates and returns a new Dataframe which contains a subset of this Dataframe.FlatDataListgetXColumn(java.lang.Object column)It extracts the values of a particular column from all records and stores them into an FlatDataList.java.util.Map<java.lang.Object,TypeInference.DataType>getXDataTypes()Returns an Map with column names as index and DataTypes as values.FlatDataListgetYColumn()It extracts the values of the response variables from all observations and stores them into an FlatDataList.TypeInference.DataTypegetYDataType()Returns the type of the response variable y.java.lang.Iterable<java.lang.Integer>index()Returns a read-only Iterable on the keys of the Dataframe.java.lang.IntegerindexOf(Record o)Returns the index of the first occurrence of the specified element in this Dataframe, or null if this Dataframe does not contain the element.booleanisEmpty()Checks if the Dataframe is empty.java.util.Iterator<Record>iterator()Returns a read-only iterator on the values of the Dataframe.voidrecalculateMeta()It forces the recalculation of Meta data using the Records of the dataset.Recordremove(java.lang.Integer id)Removes a record with a particular id from the Dataframe but does not update the metadata.booleanremove(java.lang.Object o)Removes the first occurrence of the specified element from this Dataframe, if it is present and it does not update the metadata.booleanremoveAll(java.util.Collection<?> c)Removes all of this collection's elements that are also contained in the specified collection and updates the metadata.booleanretainAll(java.util.Collection<?> c)Retains only the elements in this collection that are contained in the specified collection and updates the meta data.voidsave(java.lang.String storageName)Saves the Dataframe to disk.java.lang.Integerset(java.lang.Integer rId, Record r)Sets the record of a particular id in the dataset.intsize()Returns the total number of Records of the Dataframe.java.util.stream.Stream<Record>stream()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.Iterable<Record>values()Returns a read-only Iterable on the values of the Dataframe.intxColumnSize()Returns the total number of X columns in the Dataframe.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
COLUMN_NAME_Y
public static final java.lang.String COLUMN_NAME_Y
Internal name of the response variable.- See Also:
- Constant Field Values
-
COLUMN_NAME_CONSTANT
public static final java.lang.String COLUMN_NAME_CONSTANT
Internal name of the constant.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Dataframe
public Dataframe(Configuration configuration)
Public constructor of Dataframe.- Parameters:
configuration-
-
-
Method Detail
-
save
public void save(java.lang.String storageName)
Saves the Dataframe to disk.
-
delete
public void delete()
Deletes the Dataframe and removes all internal variables. Once you delete a dataset, the instance can no longer be used.
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
size
public int size()
Returns the total number of Records of the Dataframe.- Specified by:
sizein interfacejava.util.Collection<Record>- Returns:
-
isEmpty
public boolean isEmpty()
Checks if the Dataframe is empty.- Specified by:
isEmptyin interfacejava.util.Collection<Record>- Returns:
-
clear
public void clear()
Clears all the internal Records of the Dataframe. The Dataframe can be used after you clear it.- Specified by:
clearin interfacejava.util.Collection<Record>
-
add
public boolean add(Record r)
Adds a record in the Dataframe and updates the Meta data.- Specified by:
addin interfacejava.util.Collection<Record>- Parameters:
r-- Returns:
-
contains
public boolean contains(java.lang.Object o)
Checks if the Record exists in the Dataframe. Note that the Record is checked only for its x and y components.- Specified by:
containsin interfacejava.util.Collection<Record>- Parameters:
o-- Returns:
-
addAll
public boolean addAll(java.util.Collection<? extends Record> c)
- Specified by:
addAllin interfacejava.util.Collection<Record>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<Record>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<Record>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<Record>
-
iterator
public java.util.Iterator<Record> iterator()
Returns a read-only iterator on the values of the Dataframe.
-
stream
public java.util.stream.Stream<Record> stream()
- Specified by:
streamin interfacejava.util.Collection<Record>
-
remove
public boolean remove(java.lang.Object o)
Removes the first occurrence of the specified element from this Dataframe, if it is present and it does not update the metadata.- Specified by:
removein interfacejava.util.Collection<Record>- Parameters:
o-- Returns:
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
Removes all of this collection's elements that are also contained in the specified collection and updates the metadata.- Specified by:
removeAllin interfacejava.util.Collection<Record>- Parameters:
c-- Returns:
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection and updates the meta data.- Specified by:
retainAllin interfacejava.util.Collection<Record>- Parameters:
c-- Returns:
-
remove
public Record remove(java.lang.Integer id)
Removes a record with a particular id from the Dataframe but does not update the metadata.- Parameters:
id-- Returns:
-
indexOf
public java.lang.Integer indexOf(Record o)
Returns the index of the first occurrence of the specified element in this Dataframe, or null if this Dataframe does not contain the element. WARNING: The Records are checked only for their X and Y values, not for the yPredicted and yPredictedProbabilities values.- Parameters:
o-- Returns:
-
get
public Record get(java.lang.Integer id)
Returns a particular Record using its id.- Parameters:
id-- Returns:
-
addRecord
public java.lang.Integer addRecord(Record r)
Adds a Record in the Dataframe and returns its id.- Parameters:
r-- Returns:
-
set
public java.lang.Integer set(java.lang.Integer rId, Record r)Sets the record of a particular id in the dataset. If the record does not exist it will be added with the specific id and the next added record will have as id the next integer. Note that the meta-data are partially updated. This means that if the replaced Record contained a column which is now no longer available in the dataset, then the meta-data will not refect this update (the column will continue to exist in the meta data). If this is a problem, you should call the recalculateMeta() method to force them being recalculated.- Parameters:
rId-r-- Returns:
-
xColumnSize
public int xColumnSize()
Returns the total number of X columns in the Dataframe.- Returns:
-
getYDataType
public TypeInference.DataType getYDataType()
Returns the type of the response variable y.- Returns:
-
getXDataTypes
public java.util.Map<java.lang.Object,TypeInference.DataType> getXDataTypes()
Returns an Map with column names as index and DataTypes as values.- Returns:
-
getXColumn
public FlatDataList getXColumn(java.lang.Object column)
It extracts the values of a particular column from all records and stores them into an FlatDataList.- Parameters:
column-- Returns:
-
getYColumn
public FlatDataList getYColumn()
It extracts the values of the response variables from all observations and stores them into an FlatDataList.- Returns:
-
dropXColumns
public void dropXColumns(java.util.Set<java.lang.Object> columnSet)
Removes completely a list of columns from the dataset. The meta-data of the Dataframe are updated. The method internally uses threads.- Parameters:
columnSet-
-
getSubset
public Dataframe getSubset(FlatDataList idsCollection)
It generates and returns a new Dataframe which contains a subset of this Dataframe. All the Records of the returned Dataframe are copies of the original Records. The method is used for k-fold cross validation and sampling. Note that the Records in the new Dataframe have DIFFERENT ids from the original ones.- Parameters:
idsCollection-- Returns:
-
recalculateMeta
public void recalculateMeta()
It forces the recalculation of Meta data using the Records of the dataset.
-
copy
public Dataframe copy()
Copies itself and returns a new instance of the same type.
-
entries
public java.lang.Iterable<java.util.Map.Entry<java.lang.Integer,Record>> entries()
Returns a read-only Iterable on the keys and Records of the Dataframe.- Returns:
-
index
public java.lang.Iterable<java.lang.Integer> index()
Returns a read-only Iterable on the keys of the Dataframe.- Returns:
-
values
public java.lang.Iterable<Record> values()
Returns a read-only Iterable on the values of the Dataframe.- Returns:
-
_unsafe_set
public Record _unsafe_set(java.lang.Integer rId, Record r)
Sets the record in a particular position in the dataset, WITHOUT updating the internal meta-info and returns the previous value (null if not existed). This method is similar to set() and it allows quick updates on the dataset. Nevertheless it is not advised to use this method because unless you explicitly call the recalculateMeta() method, the meta data will be corrupted. If you do use this method, MAKE sure you perform the recalculation after you are done with the updates.- Parameters:
rId-r-- Returns:
-
-
DataMelt 3.0 © DataMelt by jWork.ORG