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 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 Tutorial"
catalog = fb.Catalog.activate(catalog_name)  
    
        14:22:45 | INFO | SDK version: 3.0.1.dev45 INFO :featurebyte:SDK version: 3.0.1.dev45 14:22:45 | INFO | No catalog activated. INFO :featurebyte:No catalog activated. 14:22:45 | INFO | Using profile: tutorial INFO :featurebyte:Using profile: tutorial 14:22:45 | INFO | Using configuration file at: /Users/gxav/.featurebyte/config.yaml INFO :featurebyte:Using configuration file at: /Users/gxav/.featurebyte/config.yaml 14:22:45 | INFO | Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) INFO :featurebyte:Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) 14:22:46 | INFO | SDK version: 3.0.1.dev45 INFO :featurebyte:SDK version: 3.0.1.dev45 14:22:46 | INFO | No catalog activated. INFO :featurebyte:No catalog activated. 14:22:46 | INFO | Catalog activated: Grocery Dataset Tutorial INFO :featurebyte.api.catalog:Catalog activated: Grocery Dataset Tutorial 16:08:27 | INFO | Using configuration file at: /Users/gxav/.featurebyte/config.yaml 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 0x148d647c0>
 {
   'name': 'customer',
   'created_at': '2025-06-02T06:17:26.675000',
   'updated_at': '2025-06-02T06:17:28.925000',
   'description': None,
   'serving_names': [
     'GROCERYCUSTOMERGUID'
   ],
   'catalog_name': 'Grocery Dataset 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 | 2022-07-23 15:32:29 | d87d65b8-4f78-41cc-8bd3-0064f83fe4fb | -1.067855 | 
| 1 | 2023-05-25 05:21:12 | cf670b7a-c6bf-4598-b0c0-400378b9cab6 | -0.393856 | 
| 2 | 2023-02-28 10:28:24 | 59b63729-d448-4496-8f36-de26a91e2310 | 1.000000 | 
| 3 | 2023-04-26 19:36:57 | f867935a-d33a-43d1-b3bc-02c539769836 | -0.613917 | 
| 4 | 2023-01-06 14:38:32 | e63c0f14-3530-49e9-b73e-f92594e82663 | 1.000000 | 
| 5 | 2023-06-09 16:38:32 | 6acb20fd-605d-4982-aa39-77054f08103c | -1.014358 | 
| 6 | 2023-03-20 15:08:44 | 6f5299d0-fa38-4707-8108-1b66805d84e5 | -0.146625 | 
| 7 | 2023-05-04 15:15:25 | 099cb405-5b2d-4dba-9071-a157ff0dbadc | 1.494143 | 
| 8 | 2023-06-02 14:24:28 | 0154e4b4-25a4-4276-af72-2826bbc64c31 | NaN | 
| 9 | 2022-11-01 14:32:22 | 8687e2a4-7f97-4442-873c-5c52d74404f8 | -0.623232 | 
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.1s (0.17%/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"
)