HSFS:与 Hopsworks Featurestore 交互的独立于环境的客户端
项目描述
Hopsworks 特色商店
HSFS 是与 Hopsworks Feature Store 交互的库。该库使创建新特征、特征组和训练数据集变得容易。
该库独立于环境,可用于两种模式:
-
Spark 模式:用于创建特征并将特征写入特征存储或生成训练数据集的数据工程作业。它需要 Spark 环境,例如 Hopsworks 平台或 Databricks 中提供的环境。在 Spark 模式下,HSFS 为 Python 和 JVM 语言提供绑定。
-
Python 模式:为了让数据科学工作探索特征存储中可用的特征,生成训练数据集并将它们提供给训练管道。Python 模式只需要一个 Python 解释器,并且可以在来自 Python Jobs/Jupyter Kernels、Amazon SageMaker 或 KubeFlow 的 Hopsworks 中使用。
该库会根据其运行环境自动配置自身。但是,要从 Databricks 或 AWS Sagemaker 等外部环境进行连接,需要额外的连接信息,例如主机和端口。有关从外部环境进行设置的更多信息,请参阅设置部分。
Hopsworks 入门
实例化连接并获取项目功能存储处理程序
import hsfs
connection = hsfs.connection()
fs = connection.get_feature_store()
创建新功能组
fg = fs.create_feature_group("rain",
version=1,
description="Rain features",
primary_key=['date', 'location_id'],
online_enabled=True)
fg.save(dataframe)
使用time_travel_format="HUDI"
“.
fg.insert(upsert_df)
使用time_travel_format="HUDI"
“.
fg.commit_details()
“在特定时间点阅读功能组”。
fg = fs.get_feature_group("rain", 1)
fg.read("2020-10-20 07:34:11").show()
读取在指定时间点之间发生的更新。
fg = fs.get_feature_group("rain", 1)
fg.read_changes("2020-10-20 07:31:38", "2020-10-20 07:34:11").show()
将功能连接在一起
feature_join = rain_fg.select_all()
.join(temperature_fg.select_all(), on=["date", "location_id"])
.join(location_fg.select_all())
feature_join.show(5)
加入对应于特定时间点的特征组
feature_join = rain_fg.select_all()
.join(temperature_fg.select_all(), on=["date", "location_id"])
.join(location_fg.select_all())
.as_of("2020-10-31")
feature_join.show(5)
加入对应不同时间的特征组
rain_fg_q = rain_fg.select_all().as_of("2020-10-20 07:41:43")
temperature_fg_q = temperature_fg.select_all().as_of("2020-10-20 07:32:33")
location_fg_q = location_fg.select_all().as_of("2020-10-20 07:33:08")
joined_features_q = rain_fg_q.join(temperature_fg_q).join(location_fg_q)
使用查询对象创建训练数据集:
td = fs.create_training_dataset("rain_dataset",
version=1,
data_format="tfrecords",
description="A test training dataset saved in TfRecords format",
splits={'train': 0.7, 'test': 0.2, 'validate': 0.1})
td.save(feature_join)
Scala API 的简短介绍:
import com.logicalclocks.hsfs._
val connection = HopsworksConnection.builder().build()
val fs = connection.getFeatureStore();
val attendances_features_fg = fs.getFeatureGroup("games_features", 1);
attendances_features_fg.show(1)
您可以在我们的hops-examples存储库中找到有关如何使用该库的更多示例。
文档
文档可在Hopsworks Feature Store Documentation获得。
问题
有关使用 Hopsworks 和 Feature Store 的一般问题,请在Hopsworks 社区上打开一个主题。
请使用Github 问题跟踪报告任何问题。
贡献
如果您想为此库做出贡献,请参阅贡献指南。