Teradata Package for R Function Reference | 17.00 - 17.00 - ConfusionMatrix - Teradata Package for R

Teradata® Package for R Function Reference

Teradata Package for R
Release Number
Release Date
July 2021
Content Type
Programming Reference
Publication ID
English (United States)


The ConfusionMatrix function shows how often a classification algorithm correctly classifies items. The function takes an input tbl_teradata that includes two columns, one containing the observed class of an item and the other containing the class predicted by the algorithm, and outputs three tbl_teradata objects.


  td_confusion_matrix_mle (
      data = NULL,
      reference = NULL,
      prediction = NULL,
      classes = NULL,
      prevalence = NULL,
      data.sequence.column = NULL



Required Argument.
Specifies the input tbl_teradata that is used to generate Confusion Matrix.


Required Argument.
Specifies the name of the input column that contains the observed class.
Types: character


Required Argument.
Specifies the name of the input column that contains the predicted class.
Types: character


Optional Argument.
Specifies the classes to output in output tbl_teradata.
Types: character OR vector of characters


Optional Argument.
Specifies the prevalences for the classes to output in third output tbl_teradata which contains statistics for each class. Therefore, if you specify prevalence, then you must also specify classes, and for every class, you must specify a prevalence.
Types: numeric OR vector of numerics


Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)


Function returns an object of class "td_confusion_matrix_mle" which is a named list containing objects of class "tbl_teradata".
Named list members can be referenced directly with the "$" operator using following names:

  1. counttable

  2. stattable

  3. accuracytable

  4. output


    # Get the current context/connection
    con <- td_get_context()$connection
    # Load example data.
    loadExampleData("confusionmatrix_example", "iris_category_expect_predict")

    # Create object(s) of class "tbl_teradata".
    iris_category_expect_predict <- tbl(con, "iris_category_expect_predict")

    # Example 1 -
    confusion_matrix_out <- td_confusion_matrix_mle(data = iris_category_expect_predict,
                                  reference = "expected_value",
                                  prediction = "predicted_value"