Documentation of 'com.datumbox.framework.core.common.dataobjects.Dataframe' Java class
Dataframe
com.datumbox.framework.core.common.dataobjects

Class 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 class  Dataframe.Builder
      The 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.String COLUMN_NAME_CONSTANT
      Internal name of the constant.
      static java.lang.String COLUMN_NAME_Y
      Internal 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).
      boolean add(Record r)
      Adds a record in the Dataframe and updates the Meta data.
      boolean addAll(java.util.Collection<? extends Record> c)
      java.lang.Integer addRecord(Record r)
      Adds a Record in the Dataframe and returns its id.
      void clear()
      Clears all the internal Records of the Dataframe.
      void close()
      boolean contains(java.lang.Object o)
      Checks if the Record exists in the Dataframe.
      boolean containsAll(java.util.Collection<?> c)
      Dataframe copy()
      Copies itself and returns a new instance of the same type.
      void delete()
      Deletes the Dataframe and removes all internal variables.
      void dropXColumns(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.
      Record get(java.lang.Integer id)
      Returns a particular Record using its id.
      Dataframe getSubset(FlatDataList idsCollection)
      It generates and returns a new Dataframe which contains a subset of this Dataframe.
      FlatDataList getXColumn(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.
      FlatDataList getYColumn()
      It extracts the values of the response variables from all observations and stores them into an FlatDataList.
      TypeInference.DataType getYDataType()
      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.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.
      boolean isEmpty()
      Checks if the Dataframe is empty.
      java.util.Iterator<Record> iterator()
      Returns a read-only iterator on the values of the Dataframe.
      void recalculateMeta()
      It forces the recalculation of Meta data using the Records of the dataset.
      Record remove(java.lang.Integer id)
      Removes a record with a particular id from the Dataframe but does not update the metadata.
      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.
      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.
      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.
      void save(java.lang.String storageName)
      Saves the Dataframe to disk.
      java.lang.Integer set(java.lang.Integer rId, Record r)
      Sets the record of a particular id in the dataset.
      int size()
      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.
      int xColumnSize()
      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
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, removeIf, spliterator
      • Methods inherited from interface java.lang.Iterable

        forEach
    • 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.
        Specified by:
        save in interface Savable
        Parameters:
        storageName -
      • delete

        public void delete()
        Deletes the Dataframe and removes all internal variables. Once you delete a dataset, the instance can no longer be used.
        Specified by:
        delete in interface Savable
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • size

        public int size()
        Returns the total number of Records of the Dataframe.
        Specified by:
        size in interface java.util.Collection<Record>
        Returns:
      • isEmpty

        public boolean isEmpty()
        Checks if the Dataframe is empty.
        Specified by:
        isEmpty in interface java.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:
        clear in interface java.util.Collection<Record>
      • add

        public boolean add(Record r)
        Adds a record in the Dataframe and updates the Meta data.
        Specified by:
        add in interface java.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:
        contains in interface java.util.Collection<Record>
        Parameters:
        o -
        Returns:
      • addAll

        public boolean addAll(java.util.Collection<? extends Record> c)
        Specified by:
        addAll in interface java.util.Collection<Record>
      • containsAll

        public boolean containsAll(java.util.Collection<?> c)
        Specified by:
        containsAll in interface java.util.Collection<Record>
      • toArray

        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<Record>
      • toArray

        public <T> T[] toArray(T[] a)
        Specified by:
        toArray in interface java.util.Collection<Record>
      • iterator

        public java.util.Iterator<Record> iterator()
        Returns a read-only iterator on the values of the Dataframe.
        Specified by:
        iterator in interface java.lang.Iterable<Record>
        Specified by:
        iterator in interface java.util.Collection<Record>
        Returns:
      • stream

        public java.util.stream.Stream<Record> stream()
        Specified by:
        stream in interface java.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:
        remove in interface java.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:
        removeAll in interface java.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:
        retainAll in interface java.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.
        Specified by:
        copy in interface Copyable<Dataframe>
        Returns:
      • 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

You see the box below because you did not login.