Package adams.ml.data
Class DefaultDataset
- java.lang.Object
-
- adams.data.spreadsheet.DefaultSpreadSheet
-
- adams.ml.data.DefaultDataset
-
- All Implemented Interfaces:
CloneHandler<SpreadSheet>
,LocaleSupporter
,Mergeable<SpreadSheet>
,SpreadSheet
,Dataset
,Serializable
public class DefaultDataset extends DefaultSpreadSheet implements Dataset
ExtendedDefaultSpreadSheet
class, providing additional machine learning functionality.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected HashSet<String>
m_ClassAttributes
the keys of the columns that act as class attribute.-
Fields inherited from class adams.data.spreadsheet.DefaultSpreadSheet
COMMENT, m_Comments, m_DataRowClass, m_DataRowConstructor, m_DateFormat, m_DateTimeFormat, m_DateTimeMsecFormat, m_HeaderRow, m_Locale, m_Name, m_NumberFormat, m_RowKeys, m_Rows, m_StringsTable, m_TimeFormat, m_TimeMsecFormat, MISSING_VALUE
-
Fields inherited from interface adams.data.spreadsheet.SpreadSheet
COMMENT, MISSING_VALUE
-
-
Constructor Summary
Constructors Constructor Description DefaultDataset()
Default constructor.DefaultDataset(SpreadSheet sheet)
Initializes the dataset with the data from the spreadsheet.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assign(SpreadSheet sheet)
Clears this spreadsheet and copies all the data from the given one.void
clear()
Removes all cells, but leaves comments.String
equalsHeader(SpreadSheet other)
Compares the header of this spreadsheet with the other one.int[]
getClassAttributeIndices()
Returns all the class attributes that are currently set.String[]
getClassAttributeKeys()
Returns all the class attributes that are currently set.String[]
getClassAttributeNames()
Returns all the class attributes that are currently set.Dataset
getClone()
Returns a clone of itself.Dataset
getHeader()
Returns the a spreadsheet with the same header and comments.SpreadSheet
getInputs()
Returns a spreadsheet containing only the input columns, not class columns.SpreadSheet
getOutputs()
Returns a spreadsheet containing only output columns, i.e., the class columns.int
indexOfColumn(String name)
Returns the index of the column using the specified name.protected void
initialize()
Initializes the members.boolean
isClassAttribute(int colIndex)
Returns whether the specified column is a class attribute.boolean
isClassAttribute(String colKey)
Returns whether the specified column is a class attribute.boolean
isClassAttributeByName(String name)
Returns whether the specified column is a class attribute.void
mergeWith(SpreadSheet other)
Puts the content of the provided spreadsheet on the right.void
removeClassAttributes()
Removes all set class attributes.boolean
removeColumn(String columnKey)
Removes the specified column.boolean
setClassAttribute(int colIndex, boolean isClass)
Sets the class attribute status for a column.boolean
setClassAttribute(String colKey, boolean isClass)
Sets the class attribute status for a column.boolean
setClassAttributeByName(String name, boolean isClass)
Sets the class attribute status for a column.DatasetView
toView(int[] rows, int[] columns)
Creates a view of the spreadsheet with the specified rows/columns.-
Methods inherited from class adams.data.spreadsheet.DefaultSpreadSheet
addComment, addComment, addRow, addRow, calculate, getCell, getCellIndex, getCellPosition, getCellValues, getCellValues, getColumnCount, getColumnName, getColumnNames, getComments, getContentType, getContentTypes, getDataRowClass, getDateFormat, getDateTimeFormat, getDateTimeMsecFormat, getHeaderRow, getLocale, getName, getNumberFormat, getRow, getRow, getRowCount, getRowIndex, getRowKey, getSharedStringsTable, getTimeFormat, getTimeMsecFormat, getTimeZone, hasCell, hasName, hasRow, hasRow, insertColumn, insertColumn, insertColumn, insertRow, isContentType, isDateLenient, isDateTimeLenient, isDateTimeMsecLenient, isNumeric, isNumeric, isTimeLenient, isTimeMsecLenient, main, newCell, newInstance, newRow, removeColumn, removeMissing, removeRow, removeRow, rowKeys, rows, setDataRowClass, setDateLenient, setDateTimeLenient, setDateTimeMsecLenient, setLocale, setName, setTimeLenient, setTimeMsecLenient, setTimeZone, sort, sort, sort, sortRowKeys, sortRowKeys, toMatrix, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.data.spreadsheet.SpreadSheet
addComment, addComment, addRow, addRow, calculate, getCell, getCellIndex, getCellPosition, getCellValues, getCellValues, getColumnCount, getColumnName, getColumnNames, getComments, getContentType, getContentTypes, getDataRowClass, getDateFormat, getDateTimeFormat, getDateTimeMsecFormat, getHeaderRow, getLocale, getName, getNumberFormat, getRow, getRow, getRowCount, getRowIndex, getRowKey, getSharedStringsTable, getTimeFormat, getTimeMsecFormat, getTimeZone, hasCell, hasName, hasRow, hasRow, insertColumn, insertColumn, insertColumn, insertRow, isContentType, isDateLenient, isDateTimeLenient, isDateTimeMsecLenient, isNumeric, isNumeric, isTimeLenient, isTimeMsecLenient, newCell, newInstance, removeColumn, removeMissing, removeRow, removeRow, rowKeys, rows, setDataRowClass, setDateLenient, setDateTimeLenient, setDateTimeMsecLenient, setLocale, setName, setTimeLenient, setTimeMsecLenient, setTimeZone, sort, sort, sort, sortRowKeys, sortRowKeys, toMatrix, toString
-
-
-
-
Constructor Detail
-
DefaultDataset
public DefaultDataset()
Default constructor.
-
DefaultDataset
public DefaultDataset(SpreadSheet sheet)
Initializes the dataset with the data from the spreadsheet.- Parameters:
sheet
- the data to use
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classDefaultSpreadSheet
-
clear
public void clear()
Removes all cells, but leaves comments.- Specified by:
clear
in interfaceSpreadSheet
- Overrides:
clear
in classDefaultSpreadSheet
-
assign
public void assign(SpreadSheet sheet)
Clears this spreadsheet and copies all the data from the given one.- Specified by:
assign
in interfaceSpreadSheet
- Overrides:
assign
in classDefaultSpreadSheet
- Parameters:
sheet
- the data to copy
-
getClone
public Dataset getClone()
Returns a clone of itself.- Specified by:
getClone
in interfaceCloneHandler<SpreadSheet>
- Specified by:
getClone
in interfaceDataset
- Specified by:
getClone
in interfaceSpreadSheet
- Overrides:
getClone
in classDefaultSpreadSheet
- Returns:
- the clone
-
getHeader
public Dataset getHeader()
Returns the a spreadsheet with the same header and comments.- Specified by:
getHeader
in interfaceDataset
- Specified by:
getHeader
in interfaceSpreadSheet
- Overrides:
getHeader
in classDefaultSpreadSheet
- Returns:
- the spreadsheet
-
indexOfColumn
public int indexOfColumn(String name)
Returns the index of the column using the specified name.- Specified by:
indexOfColumn
in interfaceDataset
- Parameters:
name
- the name of the column to locate- Returns:
- the index, -1 if failed to locate
-
removeColumn
public boolean removeColumn(String columnKey)
Removes the specified column.- Specified by:
removeColumn
in interfaceSpreadSheet
- Overrides:
removeColumn
in classDefaultSpreadSheet
- Parameters:
columnKey
- the column to remove- Returns:
- true if removed
-
removeClassAttributes
public void removeClassAttributes()
Removes all set class attributes.- Specified by:
removeClassAttributes
in interfaceDataset
-
isClassAttribute
public boolean isClassAttribute(String colKey)
Returns whether the specified column is a class attribute.- Specified by:
isClassAttribute
in interfaceDataset
- Parameters:
colKey
- they key of the column to query- Returns:
- true if column a class attribute
-
isClassAttribute
public boolean isClassAttribute(int colIndex)
Returns whether the specified column is a class attribute.- Specified by:
isClassAttribute
in interfaceDataset
- Parameters:
colIndex
- they index of the column to query- Returns:
- true if column a class attribute
-
isClassAttributeByName
public boolean isClassAttributeByName(String name)
Returns whether the specified column is a class attribute.- Specified by:
isClassAttributeByName
in interfaceDataset
- Parameters:
name
- they name of the column to query- Returns:
- true if column a class attribute
-
setClassAttribute
public boolean setClassAttribute(String colKey, boolean isClass)
Sets the class attribute status for a column.- Specified by:
setClassAttribute
in interfaceDataset
- Parameters:
colKey
- the column to set the class attribute status forisClass
- if true then the column will be flagged as class attribute, otherwise the flag will get removed- Returns:
- true if successfully updated
-
setClassAttribute
public boolean setClassAttribute(int colIndex, boolean isClass)
Sets the class attribute status for a column.- Specified by:
setClassAttribute
in interfaceDataset
- Parameters:
colIndex
- the column to set the class attribute status forisClass
- if true then the column will be flagged as class attribute, otherwise the flag will get removed- Returns:
- true if successfully updated
-
setClassAttributeByName
public boolean setClassAttributeByName(String name, boolean isClass)
Sets the class attribute status for a column.- Specified by:
setClassAttributeByName
in interfaceDataset
- Parameters:
name
- the name of the column to set the class attribute status forisClass
- if true then the column will be flagged as class attribute, otherwise the flag will get removed- Returns:
- true if successfully updated
-
getClassAttributeKeys
public String[] getClassAttributeKeys()
Returns all the class attributes that are currently set.- Specified by:
getClassAttributeKeys
in interfaceDataset
- Returns:
- the column keys of class attributes (not ordered)
-
getClassAttributeNames
public String[] getClassAttributeNames()
Returns all the class attributes that are currently set.- Specified by:
getClassAttributeNames
in interfaceDataset
- Returns:
- the column names of class attributes (not ordered)
-
getClassAttributeIndices
public int[] getClassAttributeIndices()
Returns all the class attributes that are currently set.- Specified by:
getClassAttributeIndices
in interfaceDataset
- Returns:
- the indices of class attributes (sorted asc)
-
equalsHeader
public String equalsHeader(SpreadSheet other)
Compares the header of this spreadsheet with the other one.- Specified by:
equalsHeader
in interfaceSpreadSheet
- Overrides:
equalsHeader
in classDefaultSpreadSheet
- Parameters:
other
- the other spreadsheet to compare with- Returns:
- null if equal, otherwise details what differs
-
mergeWith
public void mergeWith(SpreadSheet other)
Puts the content of the provided spreadsheet on the right.- Specified by:
mergeWith
in interfaceMergeable<SpreadSheet>
- Specified by:
mergeWith
in interfaceSpreadSheet
- Overrides:
mergeWith
in classDefaultSpreadSheet
- Parameters:
other
- the spreadsheet to merge with
-
getInputs
public SpreadSheet getInputs()
Returns a spreadsheet containing only the input columns, not class columns.
-
getOutputs
public SpreadSheet getOutputs()
Returns a spreadsheet containing only output columns, i.e., the class columns.- Specified by:
getOutputs
in interfaceDataset
- Returns:
- the output features, null if data has no class columns
-
toView
public DatasetView toView(int[] rows, int[] columns)
Creates a view of the spreadsheet with the specified rows/columns.- Specified by:
toView
in interfaceSpreadSheet
- Overrides:
toView
in classDefaultSpreadSheet
- Parameters:
columns
- the columns to use, null for allrows
- the rows to use, null for all- Returns:
- the view
-
-