3.10.6 ML_EXPLAIN_ROW

ML_EXPLAIN_ROW 例程为一行或多行未标记数据生成解释。 ML_EXPLAIN_ROW 使用SELECT 语句调用。

ML_EXPLAIN_ROW 将解释限制为 100 个最相关的特征。

需要加载模型才能运行 ML_EXPLAIN_ROW。请参阅第 3.9.3 节,“加载模型”

ML_EXPLAIN_ROW 语法

SELECT sys.ML_EXPLAIN_ROW(input_data, model_handle, options);

ML_EXPLAIN_ROW 参数:

  • input_data:指定要为其生成解释的数据。数据必须以 JSON键值格式指定,其中键是列名。列名称必须与用于训练模型的表中的特征列名称相匹配。单行数据可以指定如下:

    SELECT sys.ML_EXPLAIN_ROW(JSON_OBJECT("column_name", value, "column_name", value, ...)', 
      model_handle);

    您可以 通过以键值格式 ML_EXPLAIN_ROW 指定列并从输入表中选择来运行多行数据 :JSON

    SELECT sys.ML_EXPLAIN_ROW(JSON_OBJECT("output_col_name", schema.`input_col_name`, 
      output_col_name", schema.`input_col_name`, ...), model_handle) FROM input_table_name LIMIT N;
  • model_handle:指定模型句柄或包含模型句柄的会话变量。

  • optionsJSON_OBJECT(): 可选参数,格式为键值对 。如果未指定选项,则使用默认设置。可用的选项是:

    • prediction_explainer:您使用 为该模型训练的预测解释器的名称 ML_EXPLAIN。有效值为:

      • permutation_importance:默认预测解释器。

      • shap:SHAP 预测解释器,它根据 Shapley 值生成全局特征重要性值。

语法示例

  • ML_EXPLAIN_ROW 在单行数据上 运行 :

    SELECT sys.ML_EXPLAIN_ROW(JSON_OBJECT("sepal length", 7.3, "sepal width", 2.9, 
    "petal length", 6.3, "petal width", 1.8), @iris_model);
  • ML_EXPLAIN_ROW 在从输入表中选择的五行数据上 运行 :

    SELECT sys.ML_EXPLAIN_ROW(JSON_OBJECT("sepal length", iris_test.`sepal length`, 
    "sepal width", iris_test.`sepal width`, "petal length", iris_test.`petal length`, 
    "petal width", iris_test.`petal width`), @iris_model) 
    FROM ml_data.iris_test LIMIT 5;
  • ML_EXPLAIN_ROW 使用 SHAP 预测解释器 运行 :

    SELECT sys.ML_EXPLAIN_ROW(JSON_OBJECT('sepal length',`iris_test`.`sepal length`,
    'sepal width',`iris_test`.`sepal width`,'petal length',`iris_test`.`petal length`,
    'petal width',`iris_test`.`petal width` ), @iris_model, JSON_OBJECT(
    'prediction_explainer', 'shap')) FROM `iris_test` LIMIT 4;