如何按名称删除SageMaker Feature Store中的Feature Group
删除非当前会话创建的SageMaker Feature Group方法
仅删除S3存储桶内的对应数据无法清除Feature Store UI中的记录,因为Feature Group的元数据存储在SageMaker服务端,需要通过服务端接口执行删除操作,具体方案如下:
1. 已知Feature Group完整名称的删除操作
你可以直接通过完整名称实例化Feature Group对象,不需要依赖创建时的会话对象即可调用删除方法,示例代码如下:
import sagemaker from sagemaker.feature_store.feature_group import FeatureGroup # 初始化SageMaker会话,需保证和目标Feature Group所在区域一致 sagemaker_session = sagemaker.Session() # 替换为你要删除的Feature Group的完整名称 target_fg_name = "my-feature-group-02-13-45-22" feature_group = FeatureGroup(name=target_fg_name, sagemaker_session=sagemaker_session) # 执行删除,默认会同步删除线下存储对应的S3数据 feature_group.delete() # 若需要保留S3内的特征数据,可使用以下参数 # feature_group.delete(delete_offline_store=False)
2. 忘记Feature Group完整名称的查询方法
可以通过boto3接口列出当前区域下所有的Feature Group,查询到目标名称后再执行删除:
import boto3 # 替换为目标Feature Group所在的区域 region = "cn-northwest-1" client = boto3.client('sagemaker', region_name=region) # 查询所有Feature Group列表 fg_list = client.list_feature_groups()["FeatureGroupSummaries"] for fg in fg_list: print(fg["FeatureGroupName"])
补充说明
目前SageMaker Feature Store控制台暂不支持直接在UI中删除Feature Group,仅能通过SDK、CLI或者调用OpenAPI的方式执行删除操作。删除操作不可逆,执行前请确认目标Feature Group的信息无误。
内容的提问来源于stack exchange,提问作者Cybernetic
相关产品推荐
相关产品推荐

