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
    • Field Detail

      • m_ActualPrefix

        protected String m_ActualPrefix
        the optional prefix for the actual 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_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.
    • Constructor Detail

      • ConfusionMatrix

        public ConfusionMatrix()
    • Method Detail

      • 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 labels
        index - the index of the label
        Returns:
        the label to use
      • doExecute

        protected String doExecute()
        Executes the flow item.
        Specified by:
        doExecute in class AbstractActor
        Returns:
        null if everything is fine, otherwise error message