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_AUC takes the following arguments:

  • project_id: Your project ID.
  • dataset: The BigQuery dataset that contains the model.
  • model: The name of the model.
  • table: The name of the input table that contains the evaluation data.

    If table is specified, the input column names in the table must match the column names in the model, and their types should be compatible according to BigQuery implicit coercion rules. The input must have a column that matches the label column name that's provided during training. This value is provided using the input_label_cols option. If input_label_cols is unspecified, the column that's named label in the training data is used.

    If you don't specify either table or query_statement, ML.ROC_CURVE computes the curve results as follows:

    • If the data is split during training, the split evaluation data is used to compute the curve results.
    • If the data is not split during training, the entire training input is used to compute the curve results.
  • query_statement: a GoogleSQL query that is used to generate the evaluation data. For the supported SQL syntax of the query_statement clause in GoogleSQL, see Query syntax.

    If query_statement is specified, the input column names from the query must match the column names in the model, and their types should be compatible according to BigQuery implicit coercion rules. The input must have a column that matches the label column name provided during training. This value is provided using the input_label_cols option. If input_label_cols is unspecified, the column named label in the training data is used. The extra columns are ignored.

    If you used the TRANSFORM clause in the CREATE MODEL statement that created the model, then only the input columns present in the TRANSFORM clause must appear in query_statement.

    If you don't specify either table or query_statement, ML.ROC_CURVE computes the curve results as follows:

    • If the data is split during training, the split evaluation data is used to compute the curve results.
    • If the data is not split during training, the entire training input is used to compute the curve results.
  • thresholds: an ARRAY<FLOAT64> value that specifies the percentile values of the prediction output supplied by the GENERATE_ARRAY function.

  • trial_id: an INT64 value that identifies the hyperparameter tuning trial that you want the function to evaluate. The function uses the optimal trial by default. Only specify this argument if you ran hyperparameter tuning when creating the model.

Output

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

  • threshold: a FLOAT64 value that contains the custom threshold for the binary class classification model.
  • recall: a FLOAT64 value that indicates the proportion of actual positive cases that were correctly predicted by the model.
  • true_positives: an INT64 value that contains the number of cases correctly predicted as positive by the model.
  • false_positives: an INT64 value that contains the number of cases incorrectly predicted as positive by the model.
  • true_negatives: an INT64 value that contains the number of cases correctly predicted as negative by the model.
  • false_negatives: an INT64 value that contains the number of cases incorrectly predicted as negative by the model.

Examples

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