{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "Transactions allow several profiles to be commited to WhyLabs as a group. Let's start with some setup.\n" ], "metadata": { "id": "u5FQGlNpNVUX" } }, { "cell_type": "code", "source": [ "!pip install whylogs" ], "metadata": { "id": "rDZLfAYMi7vi" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "import whylogs as why\n", "from whylabs_client.api.transactions_api import TransactionsApi\n", "from whylogs.core.schema import DatasetSchema\n", "from whylogs.core.segmentation_partition import segment_on_column\n", "from whylogs.api.writer.whylabs import WhyLabsWriter, WhyLabsTransaction\n", "import os\n", "from uuid import uuid4\n", "from whylogs.datasets import Ecommerce\n", "import numpy as np\n", "import pandas as pd\n", "from datetime import datetime, timedelta, timezone" ], "metadata": { "id": "3eyEw1UUi_nl" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "os.environ[\"WHYLABS_DEFAULT_ORG_ID\"] = \"org-XXX\"\n", "os.environ[\"WHYLABS_DEFAULT_DATASET_ID\"] = \"model-XXX\"\n", "os.environ[\"WHYLABS_API_KEY\"] = \"XXXX:org-XXX\"" ], "metadata": { "id": "h3Fq8l14XmpA" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "## Get example dataset" ], "metadata": { "id": "ul-WBntiyS9x" } }, { "cell_type": "code", "source": [ "dataset = Ecommerce()" ], "metadata": { "id": "kbVch_DaySHW" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "daily_batches = dataset.get_inference_data(number_batches=20)\n", "list_daily_batches = list(daily_batches)" ], "metadata": { "id": "G_wcHlmBypVj" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "columns = ['product','sales_last_week','market_price','rating','category','output_discount','output_prediction','output_score']\n", "\n", "df = list_daily_batches[0].data[columns]" ], "metadata": { "id": "ltwx9rVJyzDc" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "df.head()" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 235 }, "id": "Wd0Ms0UDynEi", "outputId": "505fef55-900a-4f85-d86d-a0f48ccb3a69" }, "execution_count": null, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ " product \\\n", "date \n", "2024-02-23 00:00:00+00:00 1-2-3 Noodles - Veg Masala Flavour \n", "2024-02-23 00:00:00+00:00 Jaggery Powder - Organic, Sulphur Free \n", "2024-02-23 00:00:00+00:00 Pudding - Assorted \n", "2024-02-23 00:00:00+00:00 Perfectly Moist Dark Chocolate Fudge Cake Mix ... \n", "2024-02-23 00:00:00+00:00 Pasta/Spaghetti Spoon - Nylon, Silicon Handle,... \n", "\n", " sales_last_week market_price rating \\\n", "date \n", "2024-02-23 00:00:00+00:00 2 12.0 4.200000 \n", "2024-02-23 00:00:00+00:00 1 280.0 3.996552 \n", "2024-02-23 00:00:00+00:00 3 50.0 4.400000 \n", "2024-02-23 00:00:00+00:00 1 495.0 4.000000 \n", "2024-02-23 00:00:00+00:00 1 299.0 3.732046 \n", "\n", " category output_discount \\\n", "date \n", "2024-02-23 00:00:00+00:00 Snacks and Branded Foods 0 \n", "2024-02-23 00:00:00+00:00 Gourmet and World Food 0 \n", "2024-02-23 00:00:00+00:00 Gourmet and World Food 0 \n", "2024-02-23 00:00:00+00:00 Gourmet and World Food 0 \n", "2024-02-23 00:00:00+00:00 Kitchen, Garden and Pets 1 \n", "\n", " output_prediction output_score \n", "date \n", "2024-02-23 00:00:00+00:00 0 1.000000 \n", "2024-02-23 00:00:00+00:00 0 0.571833 \n", "2024-02-23 00:00:00+00:00 1 0.600000 \n", "2024-02-23 00:00:00+00:00 1 0.517833 \n", "2024-02-23 00:00:00+00:00 1 0.950000 " ], "text/html": [ "\n", "
\n", " | product | \n", "sales_last_week | \n", "market_price | \n", "rating | \n", "category | \n", "output_discount | \n", "output_prediction | \n", "output_score | \n", "
---|---|---|---|---|---|---|---|---|
date | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
2024-02-23 00:00:00+00:00 | \n", "1-2-3 Noodles - Veg Masala Flavour | \n", "2 | \n", "12.0 | \n", "4.200000 | \n", "Snacks and Branded Foods | \n", "0 | \n", "0 | \n", "1.000000 | \n", "
2024-02-23 00:00:00+00:00 | \n", "Jaggery Powder - Organic, Sulphur Free | \n", "1 | \n", "280.0 | \n", "3.996552 | \n", "Gourmet and World Food | \n", "0 | \n", "0 | \n", "0.571833 | \n", "
2024-02-23 00:00:00+00:00 | \n", "Pudding - Assorted | \n", "3 | \n", "50.0 | \n", "4.400000 | \n", "Gourmet and World Food | \n", "0 | \n", "1 | \n", "0.600000 | \n", "
2024-02-23 00:00:00+00:00 | \n", "Perfectly Moist Dark Chocolate Fudge Cake Mix ... | \n", "1 | \n", "495.0 | \n", "4.000000 | \n", "Gourmet and World Food | \n", "0 | \n", "1 | \n", "0.517833 | \n", "
2024-02-23 00:00:00+00:00 | \n", "Pasta/Spaghetti Spoon - Nylon, Silicon Handle,... | \n", "1 | \n", "299.0 | \n", "3.732046 | \n", "Kitchen, Garden and Pets | \n", "1 | \n", "1 | \n", "0.950000 | \n", "