Feature Table Usage¶
In [0]:
Copied!
import tecton
import pandas
from datetime import datetime, timedelta
ws = tecton.get_workspace("prod")
import tecton
import pandas
from datetime import datetime, timedelta
ws = tecton.get_workspace("prod")
Load a Feature Table¶
In [0]:
Copied!
ft = ws.get_feature_table("user_login_counts")
ft.summary()
ft = ws.get_feature_table("user_login_counts")
ft.summary()
Out[13]:
Name | user_login_counts |
Workspace | prod |
Description | User login counts over time. |
Created At | 2022-06-07 17:57:09 UTC |
Owner | derek@tecton.ai |
Last Modified By | jake@tecton.ai |
Family | |
Source Filename | fraud/features/feature_tables/user_login_counts.py |
Tags | {'release': 'production'} |
Type | FeatureTable |
URL | https://staging.tecton.ai/app/repo/prod/features/user_login_counts |
Entities | fraud_user |
Features | user_login_count_7d, user_login_count_30d |
Feature Services | |
Timestamp Key | timestamp |
Online Materialization | Enabled |
Offline Materialization | Enabled |
Online Join Keys | user_id |
Offline Join Keys | user_id |
Serving TTL | 7 days |
Schema | user_id string timestamp timestamp user_login_count_7d long user_login_count_30d long |
Ingest Feature Data¶
In [0]:
Copied!
df = pandas.DataFrame([{"user_id": "user_1",
"timestamp": pandas.Timestamp(datetime.now()),
"user_login_count_7d": 15,
"user_login_count_30d": 35},
{"user_id": "user_1",
"timestamp": pandas.Timestamp(datetime.now() - timedelta(days=7)),
"user_login_count_7d": 20,
"user_login_count_30d": 40},
{"user_id": "user_2",
"timestamp": pandas.Timestamp(datetime.now()),
"user_login_count_7d": 100,
"user_login_count_30d": 200}])
ft.ingest(df)
df = pandas.DataFrame([{"user_id": "user_1",
"timestamp": pandas.Timestamp(datetime.now()),
"user_login_count_7d": 15,
"user_login_count_30d": 35},
{"user_id": "user_1",
"timestamp": pandas.Timestamp(datetime.now() - timedelta(days=7)),
"user_login_count_7d": 20,
"user_login_count_30d": 40},
{"user_id": "user_2",
"timestamp": pandas.Timestamp(datetime.now()),
"user_login_count_7d": 100,
"user_login_count_30d": 200}])
ft.ingest(df)
Check materialization status¶
Now that the ingestion has been kicked off, you can check the job status in your Notebook or the Web UI.
In [0]:
Copied!
ft.materialization_status()
ft.materialization_status()
All the displayed times are in UTC time zone
Out[17]:
TYPE | WINDOW_START_TIME | WINDOW_END_TIME | STATUS | ATTEMPT | JOB_CREATED_AT | JOB_LOGS |
---|---|---|---|---|---|---|
INGEST | N/A | N/A | SUCCESS | 1 | 2022-06-07 18:05:59 | https://tecton-production.cloud.databricks.com/?o=1249442739035107#job/59589832183771/run/67436640 |
Read Features Online¶
In [0]:
Copied!
ft.get_online_features(join_keys={"user_id": "user_1"}).to_dict()
ft.get_online_features(join_keys={"user_id": "user_1"}).to_dict()
Out[18]: {'user_login_count_30d': 35, 'user_login_count_7d': 15}
Read Features Offline¶
In [0]:
Copied!
ft.get_historical_features(entities=pandas.DataFrame([{"user_id": "user_1"}])).to_pandas()
ft.get_historical_features(entities=pandas.DataFrame([{"user_id": "user_1"}])).to_pandas()
Out[19]:
user_id | user_login_count_7d | user_login_count_30d | timestamp | |
---|---|---|---|---|
0 | user_1 | 15 | 35 | 2022-06-07 17:57:51.410874 |
1 | user_1 | 20 | 40 | 2022-05-31 17:57:51.410897 |