• Computes the confusion matrix from true labels and predicted labels.

    const labels = tf.tensor1d([0, 1, 2, 1, 0], 'int32');
    const predictions = tf.tensor1d([0, 2, 2, 1, 0], 'int32');
    const numClasses = 3;
    const out = tf.math.confusionMatrix(labels, predictions, numClasses);
    out.print();
    // Expected output matrix:
    // [[2, 0, 0],
    // [0, 1, 1],
    // [0, 0, 1]]

    Parameters

    • labels: TensorLike | Tensor1D

      The target labels, assumed to be 0-based integers for the classes. The shape is [numExamples], where numExamples is the number of examples included.

    • predictions: TensorLike | Tensor1D

      The predicted classes, assumed to be 0-based integers for the classes. Must have the same shape as labels.

    • numClasses: number

      Number of all classes, as an integer. Its value must be larger than the largest element in labels and predictions.

    Returns Tensor2D

    The confusion matrix as a int32-type 2D tensor. The value at row r and column c is the number of times examples of actual class r were predicted as class c.

    Doc

Generated using TypeDoc