Snowpark Method Guide
Transforming Event Data into ML-Ready Features using Snowpark and Python
Calling the Features API from Snowflake to calculate features
There are two options for calculating features in Snowflake:
Call the Features API using Snowpark
Use the Python Connector or other libraries.
If either of the above approaches are taken, the Features API can be called for each location and have the results saved into a table instead of using SQL. These options skip the maintenance of SQL and is the recommended approach if possible.
Below is an example of calling the Features API with Python in Snowpark. This uses the PredictHQ Python SDK. It loops over the SAVED_LOCATIONS table, calls the Features API using the SDK, and outputs the results into a table. So, it achieves a similar result to the SQL method but using the API. This code needs to be modified to include relevant features for what is desired to be fetched.
Note this is not designed to be production-ready code that can be used without modifications. It is provided as an example. Please test and optimize as needed.
Python Code
Table Output
The output of the script above should look similar to the data below:
location | date | phq_attendance_conferences | phq_attendance_sports |
---|---|---|---|
store1-chicago | 2024-01-16 | 231 | 19329 |
store1-chicago | 2024-01-17 | 666 | 12312 |
store1-chicago | 2024-01-18 | 215 | 0 |
store1-chicago | 2024-01-19 | 87 | 23246 |
store1-chicago | 2024-01-20 | 395 | 19448 |
Refer back to Main Guide
Last updated