{"id":22831,"date":"2021-10-29T12:05:42","date_gmt":"2021-10-29T09:05:42","guid":{"rendered":"http:\/\/sense23.com\/academy\/?post_type=episode&#038;p=22831"},"modified":"2022-09-12T07:16:39","modified_gmt":"2022-09-12T04:16:39","slug":"prinyatie-reshenij-na-osnove-a-b-testa","status":"publish","type":"episode","link":"https:\/\/sense23.com\/academy\/module\/prinyatie-reshenij-na-osnove-a-b-testa\/","title":{"rendered":"\u041f\u0440\u0438\u043d\u044f\u0442\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 A\/B-\u0442\u0435\u0441\u0442\u0430"},"content":{"rendered":"\n<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0432\u044b&nbsp;\u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439, \u043a\u0430\u043a \u0435\u0433\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c, \u0438&nbsp;\u043a\u0430\u043a \u043e\u043d&nbsp;\u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u043c\u0438; \u043a\u0430\u043a \u0441&nbsp;\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Pandas \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0438&nbsp;\u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u044f. \u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u043e\u0434\u0443\u043b\u044f&nbsp;\u2014 \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0431\u043e\u0442\u044b \u0441&nbsp;\u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u0421\u0430\u043c\u043e\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435 \u0443\u0436\u0435 \u043f\u043e\u0437\u0430\u0434\u0438. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/p>\n\n\n\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u043c\u043d\u043e\u0433\u043e\u0435 \u0443\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0437\u0430 \u043d\u0430\u0441. \u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 Python, \u0432\u044b \u0432 99,9% \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a rel=\"noreferrer noopener\" href=\"https:\/\/ru.wikipedia.org\/wiki\/Pandas\" target=\"_blank\">pandas<\/a> \u0438 \u0435\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 dataframe. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0438 \u0441\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\ndata  = pd.read_csv('my_test_data.csv') #\u0432 \u0441\u043a\u043e\u0431\u043a\u0430\u0445 \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443<\/code><\/pre>\n\n\n\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u043b\u043e\u0441\u044c, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 head(n) \u2014 \u043e\u043d\u0430 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0435 n \u0441\u0442\u0440\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data.head(10)\n<\/code><\/pre>\n\n\n\n<p>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043e\u043a.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data&#91;'\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435_\u043a\u043e\u043b\u043e\u043d\u043a\u0438']<\/code><\/pre>\n\n\n\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0443\u0441\u043b\u043e\u0432\u0438\u044e.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>data&#91;data&#91;'\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430']=='B'] \n<\/code><\/pre>\n\n\n\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u0445 <a href=\"https:\/\/www.scipy.org\/getting-started.html\" rel=\"noreferrer noopener\" target=\"_blank\">scipy<\/a> \u0438 <a href=\"https:\/\/www.statsmodels.org\/stable\/gettingstarted.html\" rel=\"noreferrer noopener\" target=\"_blank\">statsmodels<\/a>. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0442\u0430\u043c \u043d\u0435\u0442, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0435\u0433\u043e \u0443\u0436\u0435 \u043a\u0442\u043e-\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0430\u0439\u0442\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u0442\u044c \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 <a href=\"https:\/\/github.com\/facebookincubator\/bootstrapped\" rel=\"noreferrer noopener\" target=\"_blank\">bootstrap<\/a>.<\/p>\n\n\n\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u0432:<\/p>\n\n\n\n<p><strong>t-\u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0421\u0442\u044c\u044e\u0434\u0435\u043d\u0442\u0430, \u043a\u043e\u0434 \u043d\u0430 Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import scipy.stats as stats\nalpha = 0.05\nt_statistic, p = stats.ttest_ind(data&#91;data&#91;'\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430']=='A'].metric, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t data&#91;data&#91;'\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430']=='B'].metric, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t equal_var = False)\n\nprint('\u041d\u0443\u043b\u0435\u0432\u0430\u044f \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0430 \u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0435 \u0441\u0440\u0435\u0434\u043d\u0438\u0445 {}\u043e\u0442\u043a\u043b\u043e\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 {}, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 p-value = {:f}'.format('\u043d\u0435 ' if p &gt; alpha else '', 1-alpha, p))<\/code><\/pre>\n\n\n\n<p><strong>\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0445\u0438-\u043a\u0432\u0430\u0434\u0440\u0430\u0442, \u043a\u043e\u0434 \u043d\u0430 Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from scipy.stats import chi2_contingency\nchi, p, dof, exp = chi2_contingency(&#91;data.groupby('\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430').paid.sum(),\n                  data.groupby('\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430').user_id.count() - data.groupby('\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430').paid.sum()])\n\n#paid - \u043a\u043e\u043b\u043e\u043d\u043a\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 1 \u0441\u0442\u043e\u0438\u0442 \u0434\u043b\u044f \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0432\u0448\u0438\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 0 \u0434\u043b\u044f \u043d\u0435 \u0437\u0430\u043f\u043b\u0430\u0442\u0438\u0432\u0448\u0438\u0445\n\nprint('\u0420\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 \u0433\u0440\u0443\u043f\u043f\u0430\u043c\u0438 {}\u0437\u043d\u0430\u0447\u0438\u043c\u0430\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0437\u043d\u0430\u0447\u0438\u043c\u043e\u0441\u0442\u0438 {}, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 p-value = {:f}'.format('\u043d\u0435 ' if p &gt; alpha else '', 1-alpha, p))<\/code><\/pre>\n\n\n\n<p><strong>Bootstrap, \u043a\u043e\u0434 \u043d\u0430 Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>!pip install bootstrapped\nimport bootstrapped.bootstrap as bs\nimport bootstrapped.stats_functions as bs_stats\nimport bootstrapped.compare_functions as bs_compare\nimport numpy as np\nimport matplotlib.pyplot as plt\nplt.style.use('ggplot')\n\nboot = bs.bootstrap_ab(data&#91;data&#91;'\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430']=='A'].metrics.values,\n\t\t\t\t\t\t\t\t\t\t\t data&#91;data&#91;'\u0413\u0440\u0443\u043f\u043f\u0430_\u0442\u0435\u0441\u0442\u0430']=='B'].metrics.values, \n                       bs_stats.mean, bs_compare.difference, \n\t\t\t\t\t\t\t\t\t\t\t num_threads = -1, \n\t\t\t\t\t\t\t\t\t\t\t return_distribution = True)\n\nplt.hist(boot, bins = 30)\nplt.axvline(x = np.percentile(boot, 2.5), color='grey', linestyle='--', linewidth = 3)\nplt.axvline(x = np.percentile(boot, 97.5), color='grey', linestyle='--', linewidth = 3)\nplt.axvline(x = 0, color='blue', linestyle='--', linewidth = 3)\nplt.show(<\/code><\/pre>\n\n\n\n<p>\u0415\u0449\u0435 \u0440\u0430\u0437 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:<\/p>\n\n\n\n<ol><li>\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0434\u0430\u0442\u0430-\u0441\u0435\u0442\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e A\/B-\u0442\u0435\u0441\u0442\u0430.<\/li><li>\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u043c\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f.<\/li><li>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0440\u0430\u0441\u0447\u0435\u0442 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d.<\/li><li>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b A\/B-\u0442\u0435\u0441\u0442\u0430 \u0433\u043e\u0442\u043e\u0432\u044b, \u0432\u044b \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u044b!<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u0412 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u0432\u044b&nbsp;\u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439, \u043a\u0430\u043a \u0435\u0433\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c, \u0438&nbsp;\u043a\u0430\u043a \u043e\u043d&nbsp;\u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u043e \u0438 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u043c\u0438; \u043a\u0430\u043a<\/p>\n","protected":false},"author":2281,"featured_media":22955,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"mtag":[778,750],"_links":{"self":[{"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/episode\/22831"}],"collection":[{"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/episode"}],"about":[{"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/types\/episode"}],"author":[{"embeddable":true,"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/users\/2281"}],"replies":[{"embeddable":true,"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/comments?post=22831"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/media\/22955"}],"wp:attachment":[{"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/media?parent=22831"}],"wp:term":[{"taxonomy":"mtag","embeddable":true,"href":"https:\/\/sense23.com\/academy\/wp-json\/wp\/v2\/mtag?post=22831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}