{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2023-05-09T08:14:30.707049Z",
"start_time": "2023-05-09T08:12:29.159554Z"
},
"tags": []
},
"source": [
"### Setup Cleaning Operations \n",
"\n",
"Our data modeling is done, now we are ready to work with data itself. \n",
"\n",
"A crucial step in every data science project is ensuring the data is clean and ready for feature engineering. Issues such as missing values, disguised missing values (missing values that are not explicitly encoded as missing values), or outliers can significantly impair the quality of features and eventually the quality of the final model.\n",
"\n",
"FeatureByte offers an API to effectively address these concerns."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32;20m16:40:27\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mUsing configuration file at: /Users/viktor/.featurebyte/config.yaml\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:27\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mActive profile: tutorial (https://tutorials.featurebyte.com/api/v1)\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mSDK version: 0.6.0.dev121\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mNo catalog activated.\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20m10 feature lists, 59 features deployed\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mUsing profile: tutorial\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mUsing configuration file at: /Users/viktor/.featurebyte/config.yaml\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mActive profile: tutorial (https://tutorials.featurebyte.com/api/v1)\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mSDK version: 0.6.0.dev121\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:28\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mNo catalog activated.\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:29\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20m10 feature lists, 59 features deployed\u001b[0m\u001b[0m\n",
"\u001b[32;20m16:40:29\u001b[0m | \u001b[1m\u001b[38;20mINFO \u001b[0m\u001b[0m | \u001b[1m\u001b[38;20mCatalog activated: Grocery Dataset Tutorial\u001b[0m\u001b[0m\n"
]
}
],
"source": [
"import featurebyte as fb\n",
"\n",
"# Set your profile to the tutorial environment\n",
"fb.use_profile(\"tutorial\")\n",
"\n",
"catalog_name = \"Grocery Dataset Tutorial\"\n",
"catalog = fb.Catalog.activate(catalog_name) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look into descriptive statistics of Invoice Amount"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"invoice_table = catalog.get_table(\"GROCERYINVOICE\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\t\t\n",
"\t\t\tname | \n",
"\t\t\tGROCERYINVOICE | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tcreated_at | \n",
"\t\t\t2023-11-27 15:38:20 | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tupdated_at | \n",
"\t\t\t2023-11-27 15:40:33 | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tdescription | \n",
"\t\t\tGrocery invoice details, containing the timestamp and the total amount of the invoice | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tstatus | \n",
"\t\t\tPUBLIC_DRAFT | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tcatalog_name | \n",
"\t\t\tGrocery Dataset Tutorial | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\trecord_creation_timestamp_column | \n",
"\t\t\trecord_available_at | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\ttable_details | \n",
"\t\t\t\n",
"\t\t\t\t\n",
"\t\t\t\t\t \n",
"\t\t\t\t\t\t\n",
"\t\t\t\t\t\t\tdatabase_name | \n",
"\t\t\t\t\t\t\tTUTORIAL_DATASETS | \n",
"\t\t\t\t\t\t \n",
"\t\t\t\t\t\t\n",
"\t\t\t\t\t\t\tschema_name | \n",
"\t\t\t\t\t\t\tGROCERY | \n",
"\t\t\t\t\t\t \n",
"\t\t\t\t\t\t\n",
"\t\t\t\t\t\t\ttable_name | \n",
"\t\t\t\t\t\t\tGROCERYINVOICE | \n",
"\t\t\t\t\t\t \n",
"\t\t\t\t\t \n",
"\t\t\t\t \n",
"\t\t\t | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tentities | \n",
"\t\t\t\n",
"\t\t\t\t\n",
" \n",
" \n",
" | \n",
" name | \n",
" serving_names | \n",
" catalog_name | \n",
" \n",
" \n",
" \n",
" \n",
" 0 | \n",
" invoice | \n",
" [GROCERYINVOICEGUID] | \n",
" Grocery Dataset Tutorial | \n",
" \n",
" \n",
" 1 | \n",
" customer | \n",
" [GROCERYCUSTOMERGUID] | \n",
" Grocery Dataset Tutorial | \n",
" \n",
" \n",
" \n",
"\t\t\t | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tsemantics | \n",
"\t\t\t['event_id', 'event_timestamp', 'record_creation_timestamp', 'time_zone'] | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tcolumn_count | \n",
"\t\t\t6 | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tcolumns_info | \n",
"\t\t\t\n",
"\t\t\t\t\n",
" \n",
" \n",
" | \n",
" name | \n",
" dtype | \n",
" entity | \n",
" semantic | \n",
" critical_data_info | \n",
" description | \n",
" \n",
" \n",
" \n",
" \n",
" 0 | \n",
" GroceryInvoiceGuid | \n",
" VARCHAR | \n",
" invoice | \n",
" event_id | \n",
" None | \n",
" Unique identifier of each row in the table, in GUID format. Uniquely identifies each invoice. | \n",
" \n",
" \n",
" 1 | \n",
" GroceryCustomerGuid | \n",
" VARCHAR | \n",
" customer | \n",
" None | \n",
" None | \n",
" Unique identifier for each customer, in GUID format. | \n",
" \n",
" \n",
" 2 | \n",
" Timestamp | \n",
" TIMESTAMP | \n",
" None | \n",
" event_timestamp | \n",
" None | \n",
" The GMT timestamp of when this invoice transaction event occurred. | \n",
" \n",
" \n",
" 3 | \n",
" tz_offset | \n",
" VARCHAR | \n",
" None | \n",
" time_zone | \n",
" None | \n",
" The local timezone offset of the invoice event. | \n",
" \n",
" \n",
" 4 | \n",
" record_available_at | \n",
" TIMESTAMP | \n",
" None | \n",
" record_creation_timestamp | \n",
" None | \n",
" A timestamp for when this row was added to the database. | \n",
" \n",
" \n",
" 5 | \n",
" Amount | \n",
" FLOAT | \n",
" None | \n",
" None | \n",
" {'cleaning_operations': [{'imputed_value': None, 'type': 'disguised', 'disguised_values': [-99.0, -98.0]}, {'imputed_value': 0.0, 'type': 'less_than', 'end_point': 0.0}, {'imputed_value': 2000.0, 'type': 'greater_than', 'end_point': 2000.0}]} | \n",
" The total amount of the invoice, including all items and any discounts applied. Cannot be negative. | \n",
" \n",
" \n",
" \n",
"\t\t\t | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tevent_timestamp_column | \n",
"\t\t\tTimestamp | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tevent_id_column | \n",
"\t\t\tGroceryInvoiceGuid | \n",
"\t\t
\n",
"\t\t\n",
"\t\t\tdefault_feature_job_setting | \n",
"\t\t\t\n",
"\t\t\t\t\n",
"\t\t\t\t\t \n",
"\t\t\t\t\t\t\n",
"\t\t\t\t\t\t\tblind_spot | \n",
"\t\t\t\t\t\t\t120s | \n",
"\t\t\t\t\t\t \n",
"\t\t\t\t\t\t\n",
"\t\t\t\t\t\t\tfrequency | \n",
"\t\t\t\t\t\t\t3600s | \n",
"\t\t\t\t\t\t \n",
"\t\t\t\t\t\t\n",
"\t\t\t\t\t\t\ttime_modulo_frequency | \n",
"\t\t\t\t\t\t\t120s | \n",
"\t\t\t\t\t\t \n",
"\t\t\t\t\t \n",
"\t\t\t\t \n",
"\t\t\t | \n",
"\t\t
\n",
"\t
\n",
"\n"
],
"text/plain": [
"{\n",
" 'name': 'GROCERYINVOICE',\n",
" 'created_at': '2023-11-27T15:38:20.150000',\n",
" 'updated_at': '2023-11-27T15:40:33.297000',\n",
" 'description': 'Grocery invoice details, containing the timestamp and the total amount of the invoice',\n",
" 'status': 'PUBLIC_DRAFT',\n",
" 'catalog_name': 'Grocery Dataset Tutorial',\n",
" 'record_creation_timestamp_column': 'record_available_at',\n",
" 'table_details': {\n",
" 'database_name': 'TUTORIAL_DATASETS',\n",
" 'schema_name': 'GROCERY',\n",
" 'table_name': 'GROCERYINVOICE'\n",
" },\n",
" 'entities': [\n",
" {\n",
" 'name': 'invoice',\n",
" 'serving_names': [\n",
" 'GROCERYINVOICEGUID'\n",
" ],\n",
" 'catalog_name': 'Grocery Dataset Tutorial'\n",
" },\n",
" {\n",
" 'name': 'customer',\n",
" 'serving_names': [\n",
" 'GROCERYCUSTOMERGUID'\n",
" ],\n",
" 'catalog_name': 'Grocery Dataset Tutorial'\n",
" }\n",
" ],\n",
" 'semantics': [\n",
" 'event_id',\n",
" 'event_timestamp',\n",
" 'record_creation_timestamp',\n",
" 'time_zone'\n",
" ],\n",
" 'column_count': 6,\n",
" 'columns_info': [\n",
" {\n",
" 'name': 'GroceryInvoiceGuid',\n",
" 'dtype': 'VARCHAR',\n",
" 'entity': 'invoice',\n",
" 'semantic': 'event_id',\n",
" 'critical_data_info': None,\n",
" 'description': 'Unique identifier of each row in the table, in GUID format. Uniquely identifies each invoice.'\n",
" },\n",
" {\n",
" 'name': 'GroceryCustomerGuid',\n",
" 'dtype': 'VARCHAR',\n",
" 'entity': 'customer',\n",
" 'semantic': None,\n",
" 'critical_data_info': None,\n",
" 'description': 'Unique identifier for each customer, in GUID format.'\n",
" },\n",
" {\n",
" 'name': 'Timestamp',\n",
" 'dtype': 'TIMESTAMP',\n",
" 'entity': None,\n",
" 'semantic': 'event_timestamp',\n",
" 'critical_data_info': None,\n",
" 'description': 'The GMT timestamp of when this invoice transaction event occurred.'\n",
" },\n",
" {\n",
" 'name': 'tz_offset',\n",
" 'dtype': 'VARCHAR',\n",
" 'entity': None,\n",
" 'semantic': 'time_zone',\n",
" 'critical_data_info': None,\n",
" 'description': 'The local timezone offset of the invoice event.'\n",
" },\n",
" {\n",
" 'name': 'record_available_at',\n",
" 'dtype': 'TIMESTAMP',\n",
" 'entity': None,\n",
" 'semantic': 'record_creation_timestamp',\n",
" 'critical_data_info': None,\n",
" 'description': 'A timestamp for when this row was added to the database.'\n",
" },\n",
" {\n",
" 'name': 'Amount',\n",
" 'dtype': 'FLOAT',\n",
" 'entity': None,\n",
" 'semantic': None,\n",
" 'critical_data_info': {\n",
" 'cleaning_operations': [\n",
" {\n",
" 'imputed_value': None,\n",
" 'type': 'disguised',\n",
" 'disguised_values': [\n",
" -99.0,\n",
" -98.0\n",
" ]\n",
" },\n",
" {\n",
" 'imputed_value': 0.0,\n",
" 'type': 'less_than',\n",
" 'end_point': 0.0\n",
" },\n",
" {\n",
" 'imputed_value': 2000.0,\n",
" 'type': 'greater_than',\n",
" 'end_point': 2000.0\n",
" }\n",
" ]\n",
" },\n",
" 'description': 'The total amount of the invoice, including all items and any discounts applied. Cannot be negative.'\n",
" }\n",
" ],\n",
" 'event_timestamp_column': 'Timestamp',\n",
" 'event_id_column': 'GroceryInvoiceGuid',\n",
" 'default_feature_job_setting': {\n",
" 'blind_spot': '120s',\n",
" 'frequency': '3600s',\n",
" 'time_modulo_frequency': '120s'\n",
" }\n",
"}"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"invoice_table.info(verbose=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"That's all! Now, every time we generate a new entry from the invoice table, we can be confident that no undesirable values will slip through.\n",
"\n",
"### To learn more, refer to following materials: \n",
"- [Cleaning Operations](https://docs.featurebyte.com/latest/about/glossary/#cleaning-operations)\n",
"- [Views](https://docs.featurebyte.com/latest/about/glossary/#views-and-column-transforms)\n",
"\n",
"#### SDK reference for\n",
"- [Table.get view()](https://docs.featurebyte.com/latest/reference/featurebyte.api.event_table.EventTable.get_view/)\n",
"- [TableColumn.update_critical_data_info()](https://docs.featurebyte.com/latest/reference/featurebyte.api.base_table.TableColumn.update_critical_data_info/)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 4
}