Add features and records to a feature group
You can use the Amazon SageMaker Feature Store API or the console to update and describe your feature group as well as add features and records to your feature group. A feature group is an object that contains your data and a feature describes a column in the table. When you add a feature to the feature group you are effectively adding a column to the table. When you add a new record to the feature group you are filling in values for features associated with a specific record identifier. For more information on Feature Store concepts, see Feature Store concepts.
After you successfully add features to a feature group, you cannot remove those features. The features that you have added do not add any data to your records. You can add new records to the feature group or overwrite them using the PutRecord API. For examples on updating, describing, and putting records into a feature group, see Example code.
You can use the console to add features to a feature group. For more information on how to update your feature groups using the console, see Update a feature group from the console.
The following sections provide an overview of using Feature Store APIs to add features to a feature group followed by examples. With the API, you can also add or overwrite records after you've updated the feature group.
Topics
API
Use the UpdateFeatureGroup
operation to add features to a feature
group.
You can use the DescribeFeatureGroup
operation to see if you've added the
features successfully.
To add or overwrite records, use the PutRecord
operation.
To see the updates that you've made to a record, use the GetRecord
operation. To see the updates that you've made
to multiple records, use the BatchGetRecord
operation. It can take up to five minutes
for the updates that you've made to appear.
You can use the example code in the following section to walk through adding features and records using the AWS SDK for Python (Boto3).
Example code
The example code walks you through the following process:
-
Adding features to the feature group
-
Verifying that you've added them successfully
-
Adding a record to the feature group
-
Verifying that you've added it successfully
Step 1: Add features to a feature group
The following code uses the UpdateFeatureGroup
operation to add new features to
the feature group. It assumes that you've set up Feature Store and created a feature group.
For more information about getting started, see Introduction to Feature Store example
notebook.
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"} ] )
The following code uses the DescribeFeatureGroup
operation to check the status of
the update. If the LastUpdateStatus
field is Successful
,
you've added the features successfully.
sagemaker_client.describe_feature_group( FeatureGroupName=feature_group_name )
Step 2: Add a new record to the feature group
The following code uses the PutRecord
operation to add records to the feature
group that you've created.
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"
}, ] )
Use the GetRecord
operation to see which records in your
feature group don't have data for the features that you've added. You can use the
PutRecord
operation to overwrite the records that
don't have data for the features that you've added.