

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

# 特徴量グループへの特徴量とレコードの追加
<a name="feature-store-update-feature-group"></a>

Amazon SageMaker 特徴量ストア API または コンソールを使用して、特徴量グループを更新したり説明を追加したり、特徴量グループに特徴量やレコードを追加したりできます。特徴量グループはデータを含むオブジェクトで、特徴量はテーブルの列を説明します。特徴量グループに特徴量を追加すると、実質的にはテーブルに列が追加されます。特徴量グループに新しいレコードを追加すると、特定のレコード識別子に関連付けられた特徴量の値を入力することになります。特徴量ストアの概念の詳細については、「[Feature Store の概念](feature-store-concepts.md)」を参照してください。

特徴量グループに正常に特徴量を追加すると、それらの特徴量を削除することはできません。追加した特徴量によってレコードにデータが追加されることはありません。特徴量グループに新しいレコードを追加したり、[PutRecord](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_PutRecord.html) API を使用してそれらを上書きしたりできます。レコードを更新、説明、特徴量グループに追加する例については、「[コードの例](#feature-store-update-feature-group-example)」を参照してください。

コンソールを使用して、特徴量グループに特徴量を追加できます。コンソールを使用して特徴量グループを更新する方法の詳細は、「[コンソールから特徴量グループを更新する](feature-store-use-with-studio.md#feature-store-update-feature-group-studio)」を参照してください。

以下のセクションでは、Feature Store API を使用して特徴量グループに特徴量を追加する方法の概要を説明し、例を挙げて説明します。API を使用すると、特徴量グループを更新した後でレコードを追加または上書きすることもできます。

**Topics**
+ [API](#feature-store-update-feature-group-api)
+ [コードの例](#feature-store-update-feature-group-example)

## API
<a name="feature-store-update-feature-group-api"></a>

[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureGroup.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureGroup.html) 操作を使用して、特徴量グループに特徴量を追加します。

[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html) 操作を使用して、特徴量が正常に追加されたかどうかを確認できます。

レコードを追加または上書きするには、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_PutRecord.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_PutRecord.html) 操作を使用します。

レコードに加えた更新を確認するには、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_GetRecord.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_GetRecord.html) 操作を使用します。複数レコードに加えた更新を確認するには、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_BatchGetRecord.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_BatchGetRecord.html) 操作を使用します。更新内容が表示されるまでに最大 5 分かかることがあります。

次のセクションのサンプルコードを使うと、 AWS SDK for Python (Boto3)を使用して特徴量やレコードを追加する流れを追うことができます。

## コードの例
<a name="feature-store-update-feature-group-example"></a>

サンプルコードを使い、次のプロセスを順を追って説明します。

1. 特徴量グループへの特徴量の追加

1. 特徴量が正常に追加されたことの確認

1. 特徴量グループへのレコードの追加

1. レコードが正常に追加されたことの確認

### ステップ 1: 特徴量グループへの特徴量の追加
<a name="feature-store-update-feature-group-step-1"></a>

次のコードでは、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureGroup.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureGroup.html) 操作を使用して特徴量グループに新しい特徴量を追加します。Feature Store を設定して特徴量グループを作成済みであることを前提としています。使用開始の詳細については、「[Feature Store サンプルノートブックの概要](feature-store-introduction-notebook.md)」を参照してください。

```
import boto3

sagemaker_client = boto3.client("sagemaker")

sagemaker_client.update_feature_group(
    FeatureGroupName=feature_group_name,
    FeatureAdditions=[
        {"FeatureName": "new-feature-1", "FeatureType": "Integral"},
        {"FeatureName": "new-feature-2", "FeatureType": "Fractional"},
        {"FeatureName": "new-feature-3", "FeatureType": "String"}
    ]
)
```

次のコードでは、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html) 操作を使用して更新の状態を確認します。[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html#sagemaker-DescribeFeatureGroup-response-LastUpdateStatus](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html#sagemaker-DescribeFeatureGroup-response-LastUpdateStatus) フィールドが `Successful` の場合、特徴量は正常に追加されています。

```
sagemaker_client.describe_feature_group(
    FeatureGroupName=feature_group_name
)
```

### ステップ 2: 特徴量グループへの新しいレコードの追加
<a name="feature-store-update-feature-group-step-2"></a>

次のコードでは、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_PutRecord.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_PutRecord.html) 操作を使用して、作成した特徴量グループにレコードを追加します。

```
record_identifier_value = 'new_record'

sagemaker_featurestore_runtime_client = boto3.client("sagemaker-featurestore-runtime")

sagemaker_runtime_client.put_record(
    FeatureGroupName=feature_group_name,
    Record=[
        {
            'FeatureName': "record-identifier-feature-name",
            'ValueAsString': record_identifier_value
        },
        {
            'FeatureName': "event-time-feature",
            'ValueAsString': "timestamp-that-feature-store-returns"
        },
        {
            'FeatureName': "new-feature-1", 
            'ValueAsString': "value-as-string"
        },
        {
            'FeatureName': "new-feature-2", 
            'ValueAsString': "value-as-string"
        },
        {
            'FeatureName': "new-feature-3", 
            'ValueAsString': "value-as-string"
        },
    ]
)
```

[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_GetRecord.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_GetRecord.html) 操作を使用して、追加した特徴量のデータがない特徴量グループ内のレコードを調べます。[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_PutRecord.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_feature_store_PutRecord.html) 操作を使用すると、追加した特徴量のデータがないレコードを上書きできます。