Feature Table Usage¶
In [0]:
                Copied!
                
                
            import tecton
import pandas
from datetime import datetime, timedelta
import tecton
import pandas
from datetime import datetime, timedelta
    
        Load a Feature Table¶
In [0]:
                Copied!
                
                
            ft = tecton.get_feature_table("user_login_counts")
ft.summary()
ft = tecton.get_feature_table("user_login_counts")
ft.summary()
    
        Out[10]: 
| Name | user_login_counts | 
| Workspace | prod | 
| Description | |
| Created At | 2022-01-21 02:41:00 UTC | 
| Owner | |
| Last Modified By | derek@tecton.ai | 
| Family | |
| Source Filename | fraud/features/feature_tables/user_login_counts.py | 
| Tags | {} | 
| 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 | 30 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[14]: 
| TYPE | WINDOW_START_TIME | WINDOW_END_TIME | STATUS | ATTEMPT | JOB_CREATED_AT | JOB_LOGS | 
|---|---|---|---|---|---|---|
| INGEST | N/A | N/A | SUCCESS | 1 | 2022-01-21 02:45:12 | https://tecton-production.cloud.databricks.com/?o=1249442739035107#job/18424851/run/24959770 | 
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[15]: {'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[17]: 
| user_id | user_login_count_7d | user_login_count_30d | timestamp | |
|---|---|---|---|---|
| 0 | user_1 | 15 | 35 | 2022-01-21 02:42:29.385327 | 
| 1 | user_1 | 20 | 40 | 2022-01-14 02:42:29.385350 |