

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Amazon Personalize メトリクス属性の更新
<a name="updating-metric-attribution"></a>

 メトリクス属性を更新すると、メトリクスを追加および削除したり、出力設定を変更したりできます。Amazon Personalize コンソール AWS Command Line Interface、または AWS SDKS を使用してメトリクス属性を更新できます。

**Topics**
+ [メトリクス属性の更新 (コンソール)](#updating-metric-attribution-console)
+ [メトリクス属性の更新 (AWS CLI)](#updating-metric-attribution-cli)
+ [メトリクス属性の更新 (AWS SDK)](#updating-metric-attribution-sdk)

## メトリクス属性の更新 (コンソール)
<a name="updating-metric-attribution-console"></a>

Amazon Personalize コンソールでメトリクス属性を更新するには、**[メトリクス属性]**ページで変更を行います。

**メトリクス属性を更新するには**

1. [https://console.aws.amazon.com/personalize/home](https://console.aws.amazon.com/personalize/home) で Amazon Personalize コンソールを開き、アカウントにサインインします。

1. データセットグループを選択します。

1. ナビゲーションペインで **[メトリクス]** を選択します。

1. 一番下のセクションで、**[メトリクス属性]** タブまたは **[メトリクス属性設定]** タブを選択し、変更を開始します。
   + メトリクスを追加または削除するには、**[メトリクス属性]** タブを選択し、**[属性の編集]** を選択します。**[メトリクス属性の編集]** ページで変更を加え、**[更新]** を選択して変更を保存します。
   + Amazon S3 出力バケットまたは IAM サービスロールを変更するには、**[メトリクス属性設定の編集**] タブを選択し、**[属性設定の編集]** ページで変更を行います。**[更新]** を選択して変更を保存します。

## メトリクス属性の更新 (AWS CLI)
<a name="updating-metric-attribution-cli"></a>

メトリクス属性を作成したら、 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](API_UpdateMetricAttribution.md)」を参照してください。

## メトリクス属性の更新 (AWS SDK)
<a name="updating-metric-attribution-sdk"></a>

メトリクス属性を作成した後、メトリクスを追加または削除したり、出力の設定を変更したりできます。次のコードは、メトリクス属性からメトリクスを削除する方法を示しています。

------
#### [ 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](API_UpdateMetricAttribution.md)」を参照してください。