{ "cells": [ { "cell_type": "markdown", "id": "0e8be874", "metadata": {}, "source": [ "### Deploy and Serve a Feature List for Model Predictions\n", "\n", "Once you have a feature list ready, it's essential to serve these features effectively to make real-time or batch predictions using your machine learning model.\n", "\n", "In this section, we'll take the feature list we previously crafted and explore two primary ways to serve its values:\n", "\n", "**REST API:** Ideal for real-time predictions where you need instantaneous results. For instance, in applications where user interactions require immediate feedback based on model predictions.\n", "\n", "**Batch Processing:** Best suited for scenarios where you have a bulk of data and don't require instant results." ] }, { "cell_type": "code", "execution_count": 1, "id": "e6475ae1", "metadata": { "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[32;20m16:46:03\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:46:03\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:46:04\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:46:04\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:46:04\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:46:04\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:46:04\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:46:04\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:46:04\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:46:04\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:46:05\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:46:05\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", "from datetime import datetime\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", "id": "cb3085ea", "metadata": {}, "source": [ "#### List feature lists in Catalog" ] }, { "cell_type": "code", "execution_count": 2, "id": "25d0339a", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnamenum_featurestatusdeployedreadiness_fraconline_fractablesentitiesprimary_entitycreated_at
06564b959d3f7244b7fc926a0Customer Simple FeatureList7DRAFTFalse0.00.0[GROCERYCUSTOMER, GROCERYINVOICE, INVOICEITEMS...[customer][customer]2023-11-27T15:44:36.966000
\n", "
" ], "text/plain": [ " id name num_feature status \\\n", "0 6564b959d3f7244b7fc926a0 Customer Simple FeatureList 7 DRAFT \n", "\n", " deployed readiness_frac online_frac \\\n", "0 False 0.0 0.0 \n", "\n", " tables entities \\\n", "0 [GROCERYCUSTOMER, GROCERYINVOICE, INVOICEITEMS... [customer] \n", "\n", " primary_entity created_at \n", "0 [customer] 2023-11-27T15:44:36.966000 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "catalog.list_feature_lists()" ] }, { "cell_type": "markdown", "id": "abe93856", "metadata": {}, "source": [ "#### Get a feature list from Catalog" ] }, { "cell_type": "code", "execution_count": 3, "id": "96147a09", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading Feature(s) |████████████████████████████████████████| 7/7 [100%] in 0.7s\n" ] } ], "source": [ "simple_feature_list = catalog.get_feature_list(\"Customer Simple FeatureList\")" ] }, { "cell_type": "markdown", "id": "d9d8f22f", "metadata": {}, "source": [ "#### Deploy feature list" ] }, { "cell_type": "code", "execution_count": 4, "id": "7c0fbd38", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done! |████████████████████████████████████████| 100% in 6.5s (0.16%/s) \n", "Done! |████████████████████████████████████████| 100% in 3.3s (0.31%/s) \n" ] } ], "source": [ "# Create a deployment\n", "deployment = simple_feature_list.deploy(\n", " deployment_name=\"Customer Spending forecast\",\n", " make_production_ready=True,\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "id": "51119653", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done! |████████████████████████████████████████| 100% in 42.0s (0.02%/s) \n" ] } ], "source": [ "# Enable deployment\n", "deployment.enable()" ] }, { "cell_type": "code", "execution_count": 6, "id": "9e6603e5", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnamefeature_list_namefeature_list_versionnum_featureenabled
06564b9c77927bf2a9d6cca65Customer Spending forecastCustomer Simple FeatureListV2311277True
\n", "
" ], "text/plain": [ " id name \\\n", "0 6564b9c77927bf2a9d6cca65 Customer Spending forecast \n", "\n", " feature_list_name feature_list_version num_feature enabled \n", "0 Customer Simple FeatureList V231127 7 True " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Check that the deployment is enabled\n", "catalog.list_deployments()" ] }, { "cell_type": "code", "execution_count": 7, "id": "35919198", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "simple_feature_list.status: DEPLOYED\n" ] } ], "source": [ "# Check status of the feature list\n", "print(\"simple_feature_list.status:\", simple_feature_list.status)" ] }, { "cell_type": "markdown", "id": "57ae146d", "metadata": {}, "source": [ "#### Get template for online serving" ] }, { "cell_type": "code", "execution_count": 8, "id": "1428f1bb", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
from typing import Any, Dict\n",
       "\n",
       "import pandas as pd\n",
       "import requests\n",
       "\n",
       "\n",
       "def request_features(entity_serving_names: Dict[str, Any]) -> pd.DataFrame:\n",
       "    """\n",
       "    Send POST request to online serving endpoint\n",
       "\n",
       "    Parameters\n",
       "    ----------\n",
       "    entity_serving_names: Dict[str, Any]\n",
       "        Entity serving name values to used for serving request\n",
       "\n",
       "    Returns\n",
       "    -------\n",
       "    pd.DataFrame\n",
       "    """\n",
       "    response = requests.post(\n",
       "        url="https://tutorials.featurebyte.com/api/v1/deployment/6564b9c77927bf2a9d6cca65/online_features",\n",
       "        headers={"Content-Type": "application/json", "active-catalog-id": "6564b7da5cf4e2dd964abb60", "Authorization": "Bearer 2u5EXHbdmiHNjEC4Y-EXBBJV-yeBiS35I4kK7FMjsLI"},\n",
       "        json={"entity_serving_names": entity_serving_names},\n",
       "    )\n",
       "    assert response.status_code == 200, response.json()\n",
       "    return pd.DataFrame.from_dict(response.json()["features"])\n",
       "\n",
       "\n",
       "request_features([{"GROCERYCUSTOMERGUID": "016d7230-8602-42ef-9861-c672f48fb010"}])\n",
       "
\n", "
" ], "text/plain": [ "'from typing import Any, Dict\\n\\nimport pandas as pd\\nimport requests\\n\\n\\ndef request_features(entity_serving_names: Dict[str, Any]) -> pd.DataFrame:\\n \"\"\"\\n Send POST request to online serving endpoint\\n\\n Parameters\\n ----------\\n entity_serving_names: Dict[str, Any]\\n Entity serving name values to used for serving request\\n\\n Returns\\n -------\\n pd.DataFrame\\n \"\"\"\\n response = requests.post(\\n url=\"https://tutorials.featurebyte.com/api/v1/deployment/6564b9c77927bf2a9d6cca65/online_features\",\\n headers={\"Content-Type\": \"application/json\", \"active-catalog-id\": \"6564b7da5cf4e2dd964abb60\", \"Authorization\": \"Bearer 2u5EXHbdmiHNjEC4Y-EXBBJV-yeBiS35I4kK7FMjsLI\"},\\n json={\"entity_serving_names\": entity_serving_names},\\n )\\n assert response.status_code == 200, response.json()\\n return pd.DataFrame.from_dict(response.json()[\"features\"])\\n\\n\\nrequest_features([{\"GROCERYCUSTOMERGUID\": \"016d7230-8602-42ef-9861-c672f48fb010\"}])'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get a python template for consuming the feature serving API\n", "deployment.get_online_serving_code(language=\"python\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "f448dd57", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
#!/bin/sh\n",
       "\n",
       "curl -X POST \\\n",
       "    -H 'Content-Type: application/json' \\\n",
       "    -H 'active-catalog-id: 6564b7da5cf4e2dd964abb60' \\\n",
       "    -H 'Authorization: Bearer 2u5EXHbdmiHNjEC4Y-EXBBJV-yeBiS35I4kK7FMjsLI' \\\n",
       "    -d '{"entity_serving_names": [{"GROCERYCUSTOMERGUID": "016d7230-8602-42ef-9861-c672f48fb010"}]}' \\\n",
       "    https://tutorials.featurebyte.com/api/v1/deployment/6564b9c77927bf2a9d6cca65/online_features\n",
       "
\n", "
" ], "text/plain": [ "'#!/bin/sh\\n\\ncurl -X POST \\\\\\n -H \\'Content-Type: application/json\\' \\\\\\n -H \\'active-catalog-id: 6564b7da5cf4e2dd964abb60\\' \\\\\\n -H \\'Authorization: Bearer 2u5EXHbdmiHNjEC4Y-EXBBJV-yeBiS35I4kK7FMjsLI\\' \\\\\\n -d \\'{\"entity_serving_names\": [{\"GROCERYCUSTOMERGUID\": \"016d7230-8602-42ef-9861-c672f48fb010\"}]}\\' \\\\\\n https://tutorials.featurebyte.com/api/v1/deployment/6564b9c77927bf2a9d6cca65/online_features'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get shell script\n", "deployment.get_online_serving_code(language=\"sh\")" ] }, { "cell_type": "markdown", "id": "282901eb", "metadata": {}, "source": [ "#### Create batch request table" ] }, { "cell_type": "code", "execution_count": 10, "id": "50d8cfd1", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Get view of current customer\n", "customer_table = catalog.get_table(\"GROCERYCUSTOMER\")\n", "customer_view = customer_table.get_view(view_mode=\"manual\")\n", "cond = customer_view.CurrentRecord == True\n", "current_customer_view = customer_view[cond]" ] }, { "cell_type": "code", "execution_count": 11, "id": "0c1cde26", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "[\n", " {\n", " 'name': 'customer',\n", " 'created_at': '2023-11-27T15:39:09.477000',\n", " 'updated_at': '2023-11-27T15:39:19.968000',\n", " 'description': None,\n", " 'serving_names': [\n", " 'GROCERYCUSTOMERGUID'\n", " ],\n", " 'catalog_name': 'Grocery Dataset Tutorial'\n", " }]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Check primary entity of the deployed feature list to obtain its serving name\n", "simple_feature_list.primary_entity" ] }, { "cell_type": "code", "execution_count": 12, "id": "1194a65d", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done! |████████████████████████████████████████| 100% in 6.5s (0.16%/s) \n" ] } ], "source": [ "# Create batch request table from the view\n", "batch_request_table = current_customer_view.create_batch_request_table(\n", " name=\"Current Customers at \" + datetime.now().strftime(\"%Y%m%d:%H%M\"),\n", " columns=[\"GroceryCustomerGuid\"],\n", " columns_rename_mapping={\n", " \"GroceryCustomerGuid\": \"GROCERYCUSTOMERGUID\",\n", " }\n", ")" ] }, { "cell_type": "code", "execution_count": 13, "id": "02951faf", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "'Current Customers at 20231127:1647'" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Get name of the batch request table\n", "batch_request_table.name" ] }, { "cell_type": "code", "execution_count": 14, "id": "11a53ab8", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnametypeshapefeature_store_namecreated_at
06564b9fa7927bf2a9d6cca66Current Customers at 20231127:1647view[500, 1]playground2023-11-27T15:47:08.828000
\n", "
" ], "text/plain": [ " id name type \\\n", "0 6564b9fa7927bf2a9d6cca66 Current Customers at 20231127:1647 view \n", "\n", " shape feature_store_name created_at \n", "0 [500, 1] playground 2023-11-27T15:47:08.828000 " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# List batch request tables in catalog\n", "catalog.list_batch_request_tables()" ] }, { "cell_type": "markdown", "id": "eb6ef8ec", "metadata": {}, "source": [ "#### Compute batch feature table" ] }, { "cell_type": "code", "execution_count": 15, "id": "2c47638e", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Get deployment and batch request table\n", "deployment = catalog.get_deployment(\"Customer Spending forecast\")\n", "batch_request_table = catalog.get_batch_request_table(batch_request_table.name)" ] }, { "cell_type": "code", "execution_count": 16, "id": "b9494894", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done! |████████████████████████████████████████| 100% in 9.8s (0.10%/s) \n" ] } ], "source": [ "# Compute batch features\n", "batch_features = deployment.compute_batch_feature_table(\n", " batch_request_table=batch_request_table,\n", " batch_feature_table_name = \n", " f\"Customer Simple FeatureList for Spending forecast with {batch_request_table.name}\"\n", ")" ] }, { "cell_type": "code", "execution_count": 17, "id": "02737afa", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnamefeature_store_namebatch_request_table_nameshapecreated_at
06564ba027927bf2a9d6cca67Customer Simple FeatureList for Spending forec...playgroundCurrent Customers at 20231127:1647[500, 8]2023-11-27T15:47:19.526000
\n", "
" ], "text/plain": [ " id \\\n", "0 6564ba027927bf2a9d6cca67 \n", "\n", " name feature_store_name \\\n", "0 Customer Simple FeatureList for Spending forec... playground \n", "\n", " batch_request_table_name shape created_at \n", "0 Current Customers at 20231127:1647 [500, 8] 2023-11-27T15:47:19.526000 " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# List observation tables\n", "catalog.list_batch_feature_tables()" ] }, { "cell_type": "code", "execution_count": 18, "id": "df35fc25", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading table |████████████████████████████████████████| 500/500 [100%] in 0\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GROCERYCUSTOMERGUIDCUSTOMER_Age_bandCUSTOMER_Latest_invoice_AmountCUSTOMER_Count_of_invoice_14dCUSTOMER_Avg_of_invoice_Amount_14dCUSTOMER_Std_of_invoice_Amount_14dCUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28dCUSTOMER_vs_OVERALL_item_TotalCost_across_product_ProductGroups_26w
0c4f35072-c0ae-48b4-9f61-4bd4c348e48a60-6410.090.0NaNNaNNaN0.740359
1c003c0a7-73f3-41c8-be4e-a7b0ede8431230-3417.980.0NaNNaNNaN0.348179
21d15db25-a662-41d5-9bad-1079b1e443ed40-446.000.0NaNNaN-1.0000000.663154
36a780e8d-0c03-4246-b08c-d76be43470bb35-398.987.07.7342867.824217-0.0268370.774803
4716c079e-a98f-456c-af24-ed7b1d87b38d85-895.760.0NaNNaN1.0000000.733773
...........................
4951c35daf7-e880-403f-95ab-3a2f3295f30360-6410.122.06.5350003.5850000.4645640.738185
496d90fda3d-2dfb-4be0-bbcf-2b5c46c97e1960-642.683.012.06000011.073328-1.2469730.641640
497f4c7dce9-ea7d-4af2-98c6-3630b7cd869d70-7432.731.032.7300000.0000001.2214330.780169
49862fd4b3d-a46c-4166-971e-3c2041d7d4d820-243.882.04.4400000.5600000.3153710.451703
499f8d62c21-4337-4a68-9063-ad3f8d16aa2185-8919.520.0NaNNaN-1.0342240.628090
\n", "

500 rows × 8 columns

\n", "
" ], "text/plain": [ " GROCERYCUSTOMERGUID CUSTOMER_Age_band \\\n", "0 c4f35072-c0ae-48b4-9f61-4bd4c348e48a 60-64 \n", "1 c003c0a7-73f3-41c8-be4e-a7b0ede84312 30-34 \n", "2 1d15db25-a662-41d5-9bad-1079b1e443ed 40-44 \n", "3 6a780e8d-0c03-4246-b08c-d76be43470bb 35-39 \n", "4 716c079e-a98f-456c-af24-ed7b1d87b38d 85-89 \n", ".. ... ... \n", "495 1c35daf7-e880-403f-95ab-3a2f3295f303 60-64 \n", "496 d90fda3d-2dfb-4be0-bbcf-2b5c46c97e19 60-64 \n", "497 f4c7dce9-ea7d-4af2-98c6-3630b7cd869d 70-74 \n", "498 62fd4b3d-a46c-4166-971e-3c2041d7d4d8 20-24 \n", "499 f8d62c21-4337-4a68-9063-ad3f8d16aa21 85-89 \n", "\n", " CUSTOMER_Latest_invoice_Amount CUSTOMER_Count_of_invoice_14d \\\n", "0 10.09 0.0 \n", "1 17.98 0.0 \n", "2 6.00 0.0 \n", "3 8.98 7.0 \n", "4 5.76 0.0 \n", ".. ... ... \n", "495 10.12 2.0 \n", "496 2.68 3.0 \n", "497 32.73 1.0 \n", "498 3.88 2.0 \n", "499 19.52 0.0 \n", "\n", " CUSTOMER_Avg_of_invoice_Amount_14d CUSTOMER_Std_of_invoice_Amount_14d \\\n", "0 NaN NaN \n", "1 NaN NaN \n", "2 NaN NaN \n", "3 7.734286 7.824217 \n", "4 NaN NaN \n", ".. ... ... \n", "495 6.535000 3.585000 \n", "496 12.060000 11.073328 \n", "497 32.730000 0.000000 \n", "498 4.440000 0.560000 \n", "499 NaN NaN \n", "\n", " CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d \\\n", "0 NaN \n", "1 NaN \n", "2 -1.000000 \n", "3 -0.026837 \n", "4 1.000000 \n", ".. ... \n", "495 0.464564 \n", "496 -1.246973 \n", "497 1.221433 \n", "498 0.315371 \n", "499 -1.034224 \n", "\n", " CUSTOMER_vs_OVERALL_item_TotalCost_across_product_ProductGroups_26w \n", "0 0.740359 \n", "1 0.348179 \n", "2 0.663154 \n", "3 0.774803 \n", "4 0.733773 \n", ".. ... \n", "495 0.738185 \n", "496 0.641640 \n", "497 0.780169 \n", "498 0.451703 \n", "499 0.628090 \n", "\n", "[500 rows x 8 columns]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Convert to pandas \n", "batch_features.to_pandas()" ] }, { "cell_type": "code", "execution_count": 19, "id": "a769a10b", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Downloading table |████████████████████████████████████████| 500/500 [100%] in 0\n" ] }, { "data": { "text/plain": [ "PosixPath('BATCH_FEATURE_TABLE_6564ba03083bd15e6cb1e755.parquet')" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# download parquet file\n", "batch_features.download()" ] }, { "cell_type": "code", "execution_count": 20, "id": "b55ad8d2", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done! |████████████████████████████████████████| 100% in 6.5s (0.16%/s) \n", "Done! |████████████████████████████████████████| 100% in 6.5s (0.16%/s) \n" ] } ], "source": [ "# delete if not needed any more\n", "batch_features.delete()\n", "batch_request_table.delete()" ] }, { "cell_type": "markdown", "id": "3d0b71de", "metadata": {}, "source": [ "#### Manage Deployment" ] }, { "cell_type": "code", "execution_count": 21, "id": "d94c0462", "metadata": { "tags": [] }, "outputs": [], "source": [ "deployment = catalog.get_deployment(\"Customer Spending forecast\")" ] }, { "cell_type": "code", "execution_count": 22, "id": "d7e4affb", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Loading Feature(s) |████████████████████████████████████████| 7/7 [100%] in 0.7s\n" ] }, { "data": { "text/html": [ "
\n", "

Job statistics (last 1 hours)

\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
request_datejob_history_windowjob_duration_tolerance
02023-11-27T15:47:48.386771160
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
feature_nameaggregation_hash
0CUSTOMER_Avg_of_invoice_Amount_14d45351576
1CUSTOMER_Count_of_invoice_14d7cee376c
2CUSTOMER_Latest_invoice_Amount0ee300b2
3CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d0ee300b2
4CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d45351576
5CUSTOMER_Latest_invoice_Amount_Z_Score_to_invoice_Amount_28d31e54300
6CUSTOMER_Std_of_invoice_Amount_14d31e54300
7CUSTOMER_vs_OVERALL_item_TotalCost_across_product_ProductGroups_26wf831676d
8CUSTOMER_vs_OVERALL_item_TotalCost_across_product_ProductGroups_26wc5e9a3c5
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
aggregation_hashfrequency(min)completed_jobsmax_duration(s)95 percentilefrac_lateexceed_periodfailed_jobsincomplete_jobstime_since_last
00ee300b2600NaNNaNNaN001NaT
17cee376c600NaNNaNNaN001NaT
245351576600NaNNaNNaN001NaT
331e54300600NaNNaNNaN001NaT
4f831676d600NaNNaNNaN001NaT
5c5e9a3c5600NaNNaNNaN001NaT
\n", " \n", " \n", "
" ], "text/plain": [ " request_date job_history_window job_duration_tolerance\n", "0 2023-11-27T15:47:48.386771 1 60\n", "\n", " feature_name aggregation_hash\n", "0 CUSTOMER_Avg_of_invoice_Amount_14d 45351576\n", "1 CUSTOMER_Count_of_invoice_14d 7cee376c\n", "2 CUSTOMER_Latest_invoice_Amount 0ee300b2\n", "3 CUSTOMER_Latest_invoice_Amount_Z_Score_to_invo... 0ee300b2\n", "4 CUSTOMER_Latest_invoice_Amount_Z_Score_to_invo... 45351576\n", "5 CUSTOMER_Latest_invoice_Amount_Z_Score_to_invo... 31e54300\n", "6 CUSTOMER_Std_of_invoice_Amount_14d 31e54300\n", "7 CUSTOMER_vs_OVERALL_item_TotalCost_across_prod... f831676d\n", "8 CUSTOMER_vs_OVERALL_item_TotalCost_across_prod... c5e9a3c5\n", "\n", " aggregation_hash frequency(min) completed_jobs max_duration(s) \\\n", "0 0ee300b2 60 0 NaN \n", "1 7cee376c 60 0 NaN \n", "2 45351576 60 0 NaN \n", "3 31e54300 60 0 NaN \n", "4 f831676d 60 0 NaN \n", "5 c5e9a3c5 60 0 NaN \n", "\n", " 95 percentile frac_late exceed_period failed_jobs incomplete_jobs \\\n", "0 NaN NaN 0 0 1 \n", "1 NaN NaN 0 0 1 \n", "2 NaN NaN 0 0 1 \n", "3 NaN NaN 0 0 1 \n", "4 NaN NaN 0 0 1 \n", "5 NaN NaN 0 0 1 \n", "\n", " time_since_last \n", "0 NaT \n", "1 NaT \n", "2 NaT \n", "3 NaT \n", "4 NaT \n", "5 NaT " ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# get feature jobs status (this will produce meaningful results once multiple jobs have been run)\n", "deployment.get_feature_jobs_status()" ] }, { "cell_type": "code", "execution_count": 23, "id": "eb75a9fc", "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Done! |████████████████████████████████████████| 100% in 9.8s (0.10%/s) \n" ] } ], "source": [ "# Disable deployment\n", "deployment.disable()" ] }, { "cell_type": "code", "execution_count": 24, "id": "26f28433", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idnamefeature_list_namefeature_list_versionnum_featureenabled
06564b9c77927bf2a9d6cca65Customer Spending forecastCustomer Simple FeatureListV2311277False
\n", "
" ], "text/plain": [ " id name \\\n", "0 6564b9c77927bf2a9d6cca65 Customer Spending forecast \n", "\n", " feature_list_name feature_list_version num_feature enabled \n", "0 Customer Simple FeatureList V231127 7 False " ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# The deployment is still part of the catalog but disabled\n", "catalog.list_deployments()" ] }, { "cell_type": "markdown", "id": "4b005f3e", "metadata": {}, "source": [ "### Concepts in this tutorial\n", "- [Feature list deployment](https://docs.featurebyte.com/latest/about/glossary/#feature-list-deployment)\n", "- [REST API and batch serving](https://docs.featurebyte.com/latest/about/glossary/#online-and-batch-serving)\n", "- [Feature jobs](https://docs.featurebyte.com/latest/about/glossary/#feature-jobs)\n", "\n", "#### SDK reference for\n", "- [Deployment](https://docs.featurebyte.com/latest/reference/core/deployment/)\n", "- [Batch Request Table](https://docs.featurebyte.com/latest/reference/core/batch_request_table/)\n", "- [Batch Feature Table](https://docs.featurebyte.com/latest/reference/core/batch_feature_table/)\n", "- [FeatureList.deploy()](https://docs.featurebyte.com/latest/reference/featurebyte.api.feature_list.FeatureList.deploy/) \n", "- [Deployment.enable()](https://docs.featurebyte.com/latest/reference/featurebyte.api.deployment.Deployment.enable/)\n", "- [Deployment.get_online_serving_code()](https://docs.featurebyte.com/latest/reference/featurebyte.api.deployment.Deployment.get_online_serving_code/)\n", "- [Deployment.compute batch feature_table()](https://docs.featurebyte.com/latest/reference/featurebyte.api.deployment.Deployment.compute_batch_feature_table/)\n", "- [Table.get_view()](https://docs.featurebyte.com/latest/reference/featurebyte.api.scd_table.SCDTable.get_view/) in a manual mode\n", "- [View.create_batch_request_table()](https://docs.featurebyte.com/latest/reference/featurebyte.api.view.View.create_batch_request_table/)\n", "- [SourceTable.create_batch_request_table()](https://docs.featurebyte.com/latest/reference/featurebyte.api.source_table.SourceTable.create_batch_request_table/)" ] }, { "cell_type": "code", "execution_count": null, "id": "f50df3b4", "metadata": {}, "outputs": [], "source": [] } ], "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": 5 }