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
ExtendedDefaultSpreadSheetclass, 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_ClassAttributesthe 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 voidassign(SpreadSheet sheet)Clears this spreadsheet and copies all the data from the given one.voidclear()Removes all cells, but leaves comments.StringequalsHeader(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.DatasetgetClone()Returns a clone of itself.DatasetgetHeader()Returns the a spreadsheet with the same header and comments.SpreadSheetgetInputs()Returns a spreadsheet containing only the input columns, not class columns.SpreadSheetgetOutputs()Returns a spreadsheet containing only output columns, i.e., the class columns.intindexOfColumn(String name)Returns the index of the column using the specified name.protected voidinitialize()Initializes the members.booleanisClassAttribute(int colIndex)Returns whether the specified column is a class attribute.booleanisClassAttribute(String colKey)Returns whether the specified column is a class attribute.booleanisClassAttributeByName(String name)Returns whether the specified column is a class attribute.voidmergeWith(SpreadSheet other)Puts the content of the provided spreadsheet on the right.voidremoveClassAttributes()Removes all set class attributes.booleanremoveColumn(String columnKey)Removes the specified column.booleansetClassAttribute(int colIndex, boolean isClass)Sets the class attribute status for a column.booleansetClassAttribute(String colKey, boolean isClass)Sets the class attribute status for a column.booleansetClassAttributeByName(String name, boolean isClass)Sets the class attribute status for a column.DatasetViewtoView(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:
initializein classDefaultSpreadSheet
-
clear
public void clear()
Removes all cells, but leaves comments.- Specified by:
clearin interfaceSpreadSheet- Overrides:
clearin classDefaultSpreadSheet
-
assign
public void assign(SpreadSheet sheet)
Clears this spreadsheet and copies all the data from the given one.- Specified by:
assignin interfaceSpreadSheet- Overrides:
assignin classDefaultSpreadSheet- Parameters:
sheet- the data to copy
-
getClone
public Dataset getClone()
Returns a clone of itself.- Specified by:
getClonein interfaceCloneHandler<SpreadSheet>- Specified by:
getClonein interfaceDataset- Specified by:
getClonein interfaceSpreadSheet- Overrides:
getClonein classDefaultSpreadSheet- Returns:
- the clone
-
getHeader
public Dataset getHeader()
Returns the a spreadsheet with the same header and comments.- Specified by:
getHeaderin interfaceDataset- Specified by:
getHeaderin interfaceSpreadSheet- Overrides:
getHeaderin classDefaultSpreadSheet- Returns:
- the spreadsheet
-
indexOfColumn
public int indexOfColumn(String name)
Returns the index of the column using the specified name.- Specified by:
indexOfColumnin 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:
removeColumnin interfaceSpreadSheet- Overrides:
removeColumnin classDefaultSpreadSheet- Parameters:
columnKey- the column to remove- Returns:
- true if removed
-
removeClassAttributes
public void removeClassAttributes()
Removes all set class attributes.- Specified by:
removeClassAttributesin interfaceDataset
-
isClassAttribute
public boolean isClassAttribute(String colKey)
Returns whether the specified column is a class attribute.- Specified by:
isClassAttributein 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:
isClassAttributein 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:
isClassAttributeByNamein 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:
setClassAttributein 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:
setClassAttributein 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:
setClassAttributeByNamein 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:
getClassAttributeKeysin 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:
getClassAttributeNamesin 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:
getClassAttributeIndicesin 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:
equalsHeaderin interfaceSpreadSheet- Overrides:
equalsHeaderin 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:
mergeWithin interfaceMergeable<SpreadSheet>- Specified by:
mergeWithin interfaceSpreadSheet- Overrides:
mergeWithin 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:
getOutputsin 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:
toViewin interfaceSpreadSheet- Overrides:
toViewin classDefaultSpreadSheet- Parameters:
columns- the columns to use, null for allrows- the rows to use, null for all- Returns:
- the view
-
-