Package weka.djl

Class InstancesDataset.InstancesBuilder<T extends InstancesDataset.InstancesBuilder<T>>

  • Enclosing class:
    InstancesDataset

    public static class InstancesDataset.InstancesBuilder<T extends InstancesDataset.InstancesBuilder<T>>
    extends ai.djl.basicdataset.tabular.TabularDataset.BaseBuilder<T>
    Used to build a InstancesDataset.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected InstancesBuilder()
      Initializes the builder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T addAllFeatures()
      Adds all features according to their types.
      protected void addColumn​(int index)
      Adds the column as feature or label.
      protected void addColumn​(String colName, InstancesAttributeType colType, boolean isClassColumn)
      Adds the column as feature or label.
      T addIgnoredColumn​(String... colNames)
      Adds the column name(s) to ignore when adding all features.
      T addMatchingFeatures​(String... regexp)
      Adds all feature columns which names match the regular expression(s).
      InstancesDataset build()
      Builds the new InstancesDataset.
      T classIndex​(int index)
      Sets the index of the column to use as class attribute.
      T classIsFirst()
      Sets the flag that the class attribute is the first column.
      T classIsLast()
      Sets the flag that the class attribute is the last column.
      T data​(weka.core.Instances data)
      Sets the underlying Instances object.
      T dateColumnsAsNumeric()
      Sets whether to treat DATE columns as NUMERIC ones.
      T fromJson​(com.google.gson.JsonObject structure)
      Configures the builder based on the structure.
      T fromJson​(String json)
      Configures the builder based on the structure.
      T fromJson​(Path path)
      Configures the builder based on the structure.
      weka.core.Instances getData()
      Returns the underlying data.
      T ignoreMatchingColumns​(String... regexp)
      Ignores all column names that match the regexp(s).
      protected void instancesRequired()
      Raises an exception if no data set.
      protected boolean isClassColumn​(int index)
      Checks if the specified column is the class attribute.
      protected T self()
      T stringColumnsAsNominal()
      Sets whether to treat STRING columns as NOMINAL ones.
      com.google.gson.JsonObject toJson()
      Returns the structure of the dataset as JSON.
      • Methods inherited from class ai.djl.basicdataset.tabular.TabularDataset.BaseBuilder

        addCategoricalFeature, addCategoricalFeature, addCategoricalFeature, addCategoricalLabel, addCategoricalLabel, addCategoricalLabel, addFeature, addLabel, addNumericFeature, addNumericFeature, addNumericLabel, addNumericLabel, noLabels
      • Methods inherited from class ai.djl.training.dataset.RandomAccessDataset.BaseBuilder

        addTargetTransform, addTransform, getSampler, optDataBatchifier, optDevice, optLabelBatchifier, optLimit, optPipeline, optPrefetchNumber, optTargetPipeline, setSampling, setSampling, setSampling
    • Field Detail

      • data

        protected weka.core.Instances data
      • classIndex

        protected int classIndex
      • ignoredColumns

        protected Set<String> ignoredColumns
      • classAdded

        protected boolean classAdded
      • allFeaturesAdded

        protected boolean allFeaturesAdded
      • matchingFeaturesAdded

        protected Set<String> matchingFeaturesAdded
      • stringColumnsAsNominal

        protected boolean stringColumnsAsNominal
      • dateColumnsAsNumeric

        protected boolean dateColumnsAsNumeric
      • structure

        protected com.google.gson.JsonObject structure
    • Constructor Detail

      • InstancesBuilder

        protected InstancesBuilder()
        Initializes the builder.
    • Method Detail

      • data

        public T data​(weka.core.Instances data)
        Sets the underlying Instances object.
        Parameters:
        data - the data to wrap
        Returns:
        this builder
      • instancesRequired

        protected void instancesRequired()
        Raises an exception if no data set.
        Throws:
        IllegalStateException - if no data set
      • dateColumnsAsNumeric

        public T dateColumnsAsNumeric()
        Sets whether to treat DATE columns as NUMERIC ones.
        Returns:
        this builder
      • stringColumnsAsNominal

        public T stringColumnsAsNominal()
        Sets whether to treat STRING columns as NOMINAL ones.
        Returns:
        this builder
      • classIndex

        public T classIndex​(int index)
        Sets the index of the column to use as class attribute.
        Parameters:
        index - the 0-based index (based on column in Instances)
        Returns:
        this builder
      • classIsFirst

        public T classIsFirst()
        Sets the flag that the class attribute is the first column.
        Returns:
        this builder
      • classIsLast

        public T classIsLast()
        Sets the flag that the class attribute is the last column.
        Returns:
        this builder
      • isClassColumn

        protected boolean isClassColumn​(int index)
        Checks if the specified column is the class attribute.
        Parameters:
        index - the column index in the dataset
        Returns:
        true if class column
      • addColumn

        protected void addColumn​(String colName,
                                 InstancesAttributeType colType,
                                 boolean isClassColumn)
        Adds the column as feature or label. Skips ignored columns.
        Parameters:
        colName - the name of the column
        colType - the type of the column
        isClassColumn - whether the column is a class attribute
      • addColumn

        protected void addColumn​(int index)
        Adds the column as feature or label. Skips ignored columns.
        Parameters:
        index - the index of the column to add
      • addIgnoredColumn

        public T addIgnoredColumn​(String... colNames)
        Adds the column name(s) to ignore when adding all features.
        Parameters:
        colNames - the name(s) of the column(s) to ignore
        Returns:
        this builder
      • ignoreMatchingColumns

        public T ignoreMatchingColumns​(String... regexp)
        Ignores all column names that match the regexp(s).
        Parameters:
        regexp - the regular expression(s) to use
        Returns:
        this builder
      • addAllFeatures

        public T addAllFeatures()
        Adds all features according to their types. Skips ignored column names and class attribute(s). Only gets executed once.
        Returns:
        this builder
      • addMatchingFeatures

        public T addMatchingFeatures​(String... regexp)
        Adds all feature columns which names match the regular expression(s). Skips ignored column names and class attribute(s). Only gets executed once per regular expression.
        Parameters:
        regexp - the regular expression(s) to apply
        Returns:
        this builder
      • toJson

        public com.google.gson.JsonObject toJson()
        Returns the structure of the dataset as JSON.
        Returns:
        the structure
      • getData

        public weka.core.Instances getData()
        Returns the underlying data.
        Returns:
        the wrapped data
      • fromJson

        public T fromJson​(Path path)
                   throws IOException
        Configures the builder based on the structure.
        Parameters:
        path - the path to the dataset structure JSON file to load and apply
        Returns:
        this builder
        Throws:
        IOException
        See Also:
        fromJson(JsonObject)
      • fromJson

        public T fromJson​(String json)
                   throws IOException
        Configures the builder based on the structure.
        Parameters:
        json - the JSON string to load the dataset structure from and apply
        Returns:
        this builder
        Throws:
        IOException
        See Also:
        fromJson(JsonObject)
      • fromJson

        public T fromJson​(com.google.gson.JsonObject structure)
        Configures the builder based on the structure.
        Parameters:
        structure - the dataset structure to use
        Returns:
        this builder
        See Also:
        toJson()