featuretools.save_features#

featuretools.save_features(features, location=None, profile_name=None)[源]#

将特征列表保存为 JSON 到指定的文件路径/S3 路径,写入已打开的文件,或将序列化的特征作为 JSON 字符串返回。如果未提供文件,则返回字符串。

参数:
  • features (list[FeatureBase]) – 特征定义列表。

  • location (str 或 FileObject, 可选) – 保存特征列表的位置,必须包含文件名,或可写入的文件句柄。如果 location 为 None,将返回序列化特征的 JSON 字符串。默认值:None

  • profile_name (str, bool) – 指定写入 S3 的 AWS 配置文件。默认为 None 并搜索 AWS 凭证。设置为 False 以使用匿名配置文件。

注意

在一个版本的 Featuretools 中保存的特征不保证在另一个版本中可用。升级 Featuretools 后,可能需要重新生成特征。

示例

f1 = ft.Feature(es["log"].ww["product_id"])
f2 = ft.Feature(es["log"].ww["purchased"])
f3 = ft.Feature(es["log"].ww["value"])

features = [f1, f2, f3]

# Option 1
filepath = os.path.join('/Home/features/', 'list.json')
ft.save_features(features, filepath)

# Option 2
filepath = os.path.join('/Home/features/', 'list.json')
with open(filepath, 'w') as f:
    ft.save_features(features, f)

# Option 3
features_string = ft.save_features(features)

另请参阅

load_features()