Amazon Redshift ML 概率指标 - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

Amazon Redshift ML 概率指标

在有监督学习问题中,分类标签是使用输入数据进行预测的结果。例如,如果您使用模型来预测客户是否会重新订阅串流服务,那么可能的标签是“可能”和“不太可能”。Redshift ML 提供了概率指标的功能,该功能为每个标签分配一个概率以指明其可能性。这可以帮助您根据预测结果作出更明智的决策。在 Amazon Redshift ML 中,使用二进制分类或多分类器问题类型创建 AUTO ON 模型时提供了概率指标。如果您省略 AUTO ON 参数,Redshift ML 会假定模型应具有 AUTO ON。

创建模型

创建模型时,Amazon Redshift 会自动检测模型类型和问题类型。如果是分类问题,Redshift 会自动创建第二个推理函数,您可以使用该函数输出与每个标签相关的概率。第二个推理函数的名称是您指定的推理函数名称,后面再加上字符串 _probabilities。例如,如果您将推理函数命名为 customer_churn_predict,则第二个推理函数的名称为 customer_churn_predict_probabilities。然后,您可以查询此函数以获取每个标签的概率。

CREATE MODEL customer_churn_model FROM customer_activity PROBLEM_TYPE BINARY_CLASSIFICATION TARGET churn FUNCTION customer_churn_predict IAM_ROLE {default} AUTO ON SETTINGS ( S3_BUCKET '<DOC-EXAMPLE-BUCKET>'

获取概率

概率函数准备就绪后,运行该命令会返回一个 SUPER 类型,其中包含返回概率的数组及其关联标签。例如,结果 "probabilities" : [0.7, 0.3], "labels" : ["False.", "True."] 意味着 False 标签的概率为 0.7,True 标签的概率为 0.3。

SELECT customer_churn_predict_probabilities(Account_length, Area_code, VMail_message, Day_mins, Day_calls, Day_charge,Eve_mins, Eve_calls, Eve_charge, Night_mins, Night_calls, Night_charge,Intl_mins, Intl_calls, Intl_charge, Cust_serv_calls) FROM customer_activity; customer_churn_predict_probabilities -------------------- {"probabilities" : [0.7, 0.3], "labels" : ["False.", "True."]} {"probabilities" : [0.8, 0.2], "labels" : ["False.", "True."]} {"probabilities" : [0.75, 0.25], "labels" : ["True.", "False"]}

概率和标签数组总是按其概率降序排序。您可以编写查询,通过取消嵌套概率函数的 SUPER 返回结果,仅返回概率最高的预测标签。

SELECT prediction.labels[0], prediction.probabilities[0] FROM (SELECT customer_churn_predict_probabilities(Account_length, Area_code, VMail_message, Day_mins, Day_calls, Day_charge,Eve_mins, Eve_calls, Eve_charge, Night_mins, Night_calls, Night_charge,Intl_mins, Intl_calls, Intl_charge, Cust_serv_calls) AS prediction FROM customer_activity); labels | probabilities -----------+-------------- "False." | 0.7 "False." | 0.8 "True." | 0.75

为了简化查询,可以将预测函数的结果存储在表中。

CREATE TABLE churn_auto_predict_probabilities AS (SELECT customer_churn_predict_probabilities(Account_length, Area_code, VMail_message, Day_mins, Day_calls, Day_charge,Eve_mins, Eve_calls, Eve_charge, Night_mins, Night_calls, Night_charge,Intl_mins, Intl_calls, Intl_charge, Cust_serv_calls) AS prediction FROM customer_activity);

您可以查询带有结果的表,以便仅返回概率高于 0.7 的预测。

SELECT prediction.labels[0], prediction.probabilities[0] FROM churn_auto_predict_probabilities WHERE prediction.probabilities[0] > 0.7; labels | probabilities -----------+-------------- "False." | 0.8 "True." | 0.75

使用索引表示法,可以获得特定标签的概率。以下示例返回所有 True. 标签的概率。

SELECT label, index, p.prediction.probabilities[index] FROM churn_auto_predict_probabilities p, p.prediction.labels AS label AT index WHERE label='True.'; label | index | probabilities ---------+-------+--------------- "True." | 0 | 0.3 "True." | 0 | 0.2 "True." | 0 | 0.75

以下示例返回具有 True. 标签且概率大于 0.7 的所有行,这表明客户很可能会流失。

SELECT prediction.labels[0], prediction.probabilities[0] FROM churn_auto_predict_probabilities WHERE prediction.probabilities[0] > 0.7 AND prediction.labels[0] = "True."; labels | probabilities -----------+-------------- "True." | 0.75