The ML.ROC_CURVE function

This document describes the ML.ROC_CURVE function, which you can use to evaluate binary class classification specific metrics.

Syntax

ML.ROC_CURVE(
  MODEL `project_id.dataset.model`
  [, { TABLE `project_id.dataset.table` | (query_statement) }]
  [, GENERATE_ARRAY(thresholds)]
  [, STRUCT(trial_id AS trial_id)])

Arguments

ML.ROC_CURVE takes the following arguments:

Output

ML.ROC_CURVE returns multiple rows with metrics for different threshold values for the model. The metrics include the following:

Examples

The following examples assume your model and input table are in your default project.

Evaluate the ROC curve of a binary class logistic regression model

The following query returns all of the output columns for ML.ROC_CURVE. You can graph the recall and false_positive_rate values for an ROC curve. The threshold values returned are chosen based on the percentile values of the prediction output.

SELECT
  *
FROM
  ML.ROC_CURVE(MODEL `mydataset.mymodel`,
    TABLE `mydataset.mytable`)

Evaluate an ROC curve with custom thresholds

The following query returns all of the output columns for ML.ROC_CURVE. The threshold values returned are chosen based on the output of the GENERATE_ARRAY function.

SELECT
  *
FROM
  ML.ROC_CURVE(MODEL `mydataset.mymodel`,
    TABLE `mydataset.mytable`,
    GENERATE_ARRAY(0.4,0.6,0.01))

Evaluate the precision-recall curve

Instead of getting an ROC curve (the recall versus false positive rate), the following query calculates a precision-recall curve by using the precision from the true and false positive counts:

SELECT
  recall,
  true_positives / (true_positives + false_positives) AS precision
FROM
  ML.ROC_CURVE(MODEL `mydataset.mymodel`,
    TABLE `mydataset.mytable`)

What's next