Skip to content

Instantly share code, notes, and snippets.

@konosp
Last active March 13, 2021 13:44
Show Gist options
  • Select an option

  • Save konosp/6e99a17477b9441c18f806319b0e7413 to your computer and use it in GitHub Desktop.

Select an option

Save konosp/6e99a17477b9441c18f806319b0e7413 to your computer and use it in GitHub Desktop.
Z-Score
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "ruled-bennett",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"import scipy.stats as st\n",
"\n",
"# Population\n",
"n_control = 80000\n",
"n_variant = 80000\n",
"\n",
"# Conversion rate\n",
"crv_control = 0.02\n",
"crv_variant = 0.0219"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "streaming-yahoo",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"N - Control: 80000 , Variant: 80000\n",
"CRV - Control: 0.0200 , Variant: 0.0219\n",
"Conversions - Control: 1600 , Variant: 1752\n",
"Var - Control: 0.0196 , Variant: 0.0214\n",
"------------\n",
"Z-score: 2.6534\n"
]
}
],
"source": [
"# Variance\n",
"var_control = crv_control * (1-crv_control) \n",
"var_variant = crv_variant * (1-crv_variant)\n",
"\n",
"conversions_control = crv_control * n_control\n",
"conversions_variant = crv_variant * n_variant\n",
"\n",
"print('N - Control: {:0.0f} , Variant: {:0.0f}'.format(n_control, n_variant))\n",
"print('CRV - Control: {:0.4f} , Variant: {:0.4f}'.format(crv_control, crv_variant))\n",
"print('Conversions - Control: {:0.0f} , Variant: {:0.0f}'.format(conversions_control, conversions_variant))\n",
"print('Var - Control: {:0.4f} , Variant: {:0.4f}'.format(var_control, var_variant))\n",
"\n",
"# Create combined random variable S\n",
"mean_control = crv_control\n",
"mean_variant = crv_variant\n",
"S_mean = mean_variant - mean_control\n",
"S_var = (var_control/n_control) + (var_variant/n_variant)\n",
"\n",
"print('------------')\n",
"Z_score = S_mean / np.sqrt(S_var)\n",
"print('Z-score: {:0.4f}'.format(Z_score))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment