

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

# 検索可能なメタデータを特徴量に追加する
<a name="feature-store-add-metadata"></a>

Amazon SageMaker Feature Store では、すべての特徴量を検索できます。特徴量を見つけやすくするために、特徴量にメタデータを追加できます。次のタイプのメタデータを追加できます。
+ 説明 — 検索可能な特徴量の説明。
+ パラメータ — 検索可能なキーと値のペア

説明には最大 255 文字を入力できます。パラメータについては、検索でキーと値のペアを指定する必要があります。最大 25 個のパラメータを追加できます。

特徴量のメタデータを更新するには、コンソールまたは [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureMetadata.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureMetadata.html) オペレーションのいずれかを使用できます。

## 検索可能なメタデータを特徴量に追加する方法
<a name="feature-store-add-metadata-how-to"></a>

コンソールまたは Amazon SageMaker 特徴量ストア API を使用して、特徴量に検索可能なメタデータを追加できます。コンソールを介して特徴量ストアを使用する手順は、デフォルトのエクスペリエンスとして有効にしたのが、[Amazon SageMaker Studio](studio-updated.md) か [Amazon SageMaker Studio Classic](studio.md) かによって異なります。

### Studio がデフォルトのエクスペリエンスである場合に、特徴量に検索可能なメタデータを追加するには (コンソール)
<a name="feature-store-add-metadata-how-to-with-studio-updated"></a>

1. 「[Amazon SageMaker Studio を起動する](studio-updated-launch.md)」の手順に従って、Studio コンソールを開きます。

1. 左側のナビゲーションペインで **[データ]** を選択して、ドロップダウンリストを展開します。

1. ドロップダウンリストから **[Feature Store]**を選択します。

1. (オプション) 特徴量を表示するには、**[アカウント]** をクリックします。共有特徴量を表示するには、**[クロスアカウント]** をクリックします。

1. 特徴量グループを表示するには、**[特徴量カタログ]** タブで **[アカウント]** をクリックします。

1. **[特徴量カタログ]** タブで **[クロスアカウント]** を選択すると、他のユーザーにより検索可能になった特徴量グループが表示されます。**[作成者]** では、特徴量グループのリソース所有者のアカウント ID を確認できます。

1. **[検索]** ドロップダウンリストで特徴量を検索できます。
   + (オプション) 検索を絞り込むには、**[検索]** ドロップダウンリストの横にあるフィルターアイコンをクリックします。フィルターを使用して、検索結果のパラメータまたは日付範囲を指定できます。パラメータを検索する場合は、パラメータのキーと値の両方を指定します。特徴量の検出可能性を向上するには、時間範囲を指定したり、検索対象外の列を選択解除したりできます。
   + 共有リソースについては、リソース所有者アカウントが適切なアクセス許可を付与した場合にのみ、特徴量グループのメタデータまたは特徴量定義を編集できます。検出可能性アクセス許可のみの場合は、メタデータや特徴量定義を編集できません。アクセス許可の付与の詳細については、「[クロスアカウントアクセスを有効にする](feature-store-cross-account-access.md)」を参照してください。

1. 特徴量を選択します。

1. [**Edit metadata (メタデータの編集)**] を選択します。

1. **[説明]** フィールドで、説明を更新します。

1. **[パラメータ]** の **[パラメータ]**フィールドで、パラメータのキーと値のペアを指定します。

1. (オプション) **[新しいパラメータを追加]** を選択して別のパラメータを追加します。

1. **[Save changes]** (変更の保存) をクリックします。

1. **[確認]** を選択します。

### SDK for Python (Boto3) を使用して特徴量に検索可能なメタデータを追加するには
<a name="feature-store-add-metadata-how-to-with-sdk"></a>

このセクションのコードでは、 AWS SDK for Python (Boto3) の [https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureMetadata.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureMetadata.html) オペレーションを使用して、さまざまなシナリオでの特徴量に検索可能なメタデータを追加します。クエリを送信する他の言語については、Amazon SageMaker API リファレンスの 「[See Also](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_UpdateFeatureMetadata.html#API_Search_SeeAlso)」を参照してください。**

追加の特徴量ストアの例とリソースについては、「[Amazon SageMaker Feature Store リソース](feature-store-resources.md)」を参照してください。

------
#### [ Add a list of parameters to a feature ]

特徴量にパラメータのリストを追加するには、次のフィールドの値を指定します。
+ `FeatureGroupName`
+ `Feature`
+ `Parameters`

次のコード例では、 を使用して AWS SDK for Python (Boto3) 2 つのパラメータを追加します。

```
sagemaker_client.update_feature_metadata(
    FeatureGroupName={{"feature_group_name"}},
    FeatureName={{"feature-name"}},
    ParameterAdditions=[
        {"Key": {{"example-key-0"}}, "Value": {{"example-value-0"}}},
        {"Key": {{"example-key-1"}}, "Value": {{"example-value-1"}}},
    ]
)
```

------
#### [ Add a description to a feature ]

特徴量に説明を追加するには、次のフィールドの値を指定します。
+ `FeatureGroupName`
+ `Feature`
+ `Description`

```
sagemaker_client.update_feature_metadata(
    FeatureGroupName={{"feature-group-name"}},
    FeatureName={{"feature-name"}},
    Description={{"description"}}
)
```

------
#### [ Remove parameters for a feature ]

特徴量のパラメータをすべて削除するには、次の操作を行います。

以下のフィールドに値を入力します。
+ `FeatureGroupName`
+ `Feature`

`ParameterRemovals` で削除するパラメータのキーを指定します。

```
sagemaker_client.update_feature_metadata(
    FeatureGroupName={{"feature_group_name"}},
    FeatureName={{"feature-name"}},
        ParameterRemovals=[
        {"Key": {{"example-key-0"}}},
        {"Key": {{"example-key-1"}}},
    ]
)
```

------
#### [ Remove the description for a feature ]

特徴量の説明を削除するには、次の操作を行います。

以下のフィールドに値を入力します。
+ `FeatureGroupName`
+ `Feature`

`Description` には空の文字列を指定します。

```
sagemaker_client.update_feature_metadata(
    FeatureGroupName={{"feature-group-name"}},
    FeatureName={{"feature-name"}},
    Description=""
)
```

------

#### コードの例
<a name="feature-store-add-metadata-python-sdk-example"></a>

特徴量のメタデータを更新したら、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureMetadata.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureMetadata.html) 操作を使用して、実行した更新を確認できます。

次のコードは、 AWS SDK for Python (Boto3)を使用したワークフローの例を示しています。このコード例では、以下を行います。

1. SageMaker AI 環境を設定します。

1. 特徴量グループを作成します。

1. グループに特徴量を追加します。

1. 特徴量にメタデータを追加します。

追加の特徴量ストアの例とリソースについては、「[Amazon SageMaker Feature Store リソース](feature-store-resources.md)」を参照してください。

##### ステップ 1: セットアップ
<a name="feature-store-add-metadata-step-1"></a>

Feature Store の使用を開始するには、SageMaker AI セッション、boto3 セッション、Feature Store セッションを作成します。次に、特徴用の S3 バケットをセットアップします。これがオフラインストアとなります。次のコードでは SageMaker AI のデフォルトバケットを使い、カスタムプレフィックスを追加します。

**注記**  
使うロールには、マネージドポリシーの `AmazonS3FullAccess` と `AmazonSageMakerFeatureStoreAccess` がアタッチされている必要があります。

```
# SageMaker Python SDK version 2.x is required
%pip install 'sagemaker>=2.0.0'
import sagemaker
import sys
```

```
import boto3
import pandas as pd
import numpy as np
import io
from sagemaker.session import Session
from sagemaker import get_execution_role
from botocore.exceptions import ClientError


prefix = 'sagemaker-featurestore-introduction'
role = get_execution_role()

sagemaker_session = sagemaker.Session()
region = sagemaker_session.boto_region_name
s3_bucket_name = sagemaker_session.default_bucket()
sagemaker_client = boto_session.client(service_name='sagemaker', region_name=region)
```

##### ステップ 2: 特徴量グループを作成して特徴量を追加する
<a name="feature-store-add-metadata-step-2"></a>

次のコードは、特徴量定義を含む特徴量グループを作成する例です。

```
feature_group_name = "test-for-feature-metadata"
feature_definitions = [
    {"FeatureName": "feature-1", "FeatureType": "String"},
    {"FeatureName": "feature-2", "FeatureType": "String"},
    {"FeatureName": "feature-3", "FeatureType": "String"},
    {"FeatureName": "feature-4", "FeatureType": "String"},
    {"FeatureName": "feature-5", "FeatureType": "String"}
]
try:
    sagemaker_client.create_feature_group(
        FeatureGroupName=feature_group_name,
        RecordIdentifierFeatureName="feature-1",
        EventTimeFeatureName="feature-2",
        FeatureDefinitions=feature_definitions,
        OnlineStoreConfig={"EnableOnlineStore": True}
    )
except ClientError as e:
    if e.response["Error"]["Code"] == "ResourceInUse":
        pass
    else:
        raise e
```

##### ステップ 3: メタデータを追加する
<a name="feature-store-add-metadata-step-3"></a>

メタデータを追加する前に、[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureGroup.html) 操作を使用して、特徴量グループのステータスが `Created` であることを確認します。

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

特徴量に説明を追加します。

```
sagemaker_client.update_feature_metadata(
    FeatureGroupName=feature_group_name,
    FeatureName="feature-1",
    Description="new description"
)
```

[https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureMetadata.html](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_DescribeFeatureMetadata.html) オペレーションを使用すると、特徴量グループの説明の更新が正常に完了したかを確認できます。

```
    sagemaker_client.describe_feature_metadata(
    FeatureGroupName=feature_group_name,
    FeatureName="feature-1"
)
```

また、これを使用して特徴量グループにパラメータを追加することもできます。

```
sagemaker_client.update_feature_metadata(
    FeatureGroupName=feature_group_name,
    FeatureName="feature-1",
    ParameterAdditions=[
        {"Key": "team", "Value": "featurestore"},
        {"Key": "org", "Value": "sagemaker"},
    ]
)
```

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

```
    sagemaker_client.describe_feature_metadata(
    FeatureGroupName=feature_group_name,
    FeatureName="feature-1"
)
```