12. Create feature list
Create a feature list¶
Feature list is a collection of features which can be used for machine learning model.
Let's take some of features we created and bundle them into a feature list.
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)
16:44:15 | INFO | Using configuration file at: /Users/viktor/.featurebyte/config.yaml 16:44:15 | INFO | Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) 16:44:15 | INFO | SDK version: 0.6.0.dev121 16:44:15 | INFO | No catalog activated. 16:44:16 | INFO | 10 feature lists, 59 features deployed 16:44:16 | INFO | Using profile: tutorial 16:44:16 | INFO | Using configuration file at: /Users/viktor/.featurebyte/config.yaml 16:44:16 | INFO | Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) 16:44:16 | INFO | SDK version: 0.6.0.dev121 16:44:16 | INFO | No catalog activated. 16:44:16 | INFO | 10 feature lists, 59 features deployed 16:44:17 | INFO | Catalog activated: Grocery Dataset Tutorial
List all features we created so far¶
In [2]:
Copied!
catalog.list_features()
catalog.list_features()
Out[2]:
id | name | dtype | readiness | online_enabled | tables | primary_tables | entities | primary_entities | created_at | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 6564b93614db530858940f50 | CUSTOMER_vs_OVERALL_item_TotalCost_across_prod... | FLOAT | DRAFT | False | [GROCERYINVOICE, INVOICEITEMS, GROCERYPRODUCT] | [INVOICEITEMS] | [customer] | [customer] | 2023-11-27T15:44:00.351000 |
1 | 6564b91c69ee318ce739930c | CUSTOMER_Latest_invoice_Amount_Z_Score_to_invo... | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:43:32.311000 |
2 | 6564b8f0a69f1a9a43bdfd85 | CUSTOMER_Std_of_invoice_Amount_28d | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:42:56.115000 |
3 | 6564b8f0a69f1a9a43bdfd84 | CUSTOMER_Std_of_invoice_Amount_14d | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:42:54.994000 |
4 | 6564b8f0a69f1a9a43bdfd83 | CUSTOMER_Avg_of_invoice_Amount_28d | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:42:53.425000 |
5 | 6564b8f0a69f1a9a43bdfd82 | CUSTOMER_Avg_of_invoice_Amount_14d | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:42:52.201000 |
6 | 6564b8f0a69f1a9a43bdfd80 | CUSTOMER_Count_of_invoice_28d | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:42:51.056000 |
7 | 6564b8f0a69f1a9a43bdfd7e | CUSTOMER_Count_of_invoice_14d | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:42:50.243000 |
8 | 6564b8f0a69f1a9a43bdfd7d | CUSTOMER_Latest_invoice_Amount | FLOAT | DRAFT | False | [GROCERYINVOICE] | [GROCERYINVOICE] | [customer] | [customer] | 2023-11-27T15:42:49.486000 |
9 | 6564b8c8e991187ee84de74e | CUSTOMER_Age_band | VARCHAR | DRAFT | False | [GROCERYCUSTOMER] | [GROCERYCUSTOMER] | [customer] | [customer] | 2023-11-27T15:42:12.722000 |
10 | 6564b8c8e991187ee84de744 | CUSTOMER_Age | INT | DRAFT | False | [GROCERYCUSTOMER] | [GROCERYCUSTOMER] | [customer] | [customer] | 2023-11-27T15:42:05.100000 |
Get features from catalog¶
In [3]:
Copied!
customer_age_band = catalog.get_feature("CUSTOMER_Age_band")
customer_latest_invoice_amount = catalog.get_feature("CUSTOMER_Latest_invoice_Amount")
customer_count_of_invoice_14d = catalog.get_feature("CUSTOMER_Count_of_invoice_14d")
customer_avg_of_invoice_amount_14d = catalog.get_feature("CUSTOMER_Avg_of_invoice_Amount_14d")
customer_std_of_invoice_amount_14d = catalog.get_feature("CUSTOMER_Std_of_invoice_Amount_14d")
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d = catalog.get_feature(
"CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d"
)
customer_vs_overall_item_totalcost_across_product_productgroups_26w = catalog.get_feature(
"CUSTOMER_vs_OVERALL_item_TotalCost_across_product_ProductGroups_26w"
)
customer_age_band = catalog.get_feature("CUSTOMER_Age_band")
customer_latest_invoice_amount = catalog.get_feature("CUSTOMER_Latest_invoice_Amount")
customer_count_of_invoice_14d = catalog.get_feature("CUSTOMER_Count_of_invoice_14d")
customer_avg_of_invoice_amount_14d = catalog.get_feature("CUSTOMER_Avg_of_invoice_Amount_14d")
customer_std_of_invoice_amount_14d = catalog.get_feature("CUSTOMER_Std_of_invoice_Amount_14d")
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d = catalog.get_feature(
"CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d"
)
customer_vs_overall_item_totalcost_across_product_productgroups_26w = catalog.get_feature(
"CUSTOMER_vs_OVERALL_item_TotalCost_across_product_ProductGroups_26w"
)
Create feature list¶
In [4]:
Copied!
simple_feature_list = fb.FeatureList(
[
customer_age_band,
customer_latest_invoice_amount,
customer_count_of_invoice_14d,
customer_avg_of_invoice_amount_14d,
customer_std_of_invoice_amount_14d,
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d,
customer_vs_overall_item_totalcost_across_product_productgroups_26w
],
name="Customer Simple FeatureList"
)
simple_feature_list = fb.FeatureList(
[
customer_age_band,
customer_latest_invoice_amount,
customer_count_of_invoice_14d,
customer_avg_of_invoice_amount_14d,
customer_std_of_invoice_amount_14d,
customer_latest_invoice_amount_Z_score_to_invoice_amount_28d,
customer_vs_overall_item_totalcost_across_product_productgroups_26w
],
name="Customer Simple FeatureList"
)
Preview feature list¶
In [5]:
Copied!
# Check the primary entity of the feature list
simple_feature_list.primary_entity
# Check the primary entity of the feature list
simple_feature_list.primary_entity
Out[5]:
[<featurebyte.api.entity.Entity at 0x16900c880> { 'name': 'customer', 'created_at': '2023-11-27T15:39:09.477000', 'updated_at': '2023-11-27T15:39:19.968000', 'description': None, 'serving_names': [ 'GROCERYCUSTOMERGUID' ], 'catalog_name': 'Grocery Dataset Tutorial' }]
In [6]:
Copied!
# Get observation table: 'Preview Table with 10 Customers'
preview_table = catalog.get_observation_table(
"Preview Table with 10 Customers"
).to_pandas()
# Get observation table: 'Preview Table with 10 Customers'
preview_table = catalog.get_observation_table(
"Preview Table with 10 Customers"
).to_pandas()
Downloading table |████████████████████████████████████████| 10/10 [100%] in 0.1
In [7]:
Copied!
# Preview simple_feature_list
simple_feature_list.preview(preview_table)
# Preview simple_feature_list
simple_feature_list.preview(preview_table)
Out[7]:
POINT_IN_TIME | GROCERYCUSTOMERGUID | CUSTOMER_Age_band | CUSTOMER_Latest_invoice_Amount | CUSTOMER_Count_of_invoice_14d | CUSTOMER_Avg_of_invoice_Amount_14d | CUSTOMER_Std_of_invoice_Amount_14d | CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d | CUSTOMER_vs_OVERALL_item_TotalCost_across_product_ProductGroups_26w | |
---|---|---|---|---|---|---|---|---|---|
0 | 2022-11-28 11:36:31 | d4559f7d-eb28-42c6-b47d-847de24952c2 | 65-69 | 6.72 | 0 | NaN | NaN | NaN | 0.466220 |
1 | 2022-10-09 15:47:55 | 3f8c7c4c-f2c2-408e-a08e-622de3d3a0b9 | 55-59 | 12.28 | 0 | NaN | NaN | NaN | 0.558564 |
2 | 2022-09-14 15:42:42 | 35390325-8443-43c1-a934-18db923d9a47 | 15-19 | 10.02 | 0 | NaN | NaN | -0.838057 | 0.872762 |
3 | 2022-12-26 18:39:46 | 4eb4ee84-ee13-4eec-9c26-61b6eb4ba35b | 70-74 | 53.09 | 5 | 15.626000 | 19.000809 | 0.992653 | 0.713610 |
4 | 2022-12-06 08:47:43 | e42fa5f3-7737-4c6a-9ef4-856f113e60bd | 20-24 | 21.74 | 3 | 15.560000 | 6.681337 | 1.530644 | 0.657608 |
5 | 2022-11-09 12:14:40 | 8440debb-6abc-4adc-8c6c-749928141fd0 | 20-24 | 15.30 | 1 | 15.300000 | 0.000000 | NaN | 0.509610 |
6 | 2022-10-12 17:32:15 | 8a54e527-e9a4-47a9-a28f-8b3c6ecc02db | 35-39 | 14.55 | 2 | 14.560000 | 0.010000 | -0.049459 | 0.753250 |
7 | 2023-01-01 11:51:28 | cea213d4-36e4-48c3-ae8d-c7a25911e11c | 85-89 | 0.89 | 12 | 3.209167 | 4.154236 | -0.530470 | 0.561260 |
8 | 2023-02-05 15:48:23 | 3b4f2821-b761-40e9-a32a-5f09685cc597 | 80-84 | 11.43 | 4 | 11.317500 | 4.526297 | 0.024855 | 0.761539 |
9 | 2023-03-10 16:15:46 | 91a64566-e212-4e36-8f23-c1f1f324a301 | 50-54 | 2.00 | 6 | 4.568333 | 2.832763 | -0.743774 | 0.729546 |
Save feature list¶
In [8]:
Copied!
# Save feature list
simple_feature_list.save()
# Add description
simple_feature_list.update_description("Simple feature list for the customer")
# Save feature list
simple_feature_list.save()
# Add description
simple_feature_list.update_description("Simple feature list for the customer")
Done! |████████████████████████████████████████| 100% in 6.5s (0.16%/s) Loading Feature(s) |████████████████████████████████████████| 7/7 [100%] in 0.7s
In [ ]:
Copied!