{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
">### 🚩 *Create a free WhyLabs account to get more value out of whylogs!*
\n",
">*Did you know you can store, visualize, and monitor whylogs profiles with the [WhyLabs Observability Platform](https://whylabs.ai/whylogs-free-signup?utm_source=whylogs-Github&utm_medium=whylogs-example&utm_campaign=Writing_Reference_Profiles_to_WhyLabs)? Sign up for a [free WhyLabs account](https://whylabs.ai/whylogs-free-signup?utm_source=whylogs-Github&utm_medium=whylogs-example&utm_campaign=Writing_Reference_Profiles_to_WhyLabs) to leverage the power of whylogs and WhyLabs together!*"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Writing Reference Profiles to WhyLabs"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/whylabs/whylogs/blob/mainline/python/examples/integrations/writers/Writing_Reference_Profiles_to_WhyLabs.ipynb)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"When monitoring your data, in many cases you'll be interested in comparing data from your production pipeline with a reference, or baseline, profile. This is helpful when inspecting for data drift, or assessing the quality of your data in general.\n",
"\n",
"In this example, we'll show how to send a profile logged with whylogs to your monitoring dashboard at WhyLabs Platform as a Reference Profile. When uploading a Reference Profile, you'll be able to use it for visualization and comparison purposes on your monitoring dashboard.\n",
"\n",
"> If you want to log your profiles as regular profiles (_Batch Profiles_), as opposed to _Reference Profiles_, please check the [Writing to WhyLabs](https://whylogs.readthedocs.io/en/stable/examples/integrations/writers/Writing_to_WhyLabs.html) example.\n",
"\n",
"We will:\n",
"\n",
"- Define environment variables with the appropriate Credentials and IDs\n",
"- Log data into a profile\n",
"- Use the WhyLabs Writer to send the profile as a Reference Profile to your Project at WhyLabs"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installing whylogs\n",
"\n",
"First, let's install __whylogs__. Since we want to write to WhyLabs, we'll also install the __whylabs__ extra.\n",
"\n",
"If you don't have it installed already, uncomment the line below:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Note: you may need to restart the kernel to use updated packages.\n",
"%pip install whylogs==1.3.32"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## ✔️ Setting the Environment Variables"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to send our profile to WhyLabs, let's first set up an account. You can skip this if you already have an account and a model set up.\n",
"\n",
"We will need three pieces of information:\n",
"\n",
"- API token\n",
"- Organization ID\n",
"- Dataset ID (or model-id)\n",
"\n",
"Go to https://whylabs.ai/free and grab a free account. You can follow along with the examples if you wish, but if you’re interested in only following this demonstration, you can go ahead and skip the quick start instructions.\n",
"\n",
"After that, you’ll be prompted to create an API token. Once you create it, copy and store it locally. The second important information here is your org ID. Take note of it as well. After you get your API Token and Org ID, you can go to https://hub.whylabsapp.com/models to see your projects dashboard. You can create a new project and take note of it's ID (if it's a model project it will look like `model-xxxx`)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import whylogs as why\n",
"\n",
"why.init()"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fetching the Data\n",
"\n",
"For demonstration, let's use data for transactions from a small retail business:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | Transaction ID | \n", "Customer ID | \n", "Quantity | \n", "Item Price | \n", "Total Tax | \n", "Total Amount | \n", "Store Type | \n", "Product Category | \n", "Product Subcategory | \n", "Gender | \n", "Transaction Type | \n", "Age | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "T14259136777 | \n", "C274477 | \n", "1 | \n", "148.9 | \n", "15.6345 | \n", "164.5345 | \n", "TeleShop | \n", "Electronics | \n", "Audio and video | \n", "F | \n", "Purchase | \n", "37.0 | \n", "
1 | \n", "T7313351894 | \n", "C267568 | \n", "4 | \n", "48.1 | \n", "20.2020 | \n", "212.6020 | \n", "Flagship store | \n", "Home and kitchen | \n", "Furnishing | \n", "M | \n", "Purchase | \n", "25.0 | \n", "
2 | \n", "T37745642681 | \n", "C267098 | \n", "1 | \n", "10.9 | \n", "1.1445 | \n", "12.0445 | \n", "Flagship store | \n", "Footwear | \n", "Mens | \n", "F | \n", "Purchase | \n", "42.0 | \n", "
3 | \n", "T13861409908 | \n", "C271608 | \n", "2 | \n", "135.2 | \n", "28.3920 | \n", "298.7920 | \n", "MBR | \n", "Footwear | \n", "Mens | \n", "F | \n", "Purchase | \n", "43.0 | \n", "
4 | \n", "T58956348529 | \n", "C272484 | \n", "4 | \n", "144.3 | \n", "60.6060 | \n", "637.8060 | \n", "TeleShop | \n", "Clothing | \n", "Mens | \n", "F | \n", "Purchase | \n", "39.0 | \n", "