8. Create Lookup Features
Create Lookup features¶
Now, let's dive into basic feature engineering.
The most straightforward features we can craft with FeatureByte are known as lookup features. These are either direct columns taken from the source table or simple transforms that don't require any aggregations.
We will declare features from the NEW_APPLICATION table.
Activate catalog¶
In [1]:
Copied!
import featurebyte as fb
# Set your profile to the tutorial environment
fb.use_profile("tutorial")
catalog_name = "Loan Applications 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 = "Loan Applications Dataset SDK Tutorial"
catalog = fb.Catalog.activate(catalog_name)
14:09:32 | INFO | SDK version: 3.0.1.dev45 INFO :featurebyte:SDK version: 3.0.1.dev45 14:09:32 | INFO | No catalog activated. INFO :featurebyte:No catalog activated. 14:09:32 | INFO | Using profile: tutorial INFO :featurebyte:Using profile: tutorial 14:09:32 | INFO | Using configuration file at: /Users/gxav/.featurebyte/config.yaml INFO :featurebyte:Using configuration file at: /Users/gxav/.featurebyte/config.yaml 14:09:32 | INFO | Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) INFO :featurebyte:Active profile: tutorial (https://tutorials.featurebyte.com/api/v1) 14:09:32 | INFO | SDK version: 3.0.1.dev45 INFO :featurebyte:SDK version: 3.0.1.dev45 14:09:32 | INFO | No catalog activated. INFO :featurebyte:No catalog activated. 14:09:33 | INFO | Catalog activated: Loan Applications Dataset SDK Tutorial INFO :featurebyte.api.catalog:Catalog activated: Loan Applications Dataset SDK Tutorial
Get view from table¶
In [2]:
Copied!
# Get view from NEW_APPLICATION dimension table.
new_application_view = catalog.get_view("NEW_APPLICATION")
# Get view from NEW_APPLICATION dimension table.
new_application_view = catalog.get_view("NEW_APPLICATION")
Create ratio column¶
In [3]:
Copied!
new_application_view["AMT_ANNUITY To AMT_CREDIT"] = (
new_application_view["AMT_ANNUITY"] / new_application_view["AMT_CREDIT"]
)
new_application_view["AMT_ANNUITY To AMT_CREDIT"] = (
new_application_view["AMT_ANNUITY"] / new_application_view["AMT_CREDIT"]
)
Derive new column¶
In [4]:
Copied!
new_application_view["Credit-Goods_Difference"] = (
new_application_view["AMT_CREDIT"] - new_application_view["AMT_GOODS_PRICE"]
)
new_application_view["Credit-Goods_Difference"] = (
new_application_view["AMT_CREDIT"] - new_application_view["AMT_GOODS_PRICE"]
)
In [5]:
Copied!
# Create lookup feature from AMT_ANNUITY column for New Application entity.
new_application_amt_annuity = new_application_view["AMT_ANNUITY"].as_feature("NEW_APPLICATION_AMT_ANNUITY")
# Create lookup feature from AMT_ANNUITY column for New Application entity.
new_application_amt_annuity = new_application_view["AMT_ANNUITY"].as_feature("NEW_APPLICATION_AMT_ANNUITY")
In [6]:
Copied!
# Create lookup feature from AMT_GOODS_PRICE column for New Application entity.
new_application_amt_goods_price = new_application_view["AMT_GOODS_PRICE"].as_feature("NEW_APPLICATION_AMT_GOODS_PRICE")
# Create lookup feature from AMT_GOODS_PRICE column for New Application entity.
new_application_amt_goods_price = new_application_view["AMT_GOODS_PRICE"].as_feature("NEW_APPLICATION_AMT_GOODS_PRICE")
In [7]:
Copied!
# Create lookup feature from REGION_POPULATION_RELATIVE column for New Application entity.
new_application_region_population_relative = new_application_view["REGION_POPULATION_RELATIVE"].as_feature(
"NEW_APPLICATION_REGION_POPULATION_RELATIVE"
)
# Create lookup feature from REGION_POPULATION_RELATIVE column for New Application entity.
new_application_region_population_relative = new_application_view["REGION_POPULATION_RELATIVE"].as_feature(
"NEW_APPLICATION_REGION_POPULATION_RELATIVE"
)
In [8]:
Copied!
# Create lookup feature from DAYS_EMPLOYED column for New Application entity.
new_application_days_employed = new_application_view["DAYS_EMPLOYED"].as_feature("NEW_APPLICATION_DAYS_EMPLOYED")
# Create lookup feature from DAYS_EMPLOYED column for New Application entity.
new_application_days_employed = new_application_view["DAYS_EMPLOYED"].as_feature("NEW_APPLICATION_DAYS_EMPLOYED")
In [9]:
Copied!
# Create lookup feature from DAYS_ID_PUBLISH column for New Application entity.
new_application_days_id_publish = new_application_view["DAYS_ID_PUBLISH"].as_feature("NEW_APPLICATION_DAYS_ID_PUBLISH")
# Create lookup feature from DAYS_ID_PUBLISH column for New Application entity.
new_application_days_id_publish = new_application_view["DAYS_ID_PUBLISH"].as_feature("NEW_APPLICATION_DAYS_ID_PUBLISH")
In [10]:
Copied!
# Create lookup feature from EXT_SOURCE_1 column for New Application entity.
new_application_ext_source_1 = new_application_view["EXT_SOURCE_1"].as_feature("NEW_APPLICATION_EXT_SOURCE_1")
# Create lookup feature from EXT_SOURCE_1 column for New Application entity.
new_application_ext_source_1 = new_application_view["EXT_SOURCE_1"].as_feature("NEW_APPLICATION_EXT_SOURCE_1")
In [11]:
Copied!
# Create lookup feature from EXT_SOURCE_2 column for New Application entity.
new_application_ext_source_2 = new_application_view["EXT_SOURCE_2"].as_feature("NEW_APPLICATION_EXT_SOURCE_2")
# Create lookup feature from EXT_SOURCE_2 column for New Application entity.
new_application_ext_source_2 = new_application_view["EXT_SOURCE_2"].as_feature("NEW_APPLICATION_EXT_SOURCE_2")
In [12]:
Copied!
# Create lookup feature from EXT_SOURCE_3 column for New Application entity.
new_application_ext_source_3 = new_application_view["EXT_SOURCE_3"].as_feature("NEW_APPLICATION_EXT_SOURCE_3")
# Create lookup feature from EXT_SOURCE_3 column for New Application entity.
new_application_ext_source_3 = new_application_view["EXT_SOURCE_3"].as_feature("NEW_APPLICATION_EXT_SOURCE_3")
In [13]:
Copied!
# Create lookup feature from FLOORSMAX_MODE column for New Application entity.
new_application_floorsmax_mode = new_application_view["FLOORSMAX_MODE"].as_feature("NEW_APPLICATION_FLOORSMAX_MODE")
# Create lookup feature from FLOORSMAX_MODE column for New Application entity.
new_application_floorsmax_mode = new_application_view["FLOORSMAX_MODE"].as_feature("NEW_APPLICATION_FLOORSMAX_MODE")
In [14]:
Copied!
# Create lookup feature from FLAG_DOCUMENT_3 column for New Application entity.
new_application_flag_document_3 = new_application_view["FLAG_DOCUMENT_3"].as_feature("NEW_APPLICATION_FLAG_DOCUMENT_3")
# Create lookup feature from FLAG_DOCUMENT_3 column for New Application entity.
new_application_flag_document_3 = new_application_view["FLAG_DOCUMENT_3"].as_feature("NEW_APPLICATION_FLAG_DOCUMENT_3")
In [15]:
Copied!
# Create lookup feature from AMT_ANNUITY To AMT_CREDIT column for New Application entity.
new_application_amt_annuity_to_amt_credit = new_application_view["AMT_ANNUITY To AMT_CREDIT"].as_feature(
"NEW_APPLICATION_AMT_ANNUITY_To_AMT_CREDIT"
)
# Create lookup feature from AMT_ANNUITY To AMT_CREDIT column for New Application entity.
new_application_amt_annuity_to_amt_credit = new_application_view["AMT_ANNUITY To AMT_CREDIT"].as_feature(
"NEW_APPLICATION_AMT_ANNUITY_To_AMT_CREDIT"
)
In [16]:
Copied!
# Create lookup feature from Credit-Goods_Difference column for New Application entity.
new_application_credit_goods_difference = new_application_view["Credit-Goods_Difference"].as_feature(
"NEW_APPLICATION_Credit-Goods_Difference"
)
# Create lookup feature from Credit-Goods_Difference column for New Application entity.
new_application_credit_goods_difference = new_application_view["Credit-Goods_Difference"].as_feature(
"NEW_APPLICATION_Credit-Goods_Difference"
)
In [17]:
Copied!
fb.FeatureGroup(
[
new_application_region_population_relative,
new_application_floorsmax_mode,
new_application_flag_document_3,
new_application_ext_source_3,
new_application_ext_source_2,
new_application_ext_source_1,
new_application_days_id_publish,
new_application_days_employed,
new_application_credit_goods_difference,
new_application_amt_goods_price,
new_application_amt_annuity_to_amt_credit,
new_application_amt_annuity,
]
).save()
fb.FeatureGroup(
[
new_application_region_population_relative,
new_application_floorsmax_mode,
new_application_flag_document_3,
new_application_ext_source_3,
new_application_ext_source_2,
new_application_ext_source_1,
new_application_days_id_publish,
new_application_days_employed,
new_application_credit_goods_difference,
new_application_amt_goods_price,
new_application_amt_annuity_to_amt_credit,
new_application_amt_annuity,
]
).save()
Done! |████████████████████████████████████████| 100% in 9.2s (0.11%/s) Done! |████████████████████████████████████████| 100% in 6.1s (0.17%/s) Loading Feature(s) |████████████████████████████████████████| 12/12 [100%] in 0.
Update feature type¶
In [18]:
Copied!
# Update feature type
new_application_region_population_relative.update_feature_type("numeric")
# Update feature type
new_application_region_population_relative.update_feature_type("numeric")
In [19]:
Copied!
# Update feature type
new_application_floorsmax_mode.update_feature_type("numeric")
# Update feature type
new_application_floorsmax_mode.update_feature_type("numeric")
In [20]:
Copied!
# Update feature type
new_application_flag_document_3.update_feature_type("numeric")
# Update feature type
new_application_flag_document_3.update_feature_type("numeric")
In [21]:
Copied!
# Update feature type
new_application_ext_source_3.update_feature_type("numeric")
# Update feature type
new_application_ext_source_3.update_feature_type("numeric")
In [22]:
Copied!
# Update feature type
new_application_ext_source_2.update_feature_type("numeric")
# Update feature type
new_application_ext_source_2.update_feature_type("numeric")
In [23]:
Copied!
# Update feature type
new_application_ext_source_1.update_feature_type("numeric")
# Update feature type
new_application_ext_source_1.update_feature_type("numeric")
In [24]:
Copied!
# Update feature type
new_application_days_id_publish.update_feature_type("numeric")
# Update feature type
new_application_days_id_publish.update_feature_type("numeric")
In [25]:
Copied!
# Update feature type
new_application_days_employed.update_feature_type("numeric")
# Update feature type
new_application_days_employed.update_feature_type("numeric")
In [26]:
Copied!
# Update feature type
new_application_credit_goods_difference.update_feature_type("numeric")
# Update feature type
new_application_credit_goods_difference.update_feature_type("numeric")
In [27]:
Copied!
# Update feature type
new_application_amt_goods_price.update_feature_type("numeric")
# Update feature type
new_application_amt_goods_price.update_feature_type("numeric")
In [28]:
Copied!
# Update feature type
new_application_amt_annuity_to_amt_credit.update_feature_type("numeric")
# Update feature type
new_application_amt_annuity_to_amt_credit.update_feature_type("numeric")
In [29]:
Copied!
# Update feature type
new_application_amt_annuity.update_feature_type("numeric")
# Update feature type
new_application_amt_annuity.update_feature_type("numeric")
Add description¶
In [30]:
Copied!
# Add description
new_application_region_population_relative.update_description("REGION_POPULATION_RELATIVE of the New Application")
# Add description
new_application_region_population_relative.update_description("REGION_POPULATION_RELATIVE of the New Application")
In [31]:
Copied!
# Add description
new_application_floorsmax_mode.update_description("FLOORSMAX_MODE of the New Application")
# Add description
new_application_floorsmax_mode.update_description("FLOORSMAX_MODE of the New Application")
In [32]:
Copied!
# Add description
new_application_flag_document_3.update_description("FLAG_DOCUMENT_3 of the New Application")
# Add description
new_application_flag_document_3.update_description("FLAG_DOCUMENT_3 of the New Application")
In [33]:
Copied!
# Add description
new_application_ext_source_3.update_description("EXT_SOURCE_3 of the New Application")
# Add description
new_application_ext_source_3.update_description("EXT_SOURCE_3 of the New Application")
In [34]:
Copied!
# Add description
new_application_ext_source_2.update_description("EXT_SOURCE_2 of the New Application")
# Add description
new_application_ext_source_2.update_description("EXT_SOURCE_2 of the New Application")
In [35]:
Copied!
# Add description
new_application_ext_source_1.update_description("EXT_SOURCE_1 of the New Application")
# Add description
new_application_ext_source_1.update_description("EXT_SOURCE_1 of the New Application")
In [36]:
Copied!
# Add description
new_application_days_id_publish.update_description("DAYS_ID_PUBLISH of the New Application")
# Add description
new_application_days_id_publish.update_description("DAYS_ID_PUBLISH of the New Application")
In [37]:
Copied!
# Add description
new_application_days_employed.update_description("DAYS_EMPLOYED of the New Application")
# Add description
new_application_days_employed.update_description("DAYS_EMPLOYED of the New Application")
In [38]:
Copied!
# Add description
new_application_credit_goods_difference.update_description("Credit-Goods_Difference of the New Application")
# Add description
new_application_credit_goods_difference.update_description("Credit-Goods_Difference of the New Application")
In [39]:
Copied!
# Add description
new_application_amt_goods_price.update_description("AMT_GOODS_PRICE of the New Application")
# Add description
new_application_amt_goods_price.update_description("AMT_GOODS_PRICE of the New Application")
In [40]:
Copied!
# Add description
new_application_amt_annuity_to_amt_credit.update_description("AMT_ANNUITY To AMT_CREDIT of the New Application")
# Add description
new_application_amt_annuity_to_amt_credit.update_description("AMT_ANNUITY To AMT_CREDIT of the New Application")
In [41]:
Copied!
# Add description
new_application_amt_annuity.update_description("AMT_ANNUITY of the New Application")
# Add description
new_application_amt_annuity.update_description("AMT_ANNUITY of the New Application")