The ML.GLOBAL_EXPLAIN function

ML.GLOBAL_EXPLAIN provides explanations for the entire model by aggregating the local explanations of the evaluation data. ML.GLOBAL_EXPLAIN can only be used with models that are trained with the option enable_global_explain set to TRUE.

For information about Explainable AI, see Explainable AI Overview.

For information about the supported model types of each SQL statement and function, and all of the supported SQL statements and functions for each model type, read the End-to-end user journey for each model.

ML.GLOBAL_EXPLAIN syntax

ML.GLOBAL_EXPLAIN(MODEL model_name
                 [, STRUCT<class_level_explain BOOL> settings])

class_level_explain

(Optional) For classification models, if class_level_explain is set to TRUE then global feature importances are returned for each class. Otherwise, the global feature importance of the entire model is returned rather than that of each class. By default, class_level_explain is set to FALSE.

This option only applies to classification models. Regression models only have model-level global feature importance.

ML.GLOBAL_EXPLAIN output

The output of ML.GLOBAL_EXPLAIN has two formats:

  • For regression and classification models with class_level_explain set to FALSE, the following two columns are returned:

    • feature: Feature name.
    • attribution: Feature importance to the model overall.
  • For classification models with class_level_explain set to TRUE, the following two columns are returned:

    • <class_name>: Name of the class in the label column.
    • top_feature_attributions: An ARRAY of STRUCTs containing the attribution of the top 10 features to this class.
      • top_feature_attributions.feature: Feature name.
      • top_feature_attributions.attribution: Feature importance of this class.

ML.GLOBAL_EXPLAIN examples

The following examples assume your model is in your default project.

Get global feature importance of a Boosted Tree regression model

SELECT
  *
FROM
  ML.GLOBAL_EXPLAIN(MODEL `mydataset.mymodel`)

Get global feature importance for each class of a Boosted Tree classifier model

SELECT
  *
FROM
  ML.GLOBAL_EXPLAIN(MODEL `mydataset.mymodel`, STRUCT(TRUE AS class_level_explain))