{"id":458732,"date":"2025-05-06T03:06:01","date_gmt":"2025-05-06T03:06:01","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=458732"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=458732","title":{"rendered":"<span>D7 \u2014 \u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c: \u0438\u0449\u0435\u043c \u043f\u0440\u0430\u0432\u0434\u0443<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e \u0440\u0435\u0442\u0435\u043d\u0448\u043d \u2014 \u0442\u0443 \u0441\u0430\u043c\u0443\u044e \u043c\u0435\u0442\u0440\u0438\u043a\u0443, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u043e \u043f\u043b\u044f\u0448\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u0412\u044b \u0437\u043d\u0430\u0435\u0442\u0435: \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0447\u0435\u0440\u0435\u0437 7 \u0434\u043d\u0435\u0439\u00bb (D7) \u2014 \u0438 \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043a\u043b\u0430\u0441\u0441<\/p>\n<p>\u041d\u043e \u043d\u0430 \u0434\u0435\u043b\u0435 \u043a\u043b\u0430\u0441\u0441 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 D7 retention \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u043a\u0440\u0438\u0432\u044b\u0435 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b, \u0432 \u0447\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 recurring vs one-shot \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435. <\/p>\n<h3>\u0413\u0434\u0435 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 D7 Retention<\/h3>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<ol>\n<li>\n<p>\u0411\u0435\u0440\u0451\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0432 \u0434\u0435\u043d\u044c D0.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043d\u0438\u0445 \u0432\u0435\u0440\u043d\u0443\u043b\u043e\u0441\u044c \u0440\u043e\u0432\u043d\u043e \u043d\u0430 D7.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u00abD7 retention = \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \/ \u0432\u0441\u0435\u0433\u043e D0\u00bb.<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u00ad\u2026<\/p>\n<ul>\n<li>\n<p><strong>\u0414\u0435\u0439\u043b\u0438-\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a<\/strong>: \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044e\u0437\u0435\u0440\u044b \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u043d\u0430\u20091-\u0439, \u043d\u0430\u20093-\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442<\/strong>: \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u0438\u043a, \u0432\u0435\u0431, \u0434\u0435\u0441\u043a\u0442\u043e\u043f \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0437\u043e\u0432\u0430\u044f \u0430\u043a\u0446\u0438\u044f<\/strong>: \u043a\u0442\u043e-\u0442\u043e \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0438\u043b\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 7-\u0439 \u0434\u0435\u043d\u044c \u0438\u0437-\u0437\u0430 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438, \u043d\u043e \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u0447\u0435\u0437 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0441\u0451 \u044d\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 D7 \u0432 \u043b\u043e\u0442\u0435\u0440\u0435\u044e: \u043a\u0442\u043e-\u0442\u043e \u043f\u043e\u043f\u0430\u043b \u043f\u043e\u0434 \u0433\u043e\u0440\u044f\u0447\u0443\u044e \u0440\u0443\u043a\u0443, \u0430 \u043a\u0442\u043e-\u0442\u043e \u043d\u0435\u0442. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u043c\u0435\u0448\u0430\u043d\u0438\u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0410 \u0432\u0435\u0434\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u044f \u0432\u043e\u043e\u0431\u0449\u0435, \u0438\u043b\u0438 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0448\u0443\u043c.<\/p>\n<h3>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 true retention curves \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h3>\n<p>\u041a\u043e\u0433\u043e\u0440\u0442\u044b \u2014 \u043d\u0430\u0448\u0435 \u0432\u0441\u0451. \u0412\u043c\u0435\u0441\u0442\u043e \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043d\u0430 D7\u00bb \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443:<\/p>\n<ul>\n<li>\n<p><strong>\u0441\u0442\u0440\u043e\u043a\u0438<\/strong> \u2014 \u043a\u043e\u0433\u043e\u0440\u0442\u044b \u043f\u043e \u0434\u0430\u0442\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u0438\u043b\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438) D0, D1, \u2026<\/p>\n<\/li>\n<li>\n<p><strong>\u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/strong> \u2014 \u0434\u043d\u0438 \u043f\u043e\u0441\u043b\u0435 D0: Day0, Day1, Day2, \u2026 DayN<\/p>\n<\/li>\n<li>\n<p><strong>\u044f\u0447\u0435\u0439\u043a\u0438<\/strong> \u2014 \u0434\u043e\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b, \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0432\u0448\u0438\u0445 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u043d\u044c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 Python + pandas \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<pre><code class=\"python\">import pandas as pd # \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 events \u0441 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438 user_id \u0438 event_timestamp events = pd.read_csv('events.csv', parse_dates=['event_timestamp']) events['cohort_date'] = events.groupby('user_id')['event_timestamp'].transform('min').dt.normalize() events['day_offset'] = (events['event_timestamp'].dt.normalize() - events['cohort_date']).dt.days  # \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0433\u043e\u0440\u0442\u044b cohort_counts = (     events.drop_duplicates(['user_id', 'day_offset'])     .groupby(['cohort_date', 'day_offset'])     .agg({'user_id': 'nunique'})     .reset_index() )  # \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0435\u0433\u043e \u0432 \u043a\u043e\u0433\u043e\u0440\u0442\u0435 cohort_sizes = (     events.groupby('cohort_date')     .agg({'user_id': 'nunique'})     .rename(columns={'user_id': 'cohort_size'})     .reset_index() )  # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c retention = cohort_counts.merge(cohort_sizes, on='cohort_date') retention['retention_rate'] = retention['user_id'] \/ retention['cohort_size'] # Pivot \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430 retention_pivot = retention.pivot(index='cohort_date', columns='day_offset', values='retention_rate') print(retention_pivot.head())<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0442\u0438\u043f\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">cohort_date<\/p>\n<\/th>\n<th>\n<p align=\"left\">0<\/p>\n<\/th>\n<th>\n<p align=\"left\">1<\/p>\n<\/th>\n<th>\n<p align=\"left\">2<\/p>\n<\/th>\n<th>\n<p align=\"left\">3<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u2026<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2025-04-01<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.0<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.45<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.30<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.25<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2025-04-02<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.0<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.50<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.28<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.22<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0422\u0443\u0442 \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u043a \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043f\u0430\u0434\u0430\u0435\u0442 \u0434\u0435\u043d\u044c \u0437\u0430 \u0434\u043d\u0451\u043c. <\/p>\n<h3>recurring behavior vs one-shot behavior<\/h3>\n<ul>\n<li>\n<p><strong>One-shot behavior<\/strong>: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0448\u0451\u043b \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b, \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u043e\u043a\u0443\u043f\u043a\u0443\/\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0438 \u043f\u0440\u043e\u043f\u0430\u043b.<\/p>\n<\/li>\n<li>\n<p><strong>Recurring behavior<\/strong>: \u044e\u0437\u0435\u0440 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0432\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0443: \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439, \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447, \u0430\u043f\u0433\u0440\u0435\u0439\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430\u2026<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u0438\u0445, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b:<\/p>\n<ul>\n<li>\n<p>One-shot \u044e\u0437\u0435\u0440\u044b \u0434\u0430\u044e\u0442 retention \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u043d\u044f\u0445 (Day0, Day1), \u0430 \u043f\u043e\u0442\u043e\u043c \u00ab\u0448\u0443\u043c\u0438\u0445\u0430\u00bb \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>Recurring \u044e\u0437\u0435\u0440\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 long tail: retention \u043c\u043e\u0436\u0435\u0442 \u00ab\u0445\u0432\u043e\u0441\u0442\u0438\u043a\u043e\u043c\u00bb \u0442\u044f\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0434\u0435\u043b\u044e, \u043c\u0435\u0441\u044f\u0446, \u0433\u043e\u0434.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u044d\u0442\u043e \u0443\u0447\u0435\u0441\u0442\u044c?<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/strong>: K-means\/DBSCAN \u043f\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e (\u0447\u0430\u0441\u0442\u043e\u0442\u0430, \u0433\u043b\u0443\u0431\u0438\u043d\u0430, \u0432\u0440\u0435\u043c\u044f) \u0438 \u0441\u0442\u0440\u043e\u0438\u0442\u044c retention \u043f\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u00ab\u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e\u043a\u00bb<\/strong>: \u0437\u0430\u0434\u0430\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u043f\u0435\u0440\u0432\u044b\u0435 N \u0434\u043d\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 core-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0410\u043d\u0430\u043b\u0438\u0437 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432<\/strong>: \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c retention \u043f\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430\u043c, \u043b\u0430\u0439\u043a\u0430\u043c, \u043f\u0443\u0448-\u043a\u0430\u043c\u0443 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440: \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f recurring-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 agg = events.groupby('user_id').agg({     'event_timestamp': ['min', 'max', 'count'] }) agg.columns = ['first', 'last', 'count'] agg['lifetime_days'] = (agg['last'] - agg['first']).dt.days recurring = agg[(agg['count'] &gt; 5) &amp; (agg['lifetime_days'] &gt; 7)].index recurring_events = events[events['user_id'].isin(recurring)] # \u0421\u0442\u0440\u043e\u0438\u043c retention \u043f\u043e recurring_events \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443<\/code><\/pre>\n<h3>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438: rolling retention, bracketed retention<\/h3>\n<h4>Rolling retention<\/h4>\n<p>\u0418\u0434\u0435\u044f: \u043d\u0435 \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043d\u0430 7-\u0439\u00bb, \u0430 \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u0439 \u0434\u0435\u043d\u044c \u2265 D7\u00bb.<\/p>\n<pre><code class=\"python\"># Rolling retention: \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u0433\u043e\u0440\u0442\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u043e\u043b\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, # \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0430 Day &gt;= 7 rolling = retention[retention['day_offset'] &gt;= 7].groupby('cohort_date').apply(     lambda df: df.sort_values('day_offset', ascending=False).iloc[0] ) rolling = rolling[['retention_rate']].rename(columns={'retention_rate': 'rolling_retention@7+'}) print(rolling)<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0443\u0437\u043d\u0430\u0451\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u044e\u0434\u0435\u0439 \u00ab\u0434\u043e\u0438\u0433\u0440\u0430\u043b\u043e\u00bb \u0434\u043e D7, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u0438\u0437\u0438\u0442\u0430 \u043d\u0430 7-\u0439 \u0434\u0435\u043d\u044c.<\/p>\n<h4>Bracketed retention<\/h4>\n<p>\u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c timeline \u043d\u0430 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0438: [Day0\u20133], [Day4\u20137], [Day8\u201314] \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u043c retention \u0432 \u043a\u0430\u0436\u0434\u043e\u043c.<\/p>\n<pre><code class=\"python\">bins = [0, 3, 7, 14, 30, 60] labels = ['0-3', '4-7', '8-14', '15-30', '31-60'] retention['bracket'] = pd.cut(retention['day_offset'], bins, labels=labels, right=True) bracketed = (     retention.groupby(['cohort_date', 'bracket'])     .agg({'user_id': 'sum', 'cohort_size': 'first'})     .assign(retention_rate=lambda x: x['user_id'] \/ x['cohort_size'])     .reset_index() ) print(bracketed.head())<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u043c \u00ab\u043e\u043a\u043d\u0435\u00bb \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f.<\/p>\n<h3>\u0421\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 3 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043d\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435<\/h3>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 <strong>\u0444\u0438\u043d\u0442\u0435\u0445-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0431\u044b\u0442\u0438\u044f: login, balance_view, payment<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0438\u043e\u0434 \u0430\u043d\u0430\u043b\u0438\u0437\u0430: \u043c\u0430\u0440\u0442 2025<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439: 10 000<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0440\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0430:<\/p>\n<ol>\n<li>\n<p><strong>D7 naive<\/strong>: \u0440\u043e\u0432\u043d\u043e \u043d\u0430 Day7.<\/p>\n<\/li>\n<li>\n<p><strong>Rolling retention@7+<\/strong>: \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u043f\u043e\u0441\u043b\u0435 Day7.<\/p>\n<\/li>\n<li>\n<p><strong>Bracketed retention<\/strong>: \u0432 \u043e\u043a\u043d\u0435 [4\u20137].<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u0414\u0430\u043d\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u043c \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 import numpy as np  np.random.seed(42) user_ids = np.arange(1, 10001) # \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0434\u0430\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0442 1 \u0434\u043e 20 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 30 \u0434\u043d\u0435\u0439 \u043f\u043e\u0441\u043b\u0435 D0 records = [] for uid in user_ids:     n = np.random.poisson(3)     days = np.random.choice(range(0, 31), size=n, replace=True)     for d in days:         records.append({'user_id': uid, 'event_timestamp': pd.Timestamp('2025-03-01') + pd.Timedelta(days=int(d))}) events = pd.DataFrame(records) events['cohort_date'] = events.groupby('user_id')['event_timestamp'].transform('min') events['day_offset'] = (events['event_timestamp'] - events['cohort_date']).dt.days cohort_size = events.groupby('cohort_date')['user_id'].nunique().iloc[0]  # ~10000  # 1) D7 naive   d7 = events[events['day_offset'] == 7]['user_id'].nunique() \/ cohort_size  # 2) Rolling 7+   rolling7 = events[events['day_offset'] &gt;= 7]['user_id'].nunique() \/ cohort_size  # 3) Bracketed 4\u20137   b4_7 = events[(events['day_offset'] &gt;= 4) &amp; (events['day_offset'] &lt;= 7)]['user_id'].nunique() \/ cohort_size  print(f\"D7 naive: {d7:.2%}\") print(f\"Rolling@7+: {rolling7:.2%}\") print(f\"Bracketed 4\u20137: {b4_7:.2%}\")<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><strong>D7 naive<\/strong>: 8.5%<\/p>\n<\/li>\n<li>\n<p><strong>Rolling@7+<\/strong>: 22.3%<\/p>\n<\/li>\n<li>\n<p><strong>Bracketed 4\u20137<\/strong>: 18.7%<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u043e\u0432\u043d\u043e \u043d\u0430 7-\u0439 \u0434\u0435\u043d\u044c \u2014 \u0432\u0438\u0434\u0438\u043c 8,5%. \u0410 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u043c \u043d\u0430\u0441 \u043e\u043a\u043d\u0435 [4\u20137] \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430. Rolling retention \u0434\u0430\u0451\u0442 \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<ol>\n<li>\n<p>\u0423\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u043a\u0440\u0438\u0432\u0430\u044f, \u0430 \u043d\u0435 \u0442\u043e\u0447\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0442\u0440\u043e\u0438\u043c retention-\u043c\u0430\u0442\u0440\u0438\u0446\u044b<\/strong> \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b. \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0437\u0431\u0435\u0440\u0438 recurring vs one-shot<\/strong>: \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 rolling &amp; bracketed metrics<\/strong> \u0434\u043b\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>\u0410\/\u0411 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0439 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/strong> \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e \u043a\u0440\u0438\u0432\u044b\u043c, \u0430 \u043d\u0435 \u043f\u043e \u00ab\u0447\u0435\u0440\u0435\u0437\u20097\u2009\u0434\u043d\u0435\u0439\u00bb.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f, \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043d\u0430\u0432\u044b\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0442\u043e\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0443\u0440\u043e\u043a\u0430\u0445. \u0418\u0437\u0443\u0447\u0438\u0442\u0435 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0443 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439.<\/p>\n<ul>\n<li>\n<p>12 \u043c\u0430\u044f 20:00 \u2014 \u0420\u0430\u043d\u0436\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u0432 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445. <a href=\"https:\/\/otus.pw\/R7EP\/\">\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>13 \u043c\u0430\u044f 18:00 \u2014 \u041f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439. <a href=\"https:\/\/otus.pw\/YfzQ\/\">\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>21 \u043c\u0430\u044f 20:00 \u2014 \u0412\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445. <a href=\"https:\/\/otus.pw\/usXe\/\">\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p><em>\u0411\u043e\u043b\u044c\u0448\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0432\u044b\u043a\u043e\u0432 \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <\/em><a href=\"https:\/\/otus.pw\/WHC4\/\"><em>\u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432<\/em><\/a><em> \u043e\u0442 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432 \u043e\u0442\u0440\u0430\u0441\u043b\u0438.<\/em><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/905068\/\"> https:\/\/habr.com\/ru\/articles\/905068\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e \u0440\u0435\u0442\u0435\u043d\u0448\u043d \u2014 \u0442\u0443 \u0441\u0430\u043c\u0443\u044e \u043c\u0435\u0442\u0440\u0438\u043a\u0443, \u043e\u0442 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u043e \u043f\u043b\u044f\u0448\u0443\u0442 \u0432\u0441\u0435 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u0412\u044b \u0437\u043d\u0430\u0435\u0442\u0435: \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0447\u0435\u0440\u0435\u0437 7 \u0434\u043d\u0435\u0439\u00bb (D7) \u2014 \u0438 \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043a\u043b\u0430\u0441\u0441<\/p>\n<p>\u041d\u043e \u043d\u0430 \u0434\u0435\u043b\u0435 \u043a\u043b\u0430\u0441\u0441 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043f\u043e\u0447\u0435\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 D7 retention \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u043a\u0440\u0438\u0432\u044b\u0435 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b, \u0432 \u0447\u0451\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043c\u0435\u0436\u0434\u0443 recurring vs one-shot \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c \u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435. <\/p>\n<h3>\u0413\u0434\u0435 \u043b\u043e\u043c\u0430\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 D7 Retention<\/h3>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434:<\/p>\n<ol>\n<li>\n<p>\u0411\u0435\u0440\u0451\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0432\u0448\u0438\u0445\u0441\u044f \u0432 \u0434\u0435\u043d\u044c D0.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043d\u0438\u0445 \u0432\u0435\u0440\u043d\u0443\u043b\u043e\u0441\u044c \u0440\u043e\u0432\u043d\u043e \u043d\u0430 D7.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u00abD7 retention = \u0432\u0435\u0440\u043d\u0443\u043b\u0438\u0441\u044c \/ \u0432\u0441\u0435\u0433\u043e D0\u00bb.<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0443 \u0432\u0430\u0441 \u00ad\u2026<\/p>\n<ul>\n<li>\n<p><strong>\u0414\u0435\u0439\u043b\u0438-\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a<\/strong>: \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044e\u0437\u0435\u0440\u044b \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u043d\u0430\u20091-\u0439, \u043d\u0430\u20093-\u0439, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0435\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0434\u0443\u043a\u0442<\/strong>: \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u0438\u043a, \u0432\u0435\u0431, \u0434\u0435\u0441\u043a\u0442\u043e\u043f \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0440\u0430\u0437\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0437\u043e\u0432\u0430\u044f \u0430\u043a\u0446\u0438\u044f<\/strong>: \u043a\u0442\u043e-\u0442\u043e \u0437\u0430\u043b\u043e\u0433\u0438\u043d\u0438\u043b\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 7-\u0439 \u0434\u0435\u043d\u044c \u0438\u0437-\u0437\u0430 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438, \u043d\u043e \u043f\u043e\u0442\u043e\u043c \u0438\u0441\u0447\u0435\u0437 \u043d\u0430\u0432\u0441\u0435\u0433\u0434\u0430.<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0441\u0451 \u044d\u0442\u043e \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442 D7 \u0432 \u043b\u043e\u0442\u0435\u0440\u0435\u044e: \u043a\u0442\u043e-\u0442\u043e \u043f\u043e\u043f\u0430\u043b \u043f\u043e\u0434 \u0433\u043e\u0440\u044f\u0447\u0443\u044e \u0440\u0443\u043a\u0443, \u0430 \u043a\u0442\u043e-\u0442\u043e \u043d\u0435\u0442. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u043c\u0435\u0448\u0430\u043d\u0438\u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0410 \u0432\u0435\u0434\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c, \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u044f \u0432\u043e\u043e\u0431\u0449\u0435, \u0438\u043b\u0438 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0448\u0443\u043c.<\/p>\n<h3>\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 true retention curves \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h3>\n<p>\u041a\u043e\u0433\u043e\u0440\u0442\u044b \u2014 \u043d\u0430\u0448\u0435 \u0432\u0441\u0451. \u0412\u043c\u0435\u0441\u0442\u043e \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043d\u0430 D7\u00bb \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443:<\/p>\n<ul>\n<li>\n<p><strong>\u0441\u0442\u0440\u043e\u043a\u0438<\/strong> \u2014 \u043a\u043e\u0433\u043e\u0440\u0442\u044b \u043f\u043e \u0434\u0430\u0442\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u0438\u043b\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438) D0, D1, \u2026<\/p>\n<\/li>\n<li>\n<p><strong>\u0441\u0442\u043e\u043b\u0431\u0446\u044b<\/strong> \u2014 \u0434\u043d\u0438 \u043f\u043e\u0441\u043b\u0435 D0: Day0, Day1, Day2, \u2026 DayN<\/p>\n<\/li>\n<li>\n<p><strong>\u044f\u0447\u0435\u0439\u043a\u0438<\/strong> \u2014 \u0434\u043e\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b, \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u0432\u0448\u0438\u0445 \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u043d\u044c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430 Python + pandas \u043e\u0447\u0435\u043d\u044c \u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<pre><code class=\"python\">import pandas as pd # \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0435\u0441\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0430 events \u0441 \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c\u0438 user_id \u0438 event_timestamp events = pd.read_csv('events.csv', parse_dates=['event_timestamp']) events['cohort_date'] = events.groupby('user_id')['event_timestamp'].transform('min').dt.normalize() events['day_offset'] = (events['event_timestamp'].dt.normalize() - events['cohort_date']).dt.days  # \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0433\u043e\u0440\u0442\u044b cohort_counts = (     events.drop_duplicates(['user_id', 'day_offset'])     .groupby(['cohort_date', 'day_offset'])     .agg({'user_id': 'nunique'})     .reset_index() )  # \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0435\u0433\u043e \u0432 \u043a\u043e\u0433\u043e\u0440\u0442\u0435 cohort_sizes = (     events.groupby('cohort_date')     .agg({'user_id': 'nunique'})     .rename(columns={'user_id': 'cohort_size'})     .reset_index() )  # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c retention = cohort_counts.merge(cohort_sizes, on='cohort_date') retention['retention_rate'] = retention['user_id'] \/ retention['cohort_size'] # Pivot \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430 retention_pivot = retention.pivot(index='cohort_date', columns='day_offset', values='retention_rate') print(retention_pivot.head())<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0442\u0438\u043f\u0430:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">cohort_date<\/p>\n<\/th>\n<th>\n<p align=\"left\">0<\/p>\n<\/th>\n<th>\n<p align=\"left\">1<\/p>\n<\/th>\n<th>\n<p align=\"left\">2<\/p>\n<\/th>\n<th>\n<p align=\"left\">3<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u2026<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2025-04-01<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.0<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.45<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.30<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.25<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">2025-04-02<\/p>\n<\/td>\n<td>\n<p align=\"left\">1.0<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.50<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.28<\/p>\n<\/td>\n<td>\n<p align=\"left\">0.22<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2026<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0422\u0443\u0442 \u0432\u0438\u0434\u043d\u043e, \u043a\u0430\u043a \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043f\u0430\u0434\u0430\u0435\u0442 \u0434\u0435\u043d\u044c \u0437\u0430 \u0434\u043d\u0451\u043c. <\/p>\n<h3>recurring behavior vs one-shot behavior<\/h3>\n<ul>\n<li>\n<p><strong>One-shot behavior<\/strong>: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0448\u0451\u043b \u0435\u0434\u0438\u043d\u043e\u0436\u0434\u044b, \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u043e\u043a\u0443\u043f\u043a\u0443\/\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0438 \u043f\u0440\u043e\u043f\u0430\u043b.<\/p>\n<\/li>\n<li>\n<p><strong>Recurring behavior<\/strong>: \u044e\u0437\u0435\u0440 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0432\u0430\u0448\u0435\u043c\u0443 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0443: \u0447\u0442\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0435\u0439, \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447, \u0430\u043f\u0433\u0440\u0435\u0439\u0434 \u0441\u0442\u0430\u0442\u0443\u0441\u0430\u2026<\/p>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u0438\u0445, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b:<\/p>\n<ul>\n<li>\n<p>One-shot \u044e\u0437\u0435\u0440\u044b \u0434\u0430\u044e\u0442 retention \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0435\u0440\u0432\u044b\u0445 \u0434\u043d\u044f\u0445 (Day0, Day1), \u0430 \u043f\u043e\u0442\u043e\u043c \u00ab\u0448\u0443\u043c\u0438\u0445\u0430\u00bb \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>Recurring \u044e\u0437\u0435\u0440\u044b \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e\u0442 long tail: retention \u043c\u043e\u0436\u0435\u0442 \u00ab\u0445\u0432\u043e\u0441\u0442\u0438\u043a\u043e\u043c\u00bb \u0442\u044f\u043d\u0443\u0442\u044c\u0441\u044f \u043d\u0430 \u043d\u0435\u0434\u0435\u043b\u044e, \u043c\u0435\u0441\u044f\u0446, \u0433\u043e\u0434.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u044d\u0442\u043e \u0443\u0447\u0435\u0441\u0442\u044c?<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/strong>: K-means\/DBSCAN \u043f\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044e (\u0447\u0430\u0441\u0442\u043e\u0442\u0430, \u0433\u043b\u0443\u0431\u0438\u043d\u0430, \u0432\u0440\u0435\u043c\u044f) \u0438 \u0441\u0442\u0440\u043e\u0438\u0442\u044c retention \u043f\u043e \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0430\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0424\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u00ab\u043e\u0434\u043d\u043e\u0440\u0430\u0437\u043e\u0432\u043e\u043a\u00bb<\/strong>: \u0437\u0430\u0434\u0430\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0432 \u043f\u0435\u0440\u0432\u044b\u0435 N \u0434\u043d\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 core-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>\u0410\u043d\u0430\u043b\u0438\u0437 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432<\/strong>: \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c retention \u043f\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430\u043c, \u043b\u0430\u0439\u043a\u0430\u043c, \u043f\u0443\u0448-\u043a\u0430\u043c\u0443 \u0438 \u0442.\u0434.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440: \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f recurring-\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 agg = events.groupby('user_id').agg({     'event_timestamp': ['min', 'max', 'count'] }) agg.columns = ['first', 'last', 'count'] agg['lifetime_days'] = (agg['last'] - agg['first']).dt.days recurring = agg[(agg['count'] &gt; 5) &amp; (agg['lifetime_days'] &gt; 7)].index recurring_events = events[events['user_id'].isin(recurring)] # \u0421\u0442\u0440\u043e\u0438\u043c retention \u043f\u043e recurring_events \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443<\/code><\/pre>\n<h3>\u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438: rolling retention, bracketed retention<\/h3>\n<h4>Rolling retention<\/h4>\n<p>\u0418\u0434\u0435\u044f: \u043d\u0435 \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043d\u0430 7-\u0439\u00bb, \u0430 \u00ab\u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u0439 \u0434\u0435\u043d\u044c \u2265 D7\u00bb.<\/p>\n<pre><code class=\"python\"># Rolling retention: \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u0433\u043e\u0440\u0442\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u043e\u043b\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, # \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0432\u0435\u0440\u0448\u0438\u043b\u0438 \u0445\u043e\u0442\u044c \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0430 Day &gt;= 7 rolling = retention[retention['day_offset'] &gt;= 7].groupby('cohort_date').apply(     lambda df: df.sort_values('day_offset', ascending=False).iloc[0] ) rolling = rolling[['retention_rate']].rename(columns={'retention_rate': 'rolling_retention@7+'}) print(rolling)<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0443\u0437\u043d\u0430\u0451\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u044e\u0434\u0435\u0439 \u00ab\u0434\u043e\u0438\u0433\u0440\u0430\u043b\u043e\u00bb \u0434\u043e D7, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u0438\u0437\u0438\u0442\u0430 \u043d\u0430 7-\u0439 \u0434\u0435\u043d\u044c.<\/p>\n<h4>Bracketed retention<\/h4>\n<p>\u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c timeline \u043d\u0430 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043a\u0438: [Day0\u20133], [Day4\u20137], [Day8\u201314] \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u043c retention \u0432 \u043a\u0430\u0436\u0434\u043e\u043c.<\/p>\n<pre><code class=\"python\">bins = [0, 3, 7, 14, 30, 60] labels = ['0-3', '4-7', '8-14', '15-30', '31-60'] retention['bracket'] = pd.cut(retention['day_offset'], bins, labels=labels, right=True) bracketed = (     retention.groupby(['cohort_date', 'bracket'])     .agg({'user_id': 'sum', 'cohort_size': 'first'})     .assign(retention_rate=lambda x: x['user_id'] \/ x['cohort_size'])     .reset_index() ) print(bracketed.head())<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u043a\u0430\u043a\u043e\u043c \u00ab\u043e\u043a\u043d\u0435\u00bb \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f.<\/p>\n<h3>\u0421\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 3 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043d\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0435<\/h3>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 <strong>\u0444\u0438\u043d\u0442\u0435\u0445-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0431\u044b\u0442\u0438\u044f: login, balance_view, payment<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0438\u043e\u0434 \u0430\u043d\u0430\u043b\u0438\u0437\u0430: \u043c\u0430\u0440\u0442 2025<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439: 10 000<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0440\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0430:<\/p>\n<ol>\n<li>\n<p><strong>D7 naive<\/strong>: \u0440\u043e\u0432\u043d\u043e \u043d\u0430 Day7.<\/p>\n<\/li>\n<li>\n<p><strong>Rolling retention@7+<\/strong>: \u0432\u0435\u0440\u043d\u0443\u043b\u0441\u044f \u0445\u043e\u0442\u044c \u0440\u0430\u0437 \u043f\u043e\u0441\u043b\u0435 Day7.<\/p>\n<\/li>\n<li>\n<p><strong>Bracketed retention<\/strong>: \u0432 \u043e\u043a\u043d\u0435 [4\u20137].<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u0414\u0430\u043d\u043d\u044b\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u043c \u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 import numpy as np  np.random.seed(42) user_ids = np.arange(1, 10001) # \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0434\u0430\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0442 1 \u0434\u043e 20 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 30 \u0434\u043d\u0435\u0439 \u043f\u043e\u0441\u043b\u0435 D0 records = [] for uid in user_ids:     n = np.random.poisson(3)     days = np.random.choice(range(0, 31), size=n, replace=True)     for d in days:         records.append({'user_id': uid, 'event_timestamp': pd.Timestamp('2025-03-01') + pd.Timedelta(days=int(d))}) events = pd.DataFrame(records) events['cohort_date'] = events.groupby('user_id')['event_timestamp'].transform('min') events['day_offset'] = (events['event_timestamp'] - events['cohort_date']).dt.days cohort_size = events.groupby('cohort_date')['user_id'].nunique().iloc[0]  # ~10000  # 1) D7 naive   d7 = events[events['day_offset'] == 7]['user_id'].nunique() \/ cohort_size  # 2) Rolling 7+   rolling7 = events[events['day_offset'] &gt;= 7]['user_id'].nunique() \/ cohort_size  # 3) Bracketed 4\u20137   b4_7 = events[(events['day_offset'] &gt;= 4) &amp; (events['day_offset'] &lt;= 7)]['user_id'].nunique() \/ cohort_size  print(f\"D7 naive: {d7:.2%}\") print(f\"Rolling@7+: {rolling7:.2%}\") print(f\"Bracketed 4\u20137: {b4_7:.2%}\")<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/p>\n<ul>\n<li>\n<p><strong>D7 naive<\/strong>: 8.5%<\/p>\n<\/li>\n<li>\n<p><strong>Rolling@7+<\/strong>: 22.3%<\/p>\n<\/li>\n<li>\n<p><strong>Bracketed 4\u20137<\/strong>: 18.7%<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u043e\u0432\u043d\u043e \u043d\u0430 7-\u0439 \u0434\u0435\u043d\u044c \u2014 \u0432\u0438\u0434\u0438\u043c 8,5%. \u0410 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u043c \u043d\u0430\u0441 \u043e\u043a\u043d\u0435 [4\u20137] \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430. Rolling retention \u0434\u0430\u0451\u0442 \u0435\u0449\u0451 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443.<\/p>\n<h3>\u0418\u0442\u043e\u0433\u0438<\/h3>\n<ol>\n<li>\n<p>\u0423\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u043a\u0440\u0438\u0432\u0430\u044f, \u0430 \u043d\u0435 \u0442\u043e\u0447\u043a\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>\u0421\u0442\u0440\u043e\u0438\u043c retention-\u043c\u0430\u0442\u0440\u0438\u0446\u044b<\/strong> \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0433\u043e\u0440\u0442\u044b. \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0437\u0431\u0435\u0440\u0438 recurring vs one-shot<\/strong>: \u0441\u0435\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 rolling &amp; bracketed metrics<\/strong> \u0434\u043b\u044f \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<li>\n<p><strong>\u0410\/\u0411 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0439 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/strong> \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e \u043a\u0440\u0438\u0432\u044b\u043c, \u0430 \u043d\u0435 \u043f\u043e \u00ab\u0447\u0435\u0440\u0435\u0437\u20097\u2009\u0434\u043d\u0435\u0439\u00bb.<\/p>\n<\/li>\n<\/ol>\n<hr\/>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c\u0441\u044f \u0432 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f, \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043d\u0430\u0432\u044b\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u0442\u043e\u0447\u0438\u0442\u044c \u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0443\u0440\u043e\u043a\u0430\u0445. \u0418\u0437\u0443\u0447\u0438\u0442\u0435 \u043d\u043e\u0432\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0434\u0443\u043a\u0442 \u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0443 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439.<\/p>\n<ul>\n<li>\n<p>12 \u043c\u0430\u044f 20:00 \u2014 \u0420\u0430\u043d\u0436\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u0432 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445. <a href=\"https:\/\/otus.pw\/R7EP\/\">\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>13 \u043c\u0430\u044f 18:00 \u2014 \u041f\u0440\u0438\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0438\u0441\u043a\u0430 \u0430\u043d\u043e\u043c\u0430\u043b\u0438\u0439. <a href=\"https:\/\/otus.pw\/YfzQ\/\">\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n<\/li>\n<li>\n<p>21 \u043c\u0430\u044f 20:00 \u2014 \u0412\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432 \u0431\u0438\u0437\u043d\u0435\u0441-\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445. <a href=\"https:\/\/otus.pw\/usXe\/\">\u0423\u0437\u043d\u0430\u0442\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p><em>\u0411\u043e\u043b\u044c\u0448\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0432\u044b\u043a\u043e\u0432 \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <\/em><a href=\"https:\/\/otus.pw\/WHC4\/\"><em>\u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432<\/em><\/a><em> \u043e\u0442 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u043e\u0432 \u043e\u0442\u0440\u0430\u0441\u043b\u0438.<\/em><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/905068\/\"> https:\/\/habr.com\/ru\/articles\/905068\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-458732","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=458732"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458732\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=458732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=458732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=458732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}