10. Derive Features from other Features
Derive feature from other features¶
Features can also be created based on other features.
In this tutorial we will create a feature that measures the Z-Score of the Latest invoice Amount for the customer compared to that customer's invoices over a 28d period. This feature is derived from 3 features we created previously: CUSTOMER_Latest_invoice_Amount, CUSTOMER_Avg_of_invoice_Amount_28d and CUSTOMER_Std_of_invoice_Amount_28d.
In [1]:
Copied!
import featurebyte as fb
# Set your profile to the tutorial environment
fb.use_profile("tutorial")
catalog_name = "Grocery Dataset SDK Tutorial"
catalog = fb.Catalog.activate(catalog_name)
import featurebyte as fb
# Set your profile to the tutorial environment
fb.use_profile("tutorial")
catalog_name = "Grocery Dataset SDK Tutorial"
catalog = fb.Catalog.activate(catalog_name)
17:47:21 | INFO | SDK version: 3.3.1 17:47:21 | INFO | No catalog activated. 17:47:21 | INFO | Using profile: tutorial 17:47:21 | INFO | Using configuration file at: /Users/gxav/.featurebyte/config.yaml 17:47:21 | INFO | Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) 17:47:21 | INFO | SDK version: 3.3.1 17:47:21 | INFO | No catalog activated. 17:47:21 | INFO | Catalog activated: Grocery Dataset SDK Tutorial 16:08:27 | INFO | Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) 16:08:27 | WARNING | Remote SDK version (1.1.0.dev7) is different from local (1.1.0.dev1). Update local SDK to avoid unexpected behavior. 16:08:27 | INFO | No catalog activated. 16:08:27 | INFO | Catalog activated: Grocery Dataset Tutorial
Get features we previously created and saved¶
In [2]:
Copied!
customer_latest_invoice_amount = catalog.get_feature("CUSTOMER_Latest_invoice_Amount")
customer_avg_of_invoice_amount_28d = catalog.get_feature("CUSTOMER_Avg_of_invoice_Amount_28d")
customer_std_of_invoice_amount_28d = catalog.get_feature("CUSTOMER_Std_of_invoice_Amount_28d")
customer_latest_invoice_amount = catalog.get_feature("CUSTOMER_Latest_invoice_Amount")
customer_avg_of_invoice_amount_28d = catalog.get_feature("CUSTOMER_Avg_of_invoice_Amount_28d")
customer_std_of_invoice_amount_28d = catalog.get_feature("CUSTOMER_Std_of_invoice_Amount_28d")
Derive a z-score feature from saved features¶
In [3]:
Copied!
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d = (
customer_latest_invoice_amount
- customer_avg_of_invoice_amount_28d
) / customer_std_of_invoice_amount_28d
# Give a name to new feature
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.name = \
"CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d"
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d = (
customer_latest_invoice_amount
- customer_avg_of_invoice_amount_28d
) / customer_std_of_invoice_amount_28d
# Give a name to new feature
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.name = \
"CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d"
Preview feature¶
In [4]:
Copied!
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.primary_entity
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.primary_entity
Out[4]:
[<featurebyte.api.entity.Entity at 0x105fc7290>
{
'name': 'customer',
'created_at': '2025-12-04T09:42:26.412000',
'updated_at': '2025-12-04T09:42:31.346000',
'description': None,
'serving_names': [
'GROCERYCUSTOMERGUID'
],
'catalog_name': 'Grocery Dataset SDK Tutorial'
}]
In [5]:
Copied!
# Get observation table: 'Preview Table with 10 items'
preview_table = catalog.get_observation_table("Preview Table with 10 items")
# Get observation table: 'Preview Table with 10 items'
preview_table = catalog.get_observation_table("Preview Table with 10 items")
In [6]:
Copied!
# Preview CUSTOMER_Age
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.preview(preview_table)
# Preview CUSTOMER_Age
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.preview(preview_table)
Out[6]:
| POINT_IN_TIME | GROCERYINVOICEITEMGUID | CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d | |
|---|---|---|---|
| 0 | 2023-03-24 09:58:13 | 9c7bb568-3237-4115-8e4b-ad1e2855299a | 1.193831 |
| 1 | 2023-06-26 15:05:25 | a3ac8a5e-8d9b-40b4-a835-38ccce024110 | NaN |
| 2 | 2022-07-26 09:12:59 | 75c6652a-fb95-4d36-aad1-e9a38ad2e4b0 | 0.009317 |
| 3 | 2022-09-30 17:39:57 | a4a2b3f5-69fb-403b-8868-bc360b500add | -1.247233 |
| 4 | 2023-06-14 08:04:37 | 7b7b5ae1-4a84-449b-88f0-37bd54bc5c2c | 1.179506 |
| 5 | 2022-10-03 20:03:17 | 20941a03-d666-4718-851c-5016640f2c87 | -1.000000 |
| 6 | 2022-12-05 17:43:17 | c2dc525f-9f21-4b98-87e8-8ded5f0bdd37 | -0.329317 |
| 7 | 2023-03-27 14:11:18 | f0f67ecc-38a0-4ddf-99a4-a3d531b00aa9 | -1.799405 |
| 8 | 2022-09-11 11:55:15 | 0a9b41ff-baec-4e30-b4da-b7ade2a14176 | 1.311959 |
| 9 | 2023-02-14 11:48:38 | 889a2767-dbee-4ac0-a030-f2b921f0867c | 0.287788 |
Save feature¶
In [7]:
Copied!
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.save()
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.save()
Done! |████████████████████████████████████████| 100% in 6.2s (0.16%/s) Done! |████████████████████████████████████████| 100% in 6.1s (0.17%/s)
Add description¶
In [8]:
Copied!
# Add description
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.update_description(
"Z-Score of the Latest invoice Amount for the customer compared to customer invoices over a 28d period"
)
# Add description
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d.update_description(
"Z-Score of the Latest invoice Amount for the customer compared to customer invoices over a 28d period"
)