Package adams.flow.transformer
Class ConfusionMatrix
-
- All Implemented Interfaces:
AdditionalInformationHandler
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,VariablesInspectionHandler
,VariableChangeListener
,Actor
,ErrorHandler
,InputConsumer
,OutputProducer
,Serializable
,Comparable
public class ConfusionMatrix extends AbstractTransformer
Generates a confusion matrix from the specified actual and predicted columns containing class labels.
Can take a probability column (of prediction) into account for generating weighted counts.
Input/output:
- accepts:
adams.data.spreadsheet.SpreadSheet
- generates:
adams.data.spreadsheet.SpreadSheet
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-name <java.lang.String> (property: name) The name of the actor. default: ConfusionMatrix
-annotation <adams.core.base.BaseAnnotation> (property: annotations) The annotations to attach to this actor. default:
-skip <boolean> (property: skip) If set to true, transformation is skipped and the input token is just forwarded as it is. default: false
-stop-flow-on-error <boolean> (property: stopFlowOnError) If set to true, the flow execution at this level gets stopped in case this actor encounters an error; the error gets propagated; useful for critical actors. default: false
-silent <boolean> (property: silent) If enabled, then no errors are output in the console; Note: the enclosing actor handler must have this enabled as well. default: false
-actual-column <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: actualColumn) The column with the actual labels. default: 1 example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
-actual-prefix <java.lang.String> (property: actualPrefix) The prefix for the actual labels. default: a:
-predicted-column <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: predictedColumn) The column with the predicted labels. default: 2 example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
-predicted-prefix <java.lang.String> (property: predictedPrefix) The prefix for the predicted labels. default: p:
-probability-column <adams.data.spreadsheet.SpreadSheetColumnIndex> (property: probabilityColumn) The (optional) column with the probabilities; if not available probability of 1 is assumed. default: example: An index is a number starting with 1; column names (case-sensitive) as well as the following placeholders can be used: first, second, third, last_2, last_1, last; numeric indices can be enforced by preceding them with '#' (eg '#12'); column names can be surrounded by double quotes.
-matrix-values <COUNTS|PERCENTAGES|PERCENTAGES_PER_ROW> (property: matrixValues) The type of values to generate. default: COUNTS
-class-labels <adams.core.base.BaseString> [-class-labels ...] (property: classLabels) The class labels to use for enforcing order other than alphabetical. default:
-enumerate-labels <boolean> (property: enumerateLabels) If enable, enumerates the labels in the matrix and outputs a second spreadsheet with index/label relation. default: false
-combine-label-columns <boolean> (property: combineLabelColumns) If enable, combines the label columns of the label key matrix when enumerating the labels (if act/pred labels are the same). default: false
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConfusionMatrix.MatrixValues
Defines what values to show.
-
Field Summary
Fields Modifier and Type Field Description protected SpreadSheetColumnIndex
m_ActualColumn
the column with the actual labels.protected String
m_ActualPrefix
the optional prefix for the actual labels.protected BaseString[]
m_ClassLabels
the class labels to use (to enforce ordering other than sorted).protected boolean
m_CombineLabelColumns
combine label columns if same.protected boolean
m_EnumerateLabels
whether to number columns instead of using labels.protected ConfusionMatrix.MatrixValues
m_MatrixValues
what values to generate.protected SpreadSheetColumnIndex
m_PredictedColumn
the column with the predicted labels.protected String
m_PredictedPrefix
the optional prefix for the predicted labels.protected SpreadSheetColumnIndex
m_ProbabilityColumn
the column with the probabilities.-
Fields inherited from class adams.flow.transformer.AbstractTransformer
BACKUP_INPUT, BACKUP_OUTPUT, m_InputToken, m_OutputToken
-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description ConfusionMatrix()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class[]
accepts()
Returns the class that the consumer accepts.String
actualColumnTipText()
Returns the tip text for this property.String
actualPrefixTipText()
Returns the tip text for this property.String
classLabelsTipText()
Returns the tip text for this property.String
combineLabelColumnsTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.protected String
doExecute()
Executes the flow item.String
enumerateLabelsTipText()
Returns the tip text for this property.Class[]
generates()
Returns the class of objects that it generates.SpreadSheetColumnIndex
getActualColumn()
Returns the column of the actual labels.String
getActualPrefix()
Returns the prefix of the actual labels.BaseString[]
getClassLabels()
Returns the class labels to use for enforcing order other than alphabetical.boolean
getCombineLabelColumns()
Returns whether to combine the label columns of the label key matrix when enumerating the labels (act/pred must be same).boolean
getEnumerateLabels()
Returns whether to enumerate the labels rather than using the labels in the matrix.protected String
getLabel(List<String> labels, int index)
Returns the actual label to use.ConfusionMatrix.MatrixValues
getMatrixValues()
Returns the type of values to generate.SpreadSheetColumnIndex
getPredictedColumn()
Returns the column of the predicted labels.String
getPredictedPrefix()
Returns the prefix of the predicted labels.SpreadSheetColumnIndex
getProbabilityColumn()
Returns the column with the probabilities (optional).String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.String
globalInfo()
Returns a string describing the object.String
matrixValuesTipText()
Returns the tip text for this property.String
predictedColumnTipText()
Returns the tip text for this property.String
predictedPrefixTipText()
Returns the tip text for this property.String
probabilityColumnTipText()
Returns the tip text for this property.void
setActualColumn(SpreadSheetColumnIndex value)
Sets the column of the actual labels.void
setActualPrefix(String value)
Sets the prefix of the actual labels.void
setClassLabels(BaseString[] value)
Sets the class labels to use for enforcing order other than alphabetical.void
setCombineLabelColumns(boolean value)
Sets whether to combine the label columns of the label key matrix when enumerating the labels (act/pred must be same).void
setEnumerateLabels(boolean value)
Sets whether to enumerate the labels rather than using the labels in the matrix.void
setMatrixValues(ConfusionMatrix.MatrixValues value)
Sets the type of values to generate.void
setPredictedColumn(SpreadSheetColumnIndex value)
Sets the column of the predicted labels.void
setPredictedPrefix(String value)
Sets the prefix of the predicted labels.void
setProbabilityColumn(SpreadSheetColumnIndex value)
Sets the column with the probabilities (optional).-
Methods inherited from class adams.flow.transformer.AbstractTransformer
backupState, currentInput, execute, hasInput, hasPendingOutput, input, output, postExecute, restoreState, wrapUp
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, initialize, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, preExecute, pruneBackup, pruneBackup, reset, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
cleanUp, compareTo, destroy, equals, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setUp, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, stopExecution, toCommandLine, variableChanged
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
Methods inherited from interface adams.core.VariablesInspectionHandler
canInspectOptions
-
-
-
-
Field Detail
-
m_ActualColumn
protected SpreadSheetColumnIndex m_ActualColumn
the column with the actual labels.
-
m_ActualPrefix
protected String m_ActualPrefix
the optional prefix for the actual labels.
-
m_PredictedColumn
protected SpreadSheetColumnIndex m_PredictedColumn
the column with the predicted labels.
-
m_PredictedPrefix
protected String m_PredictedPrefix
the optional prefix for the predicted labels.
-
m_ProbabilityColumn
protected SpreadSheetColumnIndex m_ProbabilityColumn
the column with the probabilities.
-
m_MatrixValues
protected ConfusionMatrix.MatrixValues m_MatrixValues
what values to generate.
-
m_ClassLabels
protected BaseString[] m_ClassLabels
the class labels to use (to enforce ordering other than sorted).
-
m_EnumerateLabels
protected boolean m_EnumerateLabels
whether to number columns instead of using labels.
-
m_CombineLabelColumns
protected boolean m_CombineLabelColumns
combine label columns if same.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractActor
- Returns:
- null if no info available, otherwise short string
-
setActualColumn
public void setActualColumn(SpreadSheetColumnIndex value)
Sets the column of the actual labels.- Parameters:
value
- the index
-
getActualColumn
public SpreadSheetColumnIndex getActualColumn()
Returns the column of the actual labels.- Returns:
- the index
-
actualColumnTipText
public String actualColumnTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setActualPrefix
public void setActualPrefix(String value)
Sets the prefix of the actual labels.- Parameters:
value
- the prefix
-
getActualPrefix
public String getActualPrefix()
Returns the prefix of the actual labels.- Returns:
- the prefix
-
actualPrefixTipText
public String actualPrefixTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPredictedColumn
public void setPredictedColumn(SpreadSheetColumnIndex value)
Sets the column of the predicted labels.- Parameters:
value
- the index
-
getPredictedColumn
public SpreadSheetColumnIndex getPredictedColumn()
Returns the column of the predicted labels.- Returns:
- the index
-
predictedColumnTipText
public String predictedColumnTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setPredictedPrefix
public void setPredictedPrefix(String value)
Sets the prefix of the predicted labels.- Parameters:
value
- the prefix
-
getPredictedPrefix
public String getPredictedPrefix()
Returns the prefix of the predicted labels.- Returns:
- the prefix
-
predictedPrefixTipText
public String predictedPrefixTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setProbabilityColumn
public void setProbabilityColumn(SpreadSheetColumnIndex value)
Sets the column with the probabilities (optional).- Parameters:
value
- the index
-
getProbabilityColumn
public SpreadSheetColumnIndex getProbabilityColumn()
Returns the column with the probabilities (optional).- Returns:
- the index
-
probabilityColumnTipText
public String probabilityColumnTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setMatrixValues
public void setMatrixValues(ConfusionMatrix.MatrixValues value)
Sets the type of values to generate.- Parameters:
value
- the type of values
-
getMatrixValues
public ConfusionMatrix.MatrixValues getMatrixValues()
Returns the type of values to generate.- Returns:
- the type of values
-
matrixValuesTipText
public String matrixValuesTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setClassLabels
public void setClassLabels(BaseString[] value)
Sets the class labels to use for enforcing order other than alphabetical.- Parameters:
value
- the labels
-
getClassLabels
public BaseString[] getClassLabels()
Returns the class labels to use for enforcing order other than alphabetical.- Returns:
- the labels
-
classLabelsTipText
public String classLabelsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setEnumerateLabels
public void setEnumerateLabels(boolean value)
Sets whether to enumerate the labels rather than using the labels in the matrix.- Parameters:
value
- true if to enumerate
-
getEnumerateLabels
public boolean getEnumerateLabels()
Returns whether to enumerate the labels rather than using the labels in the matrix.- Returns:
- true if to enumerate
-
enumerateLabelsTipText
public String enumerateLabelsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setCombineLabelColumns
public void setCombineLabelColumns(boolean value)
Sets whether to combine the label columns of the label key matrix when enumerating the labels (act/pred must be same).- Parameters:
value
- true if to combine (if possible)
-
getCombineLabelColumns
public boolean getCombineLabelColumns()
Returns whether to combine the label columns of the label key matrix when enumerating the labels (act/pred must be same).- Returns:
- true if to combine (if possible)
-
combineLabelColumnsTipText
public String combineLabelColumnsTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
accepts
public Class[] accepts()
Returns the class that the consumer accepts.- Returns:
- adams.core.io.SpreadSheet.class
-
generates
public Class[] generates()
Returns the class of objects that it generates.- Returns:
- adams.core.io.SpreadSheet.class
-
getLabel
protected String getLabel(List<String> labels, int index)
Returns the actual label to use.- Parameters:
labels
- the list of labelsindex
- the index of the label- Returns:
- the label to use
-
doExecute
protected String doExecute()
Executes the flow item.- Specified by:
doExecute
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
-
-