首页 > 解决方案 > 功能工具可以将功能列表直接保存到s3吗?

问题描述

我正在尝试将从深度特征合成返回的特征列表直接保存到 S3。如果在本地持久化,我可以使用“ft.save_features(features,pathtofile)”。反正有没有将 S3 url 传递给这个方法?

标签: amazon-s3featuretools

解决方案


目前,它只能写入本地磁盘。如果要保存到 S3 并稍后从 S3 下载,可以通过像这样将文件写入磁盘和从磁盘写入文件来实现

import featuretools as ft
import boto

es = ft.demo.load_mock_customer(return_entityset=True)

feature_defs = ft.dfs(entityset=es,
                      target_entity="customers",
                      agg_primitives=["count"],
                      trans_primitives=["month"],
                      max_depth=1,
                      features_only=True)

# save features to disk
saved_features_file = "feature_defs"
ft.save_features(feature_defs, saved_features_file)

# upload to s3
s3_connection = boto.connect_s3()
bucket = s3_connection.get_bucket('featuretools-static')
key = boto.s3.key.Key(bucket, saved_features_file)
key.set_contents_from_filename(saved_features_file)

# download from s3
downloaded_features_file = "feature_defs_downloaded"
key.get_contents_to_filename(downloaded_features_file)
feature_defs_s3 = ft.load_features(downloaded_features_file)

# test to make sure it works
feature_matrix = ft.calculate_feature_matrix(entityset=es, features=feature_defs_s3)

推荐阅读