Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
更新 Amazon Personalize 指标归因
更新指标归因时,您可以添加和移除指标以及修改其输出配置。您可以使用 Amazon Personalize 控制台、Amazon Command Line Interface 或 Amazon SDK 更新指标归因。
更新指标归因(控制台)
要使用 Amazon Personalize 控制台更新指标归因,您可以在指标归因页面上进行更改。
更新指标归因 (Amazon CLI)
创建指标归因后,您可以使用 Amazon Command Line Interface (Amazon CLI) 添加和移除指标以及修改其输出配置。以下代码显示了如何使用 update-metric-attribution
命令删除指标:
aws personalize update-metric-attribution \
--metric-attribution-arn metric attribution arn
\
--remove-metrics metricName1
metricName2
以下代码显示了如何添加其他指标和指定新的输出配置:
aws personalize update-metric-attribution \
--metric-attribution-arn metric attribution arn
\
--metrics-output-config "{\"roleArn\": \"new role ARN
\", \"s3DataDestination\":{\"kmsKeyArn\":\"kms key ARN
\",\"path\":\"s3://amzn-s3-demo-bucket2
/new-folder-name
/\"}}" \
--add-metrics "[{
\"eventType\": \"event type
\",
\"expression\": \"SUM(DatasetType.COLUMN_NAME)
\",
\"metricName\": \"metric name
\"
}]"
如果成功,则 Amazon Personalize 会返回您更新的指标归因的 ARN。要获得所有参数的完整列表,请参阅 UpdateMetricAttribution。
更新指标归因 (Amazon SDK)
创建指标归因后,您可以添加或移除指标以及修改其输出配置。以下代码显示了如何从指标归因中移除指标。
- SDK for Python (Boto3)
-
import boto3
personalize = boto3.client('personalize')
metricsToRemove = ["metricName1
", "metricName2
"]
response = personalize.update_metric_attribution(
metricAttributionArn = "metric attribution ARN
",
removeMetrics = metricsToRemove
)
- SDK for Java 2.x
-
public static void removeMetrics(PersonalizeClient client,
String metricAttributionArn,
String metric1Name,
String metric2Name) {
ArrayList<String> metricsToRemove = new ArrayList<>(Arrays.asList(metric1Name, metric2Name));
try {
UpdateMetricAttributionRequest request = UpdateMetricAttributionRequest.builder()
.metricAttributionArn(metricAttributionArn)
.removeMetrics(metricsToRemove)
.build();
UpdateMetricAttributionResponse response = client.updateMetricAttribution(request);
System.out.println(response);
} catch (PersonalizeException e) {
System.out.println(e.awsErrorDetails().errorMessage());
}
}
- SDK for JavaScript v3
// Get service clients and commands using ES6 syntax.
import {UpdateMetricAttributionCommand, PersonalizeClient } from
"@aws-sdk/client-personalize";
// create personalizeClient
const personalizeClient = new PersonalizeClient({
region: "REGION"
});
// set the update request param
export const updateMetricAttributionParam = {
metricAttributionArn: "METRIC_ATTRIBUTION_ARN", /* required */
removeMetrics: ["METRIC_NAME_1", "METRIC_NAME_2"] /* specify list of names of metrics to delete */
};
export const run = async () => {
try {
const response = await personalizeClient.send(
new UpdateMetricAttributionCommand(updateMetricAttributionParam)
);
console.log("Success", response);
return response; // For unit tests.
} catch (err) {
console.log("Error", err);
}
};
run();
以下代码显示了如何添加其他指标和指定新的输出配置:
- SDK for Python (Boto3)
-
import boto3
personalize = boto3.client('personalize')
newMetrics = [{
"eventType": "event type
",
"expression": "SUM(DatasetType.COLUMN_NAME)
",
"metricName": "metric name
"
}]
newOutputConfig = {
"roleArn": "Amazon Personalize service role ARN
",
"s3DataDestination": {
"kmsKeyArn": "key ARN
",
"path": "s3://amzn-s3-demo-bucket/<folder>
"
}
}
response = personalize.update_metric_attribution(
metricAttributionArn = "metric attribution arn
",
metricsOutputConfig = newOutputConfig,
addMetrics = newMetrics
)
- SDK for Java 2.x
-
public static void addMetricsAndUpdateOutputConfig(PersonalizeClient personalizeClient,
String metricAttributionArn,
String newMetric1EventType,
String newMetric1Expression,
String newMetric1Name,
String newMetric2EventType,
String newMetric2Expression,
String newMetric2Name,
String roleArn,
String s3Path,
String kmsKeyArn) {
try {
MetricAttribute newAttribute = MetricAttribute.builder()
.eventType(newMetric1EventType)
.expression(newMetric1Expression)
.metricName(newMetric1Name)
.build();
MetricAttribute newAttribute2 = MetricAttribute.builder()
.eventType(newMetric2EventType)
.expression(newMetric2Expression)
.metricName(newMetric2Name)
.build();
ArrayList<MetricAttribute> newAttributes = new ArrayList<>(Arrays.asList(newAttribute, newAttribute2));
S3DataConfig newDataDestination = S3DataConfig.builder()
.kmsKeyArn(kmsKeyArn)
.path(s3Path)
.build();
MetricAttributionOutput newOutputConfig = MetricAttributionOutput.builder()
.roleArn(roleArn)
.s3DataDestination(newDataDestination)
.build();
UpdateMetricAttributionRequest request = UpdateMetricAttributionRequest.builder()
.metricAttributionArn(metricAttributionArn)
.metricsOutputConfig(newOutputConfig)
.addMetrics(newAttributes)
.build();
UpdateMetricAttributionResponse response = personalizeClient.updateMetricAttribution(request);
System.out.println("New metrics added!");
System.out.println(response);
} catch (PersonalizeException e) {
System.out.println(e.awsErrorDetails().errorMessage());
}
}
- SDK for JavaScript v3
// Get service clients and commands using ES6 syntax.
import {UpdateMetricAttributionCommand, PersonalizeClient } from
"@aws-sdk/client-personalize";
// create personalizeClient
const personalizeClient = new PersonalizeClient({
region: "REGION"
});
export const updateMetricAttributionParam = {
metricAttributionArn: "METRIC_ATTRIBUTION_ARN",
addMetrics: [
{
eventType: "EVENT_TYPE", /* required for each metric */
expression: "SUM(DatasetType.COLUMN_NAME)", /* required for each metric */
metricName: "METRIC_NAME", /* required for each metric */
}
],
metricsOutputConfig: {
roleArn: "ROLE_ARN", /* required */
s3DataDestination: {
kmsKeyArn: "KEY_ARN", /* optional */
path: "s3://amzn-s3-demo-bucket/<folderName>/", /* optional */
},
}
};
export const run = async () => {
try {
const response = await personalizeClient.send(
new UpdateMetricAttributionCommand(updateMetricAttributionParam)
);
console.log("Success", response);
return response; // For unit tests.
} catch (err) {
console.log("Error", err);
}
};
run();
如果成功,则 Amazon Personalize 会返回您更新的指标归因的 ARN。要获得所有参数的完整列表,请参阅 UpdateMetricAttribution。