本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
更新 Amazon Personalize 指標屬性
當您更新指標屬性時,您可以新增和移除指標,並修改其輸出組態。您可以使用 Amazon Personalize 主控台 AWS Command Line Interface或 AWS SDKS 更新指標屬性。
更新指標屬性 (主控台)
若要使用 Amazon Personalize 主控台更新指標屬性,請在指標屬性頁面上進行變更。
更新指標屬性 (AWS CLI)
建立指標屬性之後,您可以使用 AWS Command Line Interface (AWS 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。
更新指標屬性 (AWS 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
import {UpdateMetricAttributionCommand, PersonalizeClient } from
"@aws-sdk/client-personalize";
const personalizeClient = new PersonalizeClient({
region: "REGION"
});
export const updateMetricAttributionParam = {
metricAttributionArn: "METRIC_ATTRIBUTION_ARN",
removeMetrics: ["METRIC_NAME_1", "METRIC_NAME_2"]
};
export const run = async () => {
try {
const response = await personalizeClient.send(
new UpdateMetricAttributionCommand(updateMetricAttributionParam)
);
console.log("Success", response);
return response;
} 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
import {UpdateMetricAttributionCommand, PersonalizeClient } from
"@aws-sdk/client-personalize";
const personalizeClient = new PersonalizeClient({
region: "REGION"
});
export const updateMetricAttributionParam = {
metricAttributionArn: "METRIC_ATTRIBUTION_ARN",
addMetrics: [
{
eventType: "EVENT_TYPE",
expression: "SUM(DatasetType.COLUMN_NAME)",
metricName: "METRIC_NAME",
}
],
metricsOutputConfig: {
roleArn: "ROLE_ARN",
s3DataDestination: {
kmsKeyArn: "KEY_ARN",
path: "s3://amzn-s3-demo-bucket/<folderName>/",
},
}
};
export const run = async () => {
try {
const response = await personalizeClient.send(
new UpdateMetricAttributionCommand(updateMetricAttributionParam)
);
console.log("Success", response);
return response;
} catch (err) {
console.log("Error", err);
}
};
run();
如果成功,Amazon Personalize 會傳回您更新之指標屬性的 ARN。如需所有參數的完整清單,請參閱UpdateMetricAttribution。