Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light IH support focusing on Conversion monitoring #299

Merged
merged 11 commits into from
Dec 20, 2024
162 changes: 162 additions & 0 deletions examples/ih/Conversion_Modeling_Reporting.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import polars as pl\n",
"from pdstools import read_ds_export, IH\n",
"from pdstools.utils import cdh_utils\n",
"from ih_helper import interaction_history\n",
"\n",
"import plotly.io as pio\n",
"import plotly as plotly\n",
"import plotly.express as px\n",
"import plotly.graph_objs as go\n",
"from plotly.subplots import make_subplots\n",
"\n",
"plotly.offline.init_notebook_mode()\n",
"pio.renderers.default = \"vscode\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Conversion Results"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"ih_export_file = Path(\n",
" \"./Data-pxStrategyResult_InteractionFiles_20241213T091932_GMT.zip\"\n",
")\n",
"\n",
"if not ih_export_file.exists():\n",
" ih = IH.from_mock_data()\n",
"else:\n",
" ih = IH.from_ds_export(ih_export_file)\n",
"\n",
"ih.aggregates.summary_by_experiment(\n",
" experiment_field=\"ExperimentGroup\",\n",
" by=[\"Channel\"],\n",
" positive_labels=[\"Conversion\"],\n",
" negative_labels=[\"Impression\", \"Pending\"],\n",
").collect()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ih.plots.experiment_gauges(\n",
" experiment_field=\"ExperimentGroup\",\n",
" by=\"Channel\",\n",
" positive_labels=[\"Conversion\"],\n",
" negative_labels=[\"Impression\", \"Pending\"],\n",
" reference_values={\"Web\": 0.055, \"Email\": 0.09},\n",
" title = \"Overall Conversion\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Detailed View "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# TODO maybe this would only be useful for the test group\n",
"# then in the hovers show both test and control values\n",
"ih.plots.tree_map(\n",
" experiment_field=\"ExperimentGroup\", # should be optional, can also give query to select only the Test group\n",
" positive_labels=[\"Conversion\"],\n",
" negative_labels=[\"Impression\", \"Pending\"],\n",
" title=\"Conversion rates for all Actions\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Trends\n",
"\n",
"side-by-side bars and lines (separate methods) with error bars"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# ih.plots.trend_line(\n",
"# experiment_field=\"ExperimentGroup\", # should be optional, can also give query to select only the Test group\n",
"# granularity=\"1d\", # string language polars\n",
"# positive_labels=[\"Conversion\"],\n",
"# negative_labels=[\"Impression\", \"Pending\"],\n",
"# title=\"Conversion Rate trends\",\n",
"# )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Engagement"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ih.plots.experiment_gauges(\n",
" experiment_field=\"ExperimentGroup\",\n",
" by=\"Channel\",\n",
" reference_values={\"Web\": 0.20, \"Email\": 0.20},\n",
" title = \"Overall Engagement\",\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.12.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
58 changes: 34 additions & 24 deletions examples/ih/Example_IH_Analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
operdeck marked this conversation as resolved.
Show resolved Hide resolved
"ename": "ModuleNotFoundError",
"evalue": "No module named 'cdhtools'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[1], line 4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01msys\u001b[39;00m\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mcdhtools\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mIHanalysis\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mcdhtools\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcdh_utils\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m readDSExport\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmatplotlib\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpyplot\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mplt\u001b[39;00m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'cdhtools'"
]
}
],
"source": [
"import pandas as pd\n",
"import sys\n",
Expand All @@ -18,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -35,7 +47,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -51,7 +63,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -274,7 +286,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -548,7 +560,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -578,7 +590,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -607,7 +619,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -638,7 +650,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -668,7 +680,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -699,7 +711,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -728,7 +740,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -780,7 +792,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -809,7 +821,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -826,7 +838,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -856,7 +868,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -886,7 +898,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -895,7 +907,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -932,7 +944,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -968,11 +980,9 @@
}
],
"metadata": {
"interpreter": {
"hash": "0c5c31b7614ab5f7bbff6555bdc6f3ec4cea8754d51936ee45052251e94c1071"
},
"kernelspec": {
"display_name": "Python 3.9.4 64-bit ('newvfenv': conda)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
Expand All @@ -985,7 +995,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down
Loading
Loading