Interface ConfusionMatrix<T extends Classifiable<T>>

Type Parameters:
T - The type of the output.
All Known Implementing Classes:
LabelConfusionMatrix, MultiLabelConfusionMatrix

public interface ConfusionMatrix<T extends Classifiable<T>>
A confusion matrix for Classifiables.

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.

  • Method Summary

    Modifier and Type
    Method
    Description
    double
    confusion(T predictedLabel, T trueLabel)
    The number of times the supplied predicted label was returned for the supplied true class.
    default double
    fn()
    The total number of false negatives.
    double
    fn(T cls)
    The number of false negatives for the supplied label.
    default double
    fp()
    The total number of false positives.
    double
    fp(T cls)
    The number of false positives for the supplied label.
    Returns the classification domain that this confusion matrix operates over.
    default List<T>
    The label order this confusion matrix uses in toString.
    default Set<T>
    The values this confusion matrix has seen.
    default void
    setLabelOrder(List<T> labelOrder)
    Sets the label order this confusion matrix uses in toString.
    static <T extends Classifiable<T>>
    double
    Sums the supplied getter over the domain.
    double
    The number of examples this confusion matrix has seen.
    double
    support(T cls)
    The number of examples with this true label this confusion matrix has seen.
    default double
    tn()
    The total number of true negatives.
    double
    tn(T cls)
    The number of true negatives for the supplied label.
    default double
    tp()
    The total number of true positives.
    double
    tp(T cls)
    The number of true positives for the supplied label.
  • Method Details

    • getDomain

      ImmutableOutputInfo<T> getDomain()
      Returns the classification domain that this confusion matrix operates over.
      Returns:
      The classification domain.
    • support

      double support()
      The number of examples this confusion matrix has seen.
      Returns:
      The number of examples.
    • support

      double support(T cls)
      The number of examples with this true label this confusion matrix has seen.
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • tp

      double tp(T cls)
      The number of true positives for the supplied label.
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • fp

      double fp(T cls)
      The number of false positives for the supplied label.
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • fn

      double fn(T cls)
      The number of false negatives for the supplied label.
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • tn

      double tn(T cls)
      The number of true negatives for the supplied label.
      Parameters:
      cls - The label.
      Returns:
      The number of examples.
    • confusion

      double confusion(T predictedLabel, T trueLabel)
      The number of times the supplied predicted label was returned for the supplied true class.
      Parameters:
      predictedLabel - The predicted label.
      trueLabel - The true label.
      Returns:
      The number of examples predicted as predictedLabel when the true label was trueLabel.
    • tp

      default double tp()
      The total number of true positives.
      Returns:
      The total true positives.
    • fp

      default double fp()
      The total number of false positives.
      Returns:
      The total false positives.
    • fn

      default double fn()
      The total number of false negatives.
      Returns:
      The total false negatives.
    • tn

      default double tn()
      The total number of true negatives.
      Returns:
      The total true negatives.
    • observed

      default Set<T> observed()
      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.

      Returns:
      The set of observed outputs.
    • getLabelOrder

      default List<T> getLabelOrder()
      The label order this confusion matrix uses in toString.

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

      Returns:
      An unmodifiable view on the label order.
    • setLabelOrder

      default void setLabelOrder(List<T> labelOrder)
      Sets the label order this confusion matrix uses 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.

      The default implementation does not set the label order and is provided for backwards compatibility reasons. It should be overridden in all subclasses to ensure correct behaviour, and this default implementation will be removed in a future major release.

      Parameters:
      labelOrder - The label order.
    • sumOverOutputs

      static <T extends Classifiable<T>> double sumOverOutputs(ImmutableOutputInfo<T> domain, ToDoubleFunction<T> getter)
      Sums the supplied getter over the domain.
      Type Parameters:
      T - The type of the output.
      Parameters:
      domain - The domain to sum over.
      getter - The getter to use.
      Returns:
      The total summed over the domain.