AWS – SageMaker Feature Store


SageMaker Feature Store

Table Of Contents:

  1. What is Amazon SageMaker Feature Store?
  2. Key Capabilities of SageMaker Feature Store.
  3. Why Use SageMaker Feature Store?
  4. How To Use Sagemaker Feature Store ?
  5. Store Values To A Feature Store.
  6. Retrieve Values From Feature Store.

(1) What Is Amazon Sagemaker Feature Store?

  • Amazon SageMaker Feature Studio is a feature engineering and management tool within Amazon SageMaker that allows data scientists and ML engineers to create, store, and reuse machine learning features efficiently.

(2) Key Capabilities of SageMaker Feature Store.

(3) Why Use SageMaker Feature Store?

(4) How To Use Sagemaker Feature Store ?

Step – 1: Create A Feature Group
Step – 2: Give The Feature Group Details
Step – 3: Specify Feature Definations
Step – 4: Select Required Features
Step – 4: Review Feature Group
Step – 5: Feature Group Created Successfully
Step – 6: Check The Newley Created Feature Group
  • We cant directly see the data in the Feature Group UI window.
  • We have to use Python boto3 to add and retrieve the data from the Feature Group.

(5) Store Values To A Feature Store

import boto3
import time

# Initialize SageMaker Feature Store client
featurestore_runtime = boto3.client("sagemaker-featurestore-runtime")

# Feature group name
feature_group_name = "customer_transaction_features"  # Replace with your actual Feature Group name

# Record to store in Feature Group
record = [
    {"FeatureName": "customer_id", "ValueAsString": "12345"},  # String type
    {"FeatureName": "total_spent_last_7_days", "ValueAsString": "1000"},  # Integral type
    {"FeatureName": "average_transaction_value", "ValueAsString": "200"},  # Integral type
    {"FeatureName": "timestamp", "ValueAsString": time.strftime("%Y-%m-%dT%H:%M:%SZ")}  # String type (ISO 8601 format)
]

# Store the feature values
featurestore_runtime.put_record(FeatureGroupName=feature_group_name, Record=record)

print("Feature values stored successfully!")

(6) Retrieve Values From Feature Store

import boto3

# Initialize SageMaker Feature Store client
featurestore_runtime = boto3.client("sagemaker-featurestore-runtime")

# Feature Group name
feature_group_name = "customer_transaction_features"  # Replace with your actual Feature Group name

# Customer ID for which we want to retrieve features
customer_id = "12345"

# Fetch the record from the Online Store
response = featurestore_runtime.get_record(
    FeatureGroupName=feature_group_name,
    RecordIdentifierValueAsString=customer_id
)

# Print the retrieved feature values
print("Retrieved Feature Values:")
for feature in response.get("Record", []):
    print(f"{feature['FeatureName']}: {feature['ValueAsString']}")

Leave a Reply

Your email address will not be published. Required fields are marked *