Package weka.djl
Class InstancesDataset.InstancesBuilder<T extends InstancesDataset.InstancesBuilder<T>>
- java.lang.Object
-
- ai.djl.training.dataset.RandomAccessDataset.BaseBuilder<T>
-
- ai.djl.basicdataset.tabular.TabularDataset.BaseBuilder<T>
-
- weka.djl.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 aInstancesDataset
.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allFeaturesAdded
protected boolean
classAdded
protected int
classIndex
protected weka.core.Instances
data
protected boolean
dateColumnsAsNumeric
protected Set<String>
ignoredColumns
protected Set<String>
matchingFeaturesAdded
protected boolean
stringColumnsAsNominal
protected com.google.gson.JsonObject
structure
-
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 newInstancesDataset
.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
-
-
-
-
Field Detail
-
data
protected weka.core.Instances data
-
classIndex
protected int classIndex
-
classAdded
protected boolean classAdded
-
allFeaturesAdded
protected boolean allFeaturesAdded
-
stringColumnsAsNominal
protected boolean stringColumnsAsNominal
-
dateColumnsAsNumeric
protected boolean dateColumnsAsNumeric
-
structure
protected com.google.gson.JsonObject structure
-
-
Method Detail
-
self
protected T self()
- Specified by:
self
in classai.djl.training.dataset.RandomAccessDataset.BaseBuilder<T extends InstancesDataset.InstancesBuilder<T>>
-
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 columncolType
- the type of the columnisClassColumn
- 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
-
build
public InstancesDataset build()
Builds the newInstancesDataset
.- Returns:
- the new
InstancesDataset
-
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)
-
-