Package smile.data
Class AttributeDataset
- java.lang.Object
-
- smile.data.Dataset<double[]>
-
- smile.data.AttributeDataset
-
- All Implemented Interfaces:
java.lang.Iterable<Datum<double[]>>
public class AttributeDataset extends Dataset<double[]>
A dataset of fixed number of attributes. All attribute values are stored as double even if the attribute may be nominal, ordinal, string, or date. The dataset is stored row-wise internally, which is fast for frequently accessing instances of dataset.- Author:
- Haifeng Li
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AttributeDataset.Row
-
Field Summary
-
Fields inherited from class smile.data.Dataset
data, DATASET_HAS_NO_RESPONSE, description, name, response, RESPONSE_NOT_NOMINAL, RESPONSE_NOT_NUMERIC
-
-
Constructor Summary
Constructors Constructor Description AttributeDataset(java.lang.String name, double[][] x, double[] y)
Constructor.AttributeDataset(java.lang.String name, Attribute[] attributes)
Constructor.AttributeDataset(java.lang.String name, Attribute[] attributes, double[][] x, Attribute response, double[] y)
Constructor.AttributeDataset(java.lang.String name, Attribute[] attributes, Attribute response)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AttributeDataset.Row
add(double[] x)
Add a datum item into the dataset.AttributeDataset.Row
add(double[] x, double y)
Add a datum item into the dataset.AttributeDataset.Row
add(double[] x, double y, double weight)
Add a datum item into the dataset.AttributeDataset.Row
add(double[] x, int y)
Add a datum item into the dataset.AttributeDataset.Row
add(double[] x, int y, double weight)
Add a datum item into the dataset.AttributeDataset.Row
add(AttributeDataset.Row x)
Add a datum item into the dataset.Datum<double[]>
add(Datum<double[]> x)
Add a datum item into the dataset.Attribute[]
attributes()
Returns the list of attributes in this dataset.AttributeVector
column(int i)
Returns a column.AttributeVector
column(java.lang.String col)
Returns a column.AttributeDataset
columns(java.lang.String... cols)
Returns a dataset with selected columns.AttributeDataset
head(int n)
returns the first few rows.AttributeDataset
range(int from, int to)
Returns the rows in the given range [from, to).AttributeDataset
remove(java.lang.String... cols)
Returns a new dataset without given columns.AttributeDataset
summary()
Returns statistic summary.AttributeDataset
tail(int n)
Returns the last few rows.java.lang.String
toString()
java.lang.String
toString(int from, int to)
Stringify dataset.double[][]
x()
Returns the array of data items.-
Methods inherited from class smile.data.Dataset
data, get, getDescription, getName, iterator, labels, remove, response, responseAttribute, setDescription, setName, size, toArray, toArray, toArray, toArray, toArray, y
-
-
-
-
Constructor Detail
-
AttributeDataset
public AttributeDataset(java.lang.String name, Attribute[] attributes)
Constructor.- Parameters:
name
- the name of dataset.attributes
- the list of attributes in this dataset.
-
AttributeDataset
public AttributeDataset(java.lang.String name, Attribute[] attributes, Attribute response)
Constructor.- Parameters:
name
- the name of dataset.attributes
- the list of attributes in this dataset.response
- the attribute of response variable.
-
AttributeDataset
public AttributeDataset(java.lang.String name, double[][] x, double[] y)
Constructor.- Parameters:
name
- the name of dataset.x
- the data in this dataset.y
- the response data.
-
AttributeDataset
public AttributeDataset(java.lang.String name, Attribute[] attributes, double[][] x, Attribute response, double[] y)
Constructor.- Parameters:
name
- the name of dataset.attributes
- the list of attributes in this dataset.x
- the data in this dataset.response
- the attribute of response variable.y
- the response data.
-
-
Method Detail
-
attributes
public Attribute[] attributes()
Returns the list of attributes in this dataset.
-
x
public double[][] x()
Returns the array of data items.
-
add
public Datum<double[]> add(Datum<double[]> x)
Description copied from class:Dataset
Add a datum item into the dataset.
-
add
public AttributeDataset.Row add(AttributeDataset.Row x)
Add a datum item into the dataset.- Parameters:
x
- a datum item.- Returns:
- the added datum item.
-
add
public AttributeDataset.Row add(double[] x)
Description copied from class:Dataset
Add a datum item into the dataset.
-
add
public AttributeDataset.Row add(double[] x, int y)
Description copied from class:Dataset
Add a datum item into the dataset.
-
add
public AttributeDataset.Row add(double[] x, int y, double weight)
Description copied from class:Dataset
Add a datum item into the dataset.- Overrides:
add
in classDataset<double[]>
- Parameters:
x
- a datum item.y
- the class label of the datum.weight
- the weight of datum. The particular meaning of weight depends on applications and machine learning algorithms. Although there are on explicit requirements on the weights, in general, they should be positive.- Returns:
- the added datum item.
-
add
public AttributeDataset.Row add(double[] x, double y)
Description copied from class:Dataset
Add a datum item into the dataset.
-
add
public AttributeDataset.Row add(double[] x, double y, double weight)
Description copied from class:Dataset
Add a datum item into the dataset.- Overrides:
add
in classDataset<double[]>
- Parameters:
x
- a datum item.weight
- the weight of datum. The particular meaning of weight depends on applications and machine learning algorithms. Although there are on explicit requirements on the weights, in general, they should be positive.- Returns:
- the added datum item.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
head
public AttributeDataset head(int n)
returns the first few rows.
-
tail
public AttributeDataset tail(int n)
Returns the last few rows.
-
range
public AttributeDataset range(int from, int to)
Returns the rows in the given range [from, to).
-
toString
public java.lang.String toString(int from, int to)
Stringify dataset.- Parameters:
from
- starting row (inclusive)to
- ending row (exclusive)
-
column
public AttributeVector column(int i)
Returns a column.
-
column
public AttributeVector column(java.lang.String col)
Returns a column.
-
columns
public AttributeDataset columns(java.lang.String... cols)
Returns a dataset with selected columns.
-
remove
public AttributeDataset remove(java.lang.String... cols)
Returns a new dataset without given columns.
-
summary
public AttributeDataset summary()
Returns statistic summary.
-
-