Class LabelConfusionMatrix

java.lang.Object
org.tribuo.classification.evaluation.LabelConfusionMatrix
All Implemented Interfaces:
ConfusionMatrix<Label>

public final class LabelConfusionMatrix extends Object implements ConfusionMatrix<Label>
A confusion matrix for Labels.

We interpret it as follows: C[i, j] = k means "the TRUE class 'j' was PREDICTED to be class 'i' a total of 'k' times".

In other words, the row indices correspond to the model's predictions, and the column indices correspond to the ground truth.

  • Constructor Details

    • LabelConfusionMatrix

      public LabelConfusionMatrix(Model<Label> model, List<Prediction<Label>> predictions)
      Creates a confusion matrix from the supplied predictions, using the label info from the supplied model.
      Parameters:
      model - The model to use for the label information.
      predictions - The predictions.
    • LabelConfusionMatrix

      public LabelConfusionMatrix(ImmutableOutputInfo<Label> domain, List<Prediction<Label>> predictions)
      Creates a confusion matrix from the supplied predictions and label info.
      Parameters:
      domain - The label information.
      predictions - The predictions.
      Throws:
      IllegalArgumentException - If the domain doesn't contain all the predictions.
  • Method Details

    • getDomain

      public ImmutableOutputInfo<Label> getDomain()
      Description copied from interface: ConfusionMatrix
      Returns the classification domain that this confusion matrix operates over.
      Specified by:
      getDomain in interface ConfusionMatrix<Label>
      Returns:
      The classification domain.
    • observed

      public Set<Label> observed()
      Description copied from interface: ConfusionMatrix
      The values this confusion matrix has seen.

      The default implementation is provided for compatibility reasons and will be removed in a future major release. It defaults to returning the output domain.

      Specified by:
      observed in interface ConfusionMatrix<Label>
      Returns:
      The set of observed outputs.
    • support

      public double support()
      Description copied from interface: ConfusionMatrix
      The number of examples this confusion matrix has seen.
      Specified by:
      support in interface ConfusionMatrix<Label>
      Returns:
      The number of examples.
    • support

      public double support(Label label)
      Description copied from interface: ConfusionMatrix
      The number of examples with this true label this confusion matrix has seen.
      Specified by:
      support in interface ConfusionMatrix<Label>
      Parameters:
      label - The label.
      Returns:
      The number of examples.
    • tp

      public double tp(Label cls)
      Description copied from interface: ConfusionMatrix
      The number of true positives for the supplied label.
      Specified by:
      tp in interface ConfusionMatrix<Label>
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • fp

      public double fp(Label cls)
      Description copied from interface: ConfusionMatrix
      The number of false positives for the supplied label.
      Specified by:
      fp in interface ConfusionMatrix<Label>
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • fn

      public double fn(Label cls)
      Description copied from interface: ConfusionMatrix
      The number of false negatives for the supplied label.
      Specified by:
      fn in interface ConfusionMatrix<Label>
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • tn

      public double tn(Label cls)
      Description copied from interface: ConfusionMatrix
      The number of true negatives for the supplied label.
      Specified by:
      tn in interface ConfusionMatrix<Label>
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • confusion

      public double confusion(Label predicted, Label trueClass)
      Description copied from interface: ConfusionMatrix
      The number of times the supplied predicted label was returned for the supplied true class.
      Specified by:
      confusion in interface ConfusionMatrix<Label>
      Parameters:
      predicted - The predicted label.
      trueClass - The true label.
      Returns:
      The number of examples predicted as predictedLabel when the true label was trueLabel.
    • setLabelOrder

      public void setLabelOrder(List<Label> newLabelOrder)
      Sets the label order used in toString().

      If the label order is a subset of the labels in the domain, only the labels present in the label order will be displayed.

      Specified by:
      setLabelOrder in interface ConfusionMatrix<Label>
      Parameters:
      newLabelOrder - The label order to use.
    • getLabelOrder

      public List<Label> getLabelOrder()
      Gets the current label order. May trigger order instantiation if the label order has not been set.
      Specified by:
      getLabelOrder in interface ConfusionMatrix<Label>
      Returns:
      The label order.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toHTML

      public String toHTML()
      Emits a HTML table representation of the Confusion Matrix.
      Returns:
      The confusion matrix as a HTML table.