{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "Jtg2MMPnKQFl"
},
"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!*"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "oEdIvQ_7KQFm"
},
"source": [
"# Writing Reference Profiles to WhyLabs"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "vEGk6S7bKQFn"
},
"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)"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "4vVUvdAZKQFn"
},
"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"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "LJ_edm1_KQFo"
},
"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": {
"id": "LS3g1ytfKQFo",
"collapsed": true
},
"outputs": [],
"source": [
"# Note: you may need to restart the kernel to use updated packages.\n",
"%pip install whylogs"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "CIqGTOZuKQFp"
},
"source": [
"## ✔️ Setting the Environment Variables"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "FaQLcGORKQFq"
},
"source": [
"In order to send your 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`).\n",
"\n",
"Let's enter the information in environment variables so whylogs can send the profile to WhyLabs."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "E5xhjvNCKQFq"
},
"outputs": [],
"source": [
"from getpass import getpass\n",
"import os\n",
"\n",
"print(\"Enter your WhyLabs API token\")\n",
"os.environ[\"WHYLABS_API_KEY\"] = getpass()\n",
"print(f\"Using API key ID: {os.environ['WHYLABS_API_KEY'][0:10]}\")\n",
"print(\"Enter your organization ID\")\n",
"os.environ[\"WHYLABS_DEFAULT_ORG_ID\"] = input()\n",
"print(\"Enter your WhyLabs Dataset ID\")\n",
"os.environ[\"WHYLABS_DEFAULT_DATASET_ID\"] = input()"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "VdUQfnk-KQFr"
},
"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": {
"id": "PpVa5irKKQFr",
"outputId": "d513c5de-8dac-47b6-dc3a-7ca8b7653d5e",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 223
}
},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Transaction ID Customer ID Quantity Item Price Total Tax Total Amount \\\n",
"0 T14259136777 C274477 1 148.9 15.6345 164.5345 \n",
"1 T7313351894 C267568 4 48.1 20.2020 212.6020 \n",
"2 T37745642681 C267098 1 10.9 1.1445 12.0445 \n",
"3 T13861409908 C271608 2 135.2 28.3920 298.7920 \n",
"4 T58956348529 C272484 4 144.3 60.6060 637.8060 \n",
"\n",
" Store Type Product Category Product Subcategory Gender \\\n",
"0 TeleShop Electronics Audio and video F \n",
"1 Flagship store Home and kitchen Furnishing M \n",
"2 Flagship store Footwear Mens F \n",
"3 MBR Footwear Mens F \n",
"4 TeleShop Clothing Mens F \n",
"\n",
" Transaction Type Age \n",
"0 Purchase 37.0 \n",
"1 Purchase 25.0 \n",
"2 Purchase 42.0 \n",
"3 Purchase 43.0 \n",
"4 Purchase 39.0 "
],
"text/html": [
"\n",
"
\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", "