{"id":344059,"date":"2023-01-17T09:04:04","date_gmt":"2023-01-17T09:04:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=344059"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=344059","title":{"rendered":"<span>ML-\u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430 30 \u043c\u0438\u043d\u0443\u0442: \u0433\u0430\u0434\u0430\u0435\u043c \u043f\u043e cookie<\/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>\u00ab\u042f \u0442\u0435\u0431\u044f \u043f\u043e IP \u0432\u044b\u0447\u0438\u0441\u043b\u044e!\u00bb \u2013 \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0442\u0430\u043a\u0443\u044e \u0443\u0433\u0440\u043e\u0437\u0443 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u0440\u0435\u043c\u0435\u043d \u043d\u0443\u043b\u0435\u0432\u044b\u0445 \u0433\u043e\u0434\u043e\u0432? \u041c\u044b \u0432 <a href=\"https:\/\/career.habr.com\/companies\/mts\/vacancies\">Big Data \u041c\u0422\u0421<\/a> \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0435, \u043e\u0431\u043b\u0430\u0434\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0441\u0430\u0439\u0442\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043f\u043e\u0441\u0435\u0449\u0430\u0435\u0442. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u043e\u043b\u0443\u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043c\u0435\u043b\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u044d\u0442\u0438\u0445 \u0432\u0430\u0448\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/6ad\/35f\/7e8\/6ad35f7e83e874f1668cf9e181c4ad59.jpg\" width=\"1920\" height=\"1080\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6ad\/35f\/7e8\/6ad35f7e83e874f1668cf9e181c4ad59.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u043d\u044b\u0445 \u0441\u0430\u0439\u0442\u0430\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0435 \u043f\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u044b\u0447\u0443, \u0430 \u043f\u043e \u043e\u0431\u0435\u0437\u043b\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 cookie, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043e\u0431\u043c\u0435\u043d\u0435 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u043c\u0438 DSP- \u0438 SSP- \u043f\u043b\u043e\u0449\u0430\u0434\u043a\u0430\u043c\u0438. <\/p>\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 \u0437\u0432\u0443\u0447\u0438\u0442 \u0442\u0430\u043a: \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043f\u043e \u0446\u0438\u0444\u0440\u043e\u0432\u044b\u043c \u0441\u043b\u0435\u0434\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043d\u0430 \u043a\u0430\u043a\u0438\u0445 \u0441\u0430\u0439\u0442\u0430\u0445 \u0441 \u043a\u0430\u043a\u0438\u0445 IP \u043e\u043d \u0441\u0438\u0434\u0435\u043b, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0437\u0430\u0445\u043e\u0434\u0438\u043b, \u043a\u0430\u043a\u043e\u0435 \u0443 \u043d\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e) \u043f\u043e\u043d\u044f\u0442\u044c, <strong>\u043a\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c?<\/strong> \u0421\u0442\u0443\u0434\u0435\u043d\u0442 \u0438\u043b\u0438 \u043f\u0435\u043d\u0441\u0438\u043e\u043d\u0435\u0440? \u041c\u0443\u0436\u0447\u0438\u043d\u0430 \u0438\u043b\u0438 \u0436\u0435\u043d\u0449\u0438\u043d\u0430? \u041a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c?<\/p>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0432 Digital-\u0440\u0435\u043a\u043b\u0430\u043c\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0447\u0430\u0441\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u043e\u043b \u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0431\u0430\u043a\u0435\u0442\u043e\u0432 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443 (&lt;18, 18-24, 25-34, 35-44, 45-54, 55-64, 65+). \u042d\u0442\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430 \u0434\u043b\u044f \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u0445 DSP-\u043f\u043b\u043e\u0449\u0430\u0434\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 OpenRTB \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 200 000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0441\u043e \u0432\u0441\u0435\u0445 \u0441\u0430\u0439\u0442\u043e\u0432, \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0449\u0438\u0445 \u0440\u0435\u043a\u043b\u0430\u043c\u0443 \u0437\u0430 \u0434\u0435\u043d\u044c\u0433\u0438. <\/p>\n<p>\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0438 \u0432\u0430\u0441 <strong>\u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0440\u0442\u0440\u0435\u0442<\/strong> \u0440\u044f\u0434\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <s>\u0425\u0430\u0431\u0440\u0430<\/s> \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u043f\u043e\u0447\u0442\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u043d\u044b\u043c \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u2013 \u043d\u0430\u0448 baseline \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u2013 \u0431\u0435\u0437 \u043a\u0440\u043e\u0441\u0441-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, feature engineering \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0445 \u0441\u0435\u0440\u0434\u0446\u0443 \u0432\u0435\u0449\u0435\u0439. \u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u0440\u043e \u043f\u043e \u0434\u043e\u0440\u043e\u0433\u0435 \u043e\u0442 \u0420\u0435\u0447\u043d\u043e\u0433\u043e \u0432\u043e\u043a\u0437\u0430\u043b\u0430 \u0434\u043e \u0422\u0435\u0445\u043d\u043e\u043f\u0430\u0440\u043a\u0430 (\u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0444\u0438\u0441 \u041c\u0422\u0421 Digital). \u042d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u0437\u0430\u0439\u043c\u0435\u0442 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 30 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/5ad\/861\/6bd\/5ad8616bd2b480d4c26d0514a76102ad.jpg\" width=\"1280\" height=\"139\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5ad\/861\/6bd\/5ad8616bd2b480d4c26d0514a76102ad.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u0417\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0432\u0441\u0435\u043c DS-\u0438\u043a\u043e\u043d\u043e\u0441\u0442\u0430\u0441<\/h3>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u0435 \u043d\u0443\u0436\u043d\u043e\u0435 =) (\u043d\u0443 \u043f\u043e\u0447\u0442\u0438).<\/p>\n<pre><code class=\"python\">import sys import os import warnings os.environ['OPENBLAS_NUM_THREADS'] = '1' warnings.filterwarnings('ignore')<\/code><\/pre>\n<pre><code class=\"python\">import pandas as pd import numpy as np import time import pyarrow.parquet as pq import scipy import implicit import bisect import sklearn.metrics as m from catboost import CatBoostClassifier, CatBoostRegressor, Pool from sklearn.model_selection import train_test_split from sklearn.calibration import calibration_curve, CalibratedClassifierCV<\/code><\/pre>\n<pre><code class=\"python\">LOCAL_DATA_PATH = '.\/context_data\/' SPLIT_SEED = 42 DATA_FILE = 'competition_data_final_pqt' TARGET_FILE = 'competition_target_pqt'<\/code><\/pre>\n<h4>\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u044b<\/h4>\n<pre><code class=\"python\">data = pq.read_table(f'{LOCAL_DATA_PATH}\/{DATA_FILE}') pd.DataFrame([(z.name, z.type) for z in data.schema], \\              columns = [['field', 'type']])<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/926\/da9\/0b1\/926da90b12428fa227c422344f6b209f.png\" width=\"1476\" height=\"714\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/926\/da9\/0b1\/926da90b12428fa227c422344f6b209f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u044b\u0448\u0435:<\/p>\n<ul>\n<li>\n<p>\u0440\u0435\u0433\u0438\u043e\u043d;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0430\u0441\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0443\u043d\u043a\u0442;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430;<\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043c\u0435\u043d, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u0448\u0435\u043b \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0438\u043f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (\u0441\u043c\u0430\u0440\u0442\u0444\u043e\u043d \u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435);<\/p>\n<\/li>\n<li>\n<p>\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043a\u0430 \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0446\u0435\u043d\u043a\u0430 \u0446\u0435\u043d\u044b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0434\u0430\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u044f \u0434\u043d\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0434\u043e\u043c\u0435\u043d\u0443 \u0432 \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u0434\u043d\u044f \u0432 \u044d\u0442\u0443 \u0434\u0430\u0442\u0443;<\/p>\n<\/li>\n<li>\n<p>id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">data.select(['cpe_type_cd']).to_pandas()['cpe_type_cd'].value_counts()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/310\/08d\/335\/31008d3353d9a739f708b7546c454d8e.png\" alt=\"\" title=\"\" width=\"1178\" height=\"180\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/310\/08d\/335\/31008d3353d9a739f708b7546c454d8e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0441\u0435\u0431\u044f \u043e\u0442\u043a\u0440\u044b\u043b \u0441\u043b\u043e\u0432\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A4%D0%B0%D0%B1%D0%BB%D0%B5%D1%82\">\u0444\u0430\u0431\u043b\u0435\u0442<\/a>.<\/p>\n<pre><code class=\"python\">targets = pq.read_table(f'{LOCAL_DATA_PATH}\/{TARGET_FILE}') pd.DataFrame([(z.name, z.type) for z in targets.schema], \\              columns = [['field', 'type']])<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/cfd\/77b\/b23\/cfd77bb23fa9613d32f7db00b284fae0.png\" alt=\"\u043d\u0443 \u0442\u0443\u0442 \u0432\u0441\u0435 \u044f\u0441\u043d\u043e\" title=\"\u043d\u0443 \u0442\u0443\u0442 \u0432\u0441\u0435 \u044f\u0441\u043d\u043e\" width=\"1216\" height=\"214\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cfd\/77b\/b23\/cfd77bb23fa9613d32f7db00b284fae0.png\"\/><figcaption>\u043d\u0443 \u0442\u0443\u0442 \u0432\u0441\u0435 \u044f\u0441\u043d\u043e<\/figcaption><\/figure>\n<h3>\u041e\u043a, \u043d\u0430\u043c \u043b\u0435\u043d\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0442\u044c \u0444\u0438\u0447\u0438<\/h3>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443, \u043a\u0430\u043a \u043d\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443: \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0443\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 Users \u0438 Items (\u043f\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b) \u2013 \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433, \u0434\u0430 \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u043d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u0447\u0442\u0438 \u043d\u0430 \u0411\u0435\u043b\u043e\u0440\u0443\u0441\u0441\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/98b\/d56\/5a3\/98bd565a3256809c906006eb888b8c14.jpg\" width=\"1280\" height=\"139\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/98b\/d56\/5a3\/98bd565a3256809c906006eb888b8c14.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">%%time data_agg = data.select(['user_id', 'url_host', 'request_cnt']).\\     group_by(['user_id', 'url_host']).aggregate([('request_cnt', \"sum\")])<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1c2\/b89\/ae9\/1c2b89ae9cab9ba2850f5adeb184ce37.png\" width=\"1250\" height=\"80\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1c2\/b89\/ae9\/1c2b89ae9cab9ba2850f5adeb184ce37.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">url_set = set(data_agg.select(['url_host']).to_pandas()['url_host']) print(f'{len(url_set)} urls') url_dict = {url: idurl for url, idurl in zip(url_set, range(len(url_set)))} usr_set = set(data_agg.select(['user_id']).to_pandas()['user_id']) print(f'{len(usr_set)} users') usr_dict = {usr: user_id for usr, user_id in zip(usr_set, range(len(usr_set)))}<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/169\/6f6\/e06\/1696f6e066945a9e2577b58e95e3dbb8.png\" alt=\"\u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432\u044b\u0439\u0434\u0435\u0442\" title=\"\u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432\u044b\u0439\u0434\u0435\u0442\" width=\"1192\" height=\"84\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/169\/6f6\/e06\/1696f6e066945a9e2577b58e95e3dbb8.png\"\/><figcaption>\u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432\u044b\u0439\u0434\u0435\u0442<\/figcaption><\/figure>\n<pre><code class=\"python\">%%time values = np.array(data_agg.select(['request_cnt_sum']).to_pandas()['request_cnt_sum']) rows = np.array(data_agg.select(['user_id']).to_pandas()['user_id'].map(usr_dict)) cols = np.array(data_agg.select(['url_host']).to_pandas()['url_host'].map(url_dict)) mat = scipy.sparse.coo_matrix((values, (rows, cols)), shape=(rows.max() + 1, cols.max() + 1)) als = implicit.approximate_als.FaissAlternatingLeastSquares(factors = 50, \\       iterations = 30, use_gpu = False, calculate_training_loss = False, regularization = 0.1)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c8c\/aff\/e27\/c8caffe27689ff6024eda3ace23fd5ef.png\" alt=\"\" title=\"\" width=\"1398\" height=\"94\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c8c\/aff\/e27\/c8caffe27689ff6024eda3ace23fd5ef.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">%%time als.fit(mat) u_factors = als.model.user_factors  d_factors = als.model.item_factors<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dfd\/db7\/e43\/dfddb7e4375741a3bff4d36b17fd6bec.png\" alt=\"30 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430 30 \u0441\u0435\u043a -- \u0441\u043f\u0430\u0441\u0438\u0431\u043e FAISS!\" title=\"30 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430 30 \u0441\u0435\u043a -- \u0441\u043f\u0430\u0441\u0438\u0431\u043e FAISS!\" width=\"1382\" height=\"120\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dfd\/db7\/e43\/dfddb7e4375741a3bff4d36b17fd6bec.png\"\/><figcaption>30 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430 30 \u0441\u0435\u043a &#8212; \u0441\u043f\u0430\u0441\u0438\u0431\u043e FAISS!<\/figcaption><\/figure>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0446\u0435\u043d\u043a\u0443 \u043f\u043e \u043f\u043e\u043b\u0443<\/h3>\n<p>\u0420\u0430\u0437 \u0443\u0436 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0435 \u2013 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u043b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044f \u0432\u0441\u0435 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u0438 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u0440\u043e \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0438\u0447\u0438.<\/p>\n<pre><code class=\"python\">%%time inv_usr_map = {v: k for k, v in usr_dict.items()} usr_emb = pd.DataFrame(u_factors) usr_emb['user_id'] = usr_emb.index.map(inv_usr_map) usr_targets = targets.to_pandas() df = usr_targets.merge(usr_emb, how = 'inner', on = ['user_id']) df = df[df['is_male'] != 'NA'] df = df.dropna() df['is_male'] = df['is_male'].map(int) df['is_male'].value_counts()<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/88a\/bdf\/036\/88abdf036571608234f73e83043a2746.png\" width=\"1194\" height=\"164\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/88a\/bdf\/036\/88abdf036571608234f73e83043a2746.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">%%time x_train, x_test, y_train, y_test = train_test_split(\\     df.drop(['user_id', 'age', 'is_male'], axis = 1), df['is_male'], test_size = 0.33, random_state = SPLIT_SEED) clf = CatBoostClassifier() clf.fit(x_train, y_train, verbose = False) print(f'GINI \u043f\u043e \u043f\u043e\u043b\u0443 {2 * m.roc_auc_score(y_test, clf.predict_proba(x_test)[:,1]) - 1:2.3f}')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3bd\/dca\/370\/3bddca3705adc1cee6b2b9c2d39271d7.png\" alt=\"\" title=\"\" width=\"1692\" height=\"112\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3bd\/dca\/370\/3bddca3705adc1cee6b2b9c2d39271d7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0443\u0436 \u043f\u043b\u043e\u0445\u043e! \u041d\u043e \u043c\u044b \u043f\u043e\u0447\u0442\u0438 \u0434\u043e\u0435\u0445\u0430\u043b\u0438 \u0434\u043e \u041f\u0430\u0432\u0435\u043b\u0435\u0446\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/b04\/577\/67d\/b0457767d2f6f316d7484a58b8ec07c1.jpg\" width=\"1280\" height=\"139\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b04\/577\/67d\/b0457767d2f6f316d7484a58b8ec07c1.jpg\" data-blurred=\"true\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0446\u0435\u043d\u043a\u0443 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443<\/h3>\n<pre><code class=\"python\">import seaborn as sns import matplotlib.pyplot as plt import plotly.express as px  %matplotlib inline sns.set_style('darkgrid')<\/code><\/pre>\n<pre><code class=\"python\">def age_bucket(x):     return bisect.bisect_left([18,25,35,45,55,65], x)<\/code><\/pre>\n<pre><code class=\"python\">df = usr_targets.merge(usr_emb, how = 'inner', on = ['user_id']) df = df[df['age'] != 'NA'] df = df.dropna() df['age'] = df['age'].map(age_bucket) sns.histplot(df['age'], bins = 7)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ca1\/322\/588\/ca1322588c4325f15bd755259d60e584.png\" width=\"1230\" height=\"574\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ca1\/322\/588\/ca1322588c4325f15bd755259d60e584.png\"\/><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">x_train, x_test, y_train, y_test = train_test_split(\\     df.drop(['user_id', 'age', 'is_male'], axis = 1), \\     df['age'], test_size = 0.33, random_state = SPLIT_SEED)  clf = CatBoostClassifier() clf.fit(x_train, y_train, verbose = False) print(m.classification_report(y_test, clf.predict(x_test), \\     target_names = ['&lt;18', '18-25','25-34', '35-44', '45-54', '55-65', '65+']))<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d37\/837\/3f7\/d378373f712f4278712afd3e04c3acde.png\" width=\"1608\" height=\"434\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d37\/837\/3f7\/d378373f712f4278712afd3e04c3acde.png\"\/><figcaption><\/figcaption><\/figure>\n<h3>\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u043e\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u0432\u043e\u0437\u0440\u0430\u0441\u0442.<br \/>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0441\u043a\u043e\u0440 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u043e\u0439\u0434\u0443\u0442 Gini \u043f\u043e \u043f\u043e\u043b\u0443 (\u043e\u0442 0 \u0434\u043e 1) \u0438 f1 weighted \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443 \u2013 \u0441 \u0432\u0435\u0441\u043e\u043c \u0434\u0432\u0430:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"score = Gini_{sex} + 2 weighted F1 _{age}\" alt=\"score = Gini_{sex} + 2 weighted F1 _{age}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7fa\/532\/806\/7fa532806f6bbc206802e75123483a73.svg\" width=\"292\" height=\"22\"\/><\/p>\n<h4>\u0418\u0442\u043e\u0433\u043e \u043e\u0431\u0449\u0438\u0439 \u0441\u043a\u043e\u0440: 0.665 + 2 * 0.41 = 1.485<\/h4>\n<p>\u0414\u043b\u044f \u043f\u043e\u0435\u0437\u0434\u043a\u0438 \u043e\u0442 \u0420\u0435\u0447\u043d\u043e\u0433\u043e \u0434\u043e \u0422\u0435\u0445\u043d\u043e\u043f\u0430\u0440\u043a\u0430 \u0442\u0435\u0440\u043f\u0438\u043c\u043e. =) <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435! \u0415\u0441\u043b\u0438 \u0436\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u2013 <strong>\u0436\u0434\u0435\u043c \u0432\u0430\u0441 \u043d\u0430 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f\u0445 \u043f\u043e Machine Learning 30 \u044f\u043d\u0432\u0430\u0440\u044f<\/strong>, \u044d\u0442\u043e \u0442\u0443\u0440\u043d\u0438\u0440 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043f\u043e\u043b\u0430\/\u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 cookie \u043e\u0442 \u041c\u0422\u0421 Digital. \u041f\u0440\u0438\u0437\u043e\u0432\u043e\u0439 \u0444\u043e\u043d\u0434 MTC ML Cup \u2013 <strong>650 000 \u0440\u0443\u0431\u043b\u0435\u0439<\/strong>: \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442 350 000 \u0440\u0443\u0431\u043b\u0435\u0439, \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u0435\u043b\u044c \u0441\u0435\u0440\u0435\u0431\u0440\u0430 \u2013 200 000 \u0440\u0443\u0431\u043b\u0435\u0439, \u0430 \u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0440\u0438\u0437\u0435\u0440 \u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u043e\u0433\u0430\u0447\u0435 \u043d\u0430 100 000 \u0440\u0443\u0431\u043b\u0435\u0439. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0443\u0436\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0430, \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0430\u043d\u043a\u0435\u0442\u0430 \u0434\u043b\u044f \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438 <a href=\"https:\/\/ods.ai\/competitions\/mtsmlcup\">\u0432\u0441\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 <\/a>\u2013 <a href=\"https:\/\/ods.ai\/competitions\/mtsmlcup\">\u043d\u0430 \u0441\u0430\u0439\u0442\u0435<\/a>. \u0423\u0432\u0438\u0434\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u0438!<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/969\/425\/ed3\/969425ed3a85cb98f5e0dfceb42724e2.png\" width=\"1236\" height=\"352\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/969\/425\/ed3\/969425ed3a85cb98f5e0dfceb42724e2.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0443\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f! \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u043b\u0438 \u0436\u0435 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e \u043f\u0430\u0440\u044b \u043f\u0435\u0440\u0435\u0433\u043e\u043d\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0430\u043d\u0446\u0438\u044f\u043c\u0438 \u043c\u0435\u0442\u0440\u043e \u2013 <strong>\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<\/strong><\/p>\n<h3>P.S.<\/h3>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u044b\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430\u043c\u0438 \u0432\u043c\u0435\u0441\u0442\u043e Pandas \u0438 PyArrow:<br \/><a href=\"https:\/\/github.com\/pola-rs\/polars\">Polars<\/a><br \/><a href=\"https:\/\/github.com\/rapidsai\/cudf\">CuDF<\/a><\/p>\n<p>\u0418 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f RecSys:<br \/><a href=\"https:\/\/github.com\/MobileTeleSystems\/RecTools\">MTS RecTools<\/a><br \/><a href=\"https:\/\/making.lyst.com\/lightfm\/docs\/home.html\">LightFM<\/a><br \/><a href=\"https:\/\/nvidia-merlin.github.io\/Transformers4Rec\/main\/index.html\">Transformers4Rec<\/a><br \/><a href=\"https:\/\/github.com\/THUwangcy\/ReChorus\">ReChorus<\/a><br \/><a href=\"https:\/\/recbole.io\/\">RecBole<\/a><\/p>\n<\/p>\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\/company\/ru_mts\/blog\/709602\/\"> https:\/\/habr.com\/ru\/company\/ru_mts\/blog\/709602\/<\/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>\u00ab\u042f \u0442\u0435\u0431\u044f \u043f\u043e IP \u0432\u044b\u0447\u0438\u0441\u043b\u044e!\u00bb \u2013 \u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0442\u0430\u043a\u0443\u044e \u0443\u0433\u0440\u043e\u0437\u0443 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430 \u0432\u0440\u0435\u043c\u0435\u043d \u043d\u0443\u043b\u0435\u0432\u044b\u0445 \u0433\u043e\u0434\u043e\u0432? \u041c\u044b \u0432 <a href=\"https:\/\/career.habr.com\/companies\/mts\/vacancies\">Big Data \u041c\u0422\u0421<\/a> \u0440\u0435\u0448\u0438\u043b\u0438 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043f\u0440\u0438\u0431\u043b\u0438\u0437\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0435, \u043e\u0431\u043b\u0430\u0434\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0441\u0430\u0439\u0442\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d \u043f\u043e\u0441\u0435\u0449\u0430\u0435\u0442. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u043e\u043b\u0443\u0441\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043c\u0435\u043b\u044b\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u044d\u0442\u0438\u0445 \u0432\u0430\u0448\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0430\u0445.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u043d\u044b\u0445 \u0441\u0430\u0439\u0442\u0430\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0435 \u043f\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0418\u0432\u0430\u043d \u0418\u0432\u0430\u043d\u044b\u0447\u0443, \u0430 \u043f\u043e \u043e\u0431\u0435\u0437\u043b\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 cookie, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043e\u0431\u043c\u0435\u043d\u0435 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u043c\u0438 DSP- \u0438 SSP- \u043f\u043b\u043e\u0449\u0430\u0434\u043a\u0430\u043c\u0438. <\/p>\n<p>\u0412\u043e\u043f\u0440\u043e\u0441 \u0437\u0432\u0443\u0447\u0438\u0442 \u0442\u0430\u043a: \u0441\u043c\u043e\u0436\u0435\u043c \u043b\u0438 \u043c\u044b \u043f\u043e \u0446\u0438\u0444\u0440\u043e\u0432\u044b\u043c \u0441\u043b\u0435\u0434\u0430\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u043d\u0430 \u043a\u0430\u043a\u0438\u0445 \u0441\u0430\u0439\u0442\u0430\u0445 \u0441 \u043a\u0430\u043a\u0438\u0445 IP \u043e\u043d \u0441\u0438\u0434\u0435\u043b, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0437\u0430\u0445\u043e\u0434\u0438\u043b, \u043a\u0430\u043a\u043e\u0435 \u0443 \u043d\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e) \u043f\u043e\u043d\u044f\u0442\u044c, <strong>\u043a\u0442\u043e \u044d\u0442\u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c?<\/strong> \u0421\u0442\u0443\u0434\u0435\u043d\u0442 \u0438\u043b\u0438 \u043f\u0435\u043d\u0441\u0438\u043e\u043d\u0435\u0440? \u041c\u0443\u0436\u0447\u0438\u043d\u0430 \u0438\u043b\u0438 \u0436\u0435\u043d\u0449\u0438\u043d\u0430? \u041a\u0430\u043a \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043c\u044b \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c?<\/p>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0432 Digital-\u0440\u0435\u043a\u043b\u0430\u043c\u0435 \u0441\u0435\u0433\u043c\u0435\u043d\u0442 \u0447\u0430\u0441\u0442\u043e \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u043e\u043b \u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u0431\u0430\u043a\u0435\u0442\u043e\u0432 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443 (&lt;18, 18-24, 25-34, 35-44, 45-54, 55-64, 65+). \u042d\u0442\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u0430 \u0434\u043b\u044f \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u0445 DSP-\u043f\u043b\u043e\u0449\u0430\u0434\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 OpenRTB \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0447\u0430\u0441\u0442\u043e\u0442\u043e\u0439 200 000 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0441\u043e \u0432\u0441\u0435\u0445 \u0441\u0430\u0439\u0442\u043e\u0432, \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0449\u0438\u0445 \u0440\u0435\u043a\u043b\u0430\u043c\u0443 \u0437\u0430 \u0434\u0435\u043d\u044c\u0433\u0438. <\/p>\n<p>\u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0438 \u0432\u0430\u0441 <strong>\u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0440\u0442\u0440\u0435\u0442<\/strong> \u0440\u044f\u0434\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <s>\u0425\u0430\u0431\u0440\u0430<\/s> \u0434\u0435\u0441\u044f\u0442\u043a\u0430 \u043f\u043e\u0447\u0442\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0447\u043d\u044b\u043c \u043e\u043d \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u2013 \u043d\u0430\u0448 baseline \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u2013 \u0431\u0435\u0437 \u043a\u0440\u043e\u0441\u0441-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, feature engineering \u0438 \u043f\u0440\u043e\u0447\u0438\u0445 \u043f\u0440\u0438\u044f\u0442\u043d\u044b\u0445 \u0441\u0435\u0440\u0434\u0446\u0443 \u0432\u0435\u0449\u0435\u0439. \u0422\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043c\u0435\u0442\u0440\u043e \u043f\u043e \u0434\u043e\u0440\u043e\u0433\u0435 \u043e\u0442 \u0420\u0435\u0447\u043d\u043e\u0433\u043e \u0432\u043e\u043a\u0437\u0430\u043b\u0430 \u0434\u043e \u0422\u0435\u0445\u043d\u043e\u043f\u0430\u0440\u043a\u0430 (\u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0444\u0438\u0441 \u041c\u0422\u0421 Digital). \u042d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u0437\u0430\u0439\u043c\u0435\u0442 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 30 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u0417\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u0432\u0441\u0435\u043c DS-\u0438\u043a\u043e\u043d\u043e\u0441\u0442\u0430\u0441<\/h3>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0432 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u043e\u0435 \u043d\u0443\u0436\u043d\u043e\u0435 =) (\u043d\u0443 \u043f\u043e\u0447\u0442\u0438).<\/p>\n<pre><code class=\"python\">import sys import os import warnings os.environ['OPENBLAS_NUM_THREADS'] = '1' warnings.filterwarnings('ignore')<\/code><\/pre>\n<pre><code class=\"python\">import pandas as pd import numpy as np import time import pyarrow.parquet as pq import scipy import implicit import bisect import sklearn.metrics as m from catboost import CatBoostClassifier, CatBoostRegressor, Pool from sklearn.model_selection import train_test_split from sklearn.calibration import calibration_curve, CalibratedClassifierCV<\/code><\/pre>\n<pre><code class=\"python\">LOCAL_DATA_PATH = '.\/context_data\/' SPLIT_SEED = 42 DATA_FILE = 'competition_data_final_pqt' TARGET_FILE = 'competition_target_pqt'<\/code><\/pre>\n<h4>\u041f\u0440\u043e\u0447\u0438\u0442\u0430\u0435\u043c \u0444\u0430\u0439\u043b\u044b<\/h4>\n<pre><code class=\"python\">data = pq.read_table(f'{LOCAL_DATA_PATH}\/{DATA_FILE}') pd.DataFrame([(z.name, z.type) for z in data.schema], \\              columns = [['field', 'type']])<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432\u044b\u0448\u0435:<\/p>\n<ul>\n<li>\n<p>\u0440\u0435\u0433\u0438\u043e\u043d;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0430\u0441\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0443\u043d\u043a\u0442;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430;<\/p>\n<\/li>\n<li>\n<p>\u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u043c\u0435\u043d, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u0438\u0448\u0435\u043b \u0440\u0435\u043a\u043b\u0430\u043c\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441;<\/p>\n<\/li>\n<li>\n<p>\u0442\u0438\u043f \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 (\u0441\u043c\u0430\u0440\u0442\u0444\u043e\u043d \u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0434\u0440\u0443\u0433\u043e\u0435);<\/p>\n<\/li>\n<li>\n<p>\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043a\u0430 \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0446\u0435\u043d\u043a\u0430 \u0446\u0435\u043d\u044b \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0434\u0430\u0442\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0432\u0440\u0435\u043c\u044f \u0434\u043d\u044f;<\/p>\n<\/li>\n<li>\n<p>\u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0434\u043e\u043c\u0435\u043d\u0443 \u0432 \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u0434\u043d\u044f \u0432 \u044d\u0442\u0443 \u0434\u0430\u0442\u0443;<\/p>\n<\/li>\n<li>\n<p>id \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">data.select(['cpe_type_cd']).to_pandas()['cpe_type_cd'].value_counts()<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0441\u0435\u0431\u044f \u043e\u0442\u043a\u0440\u044b\u043b \u0441\u043b\u043e\u0432\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A4%D0%B0%D0%B1%D0%BB%D0%B5%D1%82\">\u0444\u0430\u0431\u043b\u0435\u0442<\/a>.<\/p>\n<pre><code class=\"python\">targets = pq.read_table(f'{LOCAL_DATA_PATH}\/{TARGET_FILE}') pd.DataFrame([(z.name, z.type) for z in targets.schema], \\              columns = [['field', 'type']])<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>\u043d\u0443 \u0442\u0443\u0442 \u0432\u0441\u0435 \u044f\u0441\u043d\u043e<\/figcaption><\/figure>\n<h3>\u041e\u043a, \u043d\u0430\u043c \u043b\u0435\u043d\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0442\u044c \u0444\u0438\u0447\u0438<\/h3>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0443, \u043a\u0430\u043a \u043d\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443: \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0443\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 Users \u0438 Items (\u043f\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u043d\u044b\u0435 \u0434\u043e\u043c\u0435\u043d\u044b) \u2013 \u043e\u0436\u0438\u0434\u0430\u0435\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433, \u0434\u0430 \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f. \u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u043d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u0447\u0442\u0438 \u043d\u0430 \u0411\u0435\u043b\u043e\u0440\u0443\u0441\u0441\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">%%time data_agg = data.select(['user_id', 'url_host', 'request_cnt']).\\     group_by(['user_id', 'url_host']).aggregate([('request_cnt', \"sum\")])<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">url_set = set(data_agg.select(['url_host']).to_pandas()['url_host']) print(f'{len(url_set)} urls') url_dict = {url: idurl for url, idurl in zip(url_set, range(len(url_set)))} usr_set = set(data_agg.select(['user_id']).to_pandas()['user_id']) print(f'{len(usr_set)} users') usr_dict = {usr: user_id for usr, user_id in zip(usr_set, range(len(usr_set)))}<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>\u043d\u0435 \u0441\u0430\u043c\u0430\u044f \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0432\u044b\u0439\u0434\u0435\u0442<\/figcaption><\/figure>\n<pre><code class=\"python\">%%time values = np.array(data_agg.select(['request_cnt_sum']).to_pandas()['request_cnt_sum']) rows = np.array(data_agg.select(['user_id']).to_pandas()['user_id'].map(usr_dict)) cols = np.array(data_agg.select(['url_host']).to_pandas()['url_host'].map(url_dict)) mat = scipy.sparse.coo_matrix((values, (rows, cols)), shape=(rows.max() + 1, cols.max() + 1)) als = implicit.approximate_als.FaissAlternatingLeastSquares(factors = 50, \\       iterations = 30, use_gpu = False, calculate_training_loss = False, regularization = 0.1)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">%%time als.fit(mat) u_factors = als.model.user_factors  d_factors = als.model.item_factors<\/code><\/pre>\n<figure class=\"full-width\"><figcaption>30 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439 \u0437\u0430 30 \u0441\u0435\u043a &#8212; \u0441\u043f\u0430\u0441\u0438\u0431\u043e FAISS!<\/figcaption><\/figure>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0446\u0435\u043d\u043a\u0443 \u043f\u043e \u043f\u043e\u043b\u0443<\/h3>\n<p>\u0420\u0430\u0437 \u0443\u0436 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0435 \u2013 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u043e\u043b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044f \u0432\u0441\u0435 \u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438 \u0438 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043f\u0440\u043e \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0438\u0447\u0438.<\/p>\n<pre><code class=\"python\">%%time inv_usr_map = {v: k for k, v in usr_dict.items()} usr_emb = pd.DataFrame(u_factors) usr_emb['user_id'] = usr_emb.index.map(inv_usr_map) usr_targets = targets.to_pandas() df = usr_targets.merge(usr_emb, how = 'inner', on = ['user_id']) df = df[df['is_male'] != 'NA'] df = df.dropna() df['is_male'] = df['is_male'].map(int) df['is_male'].value_counts()<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">%%time x_train, x_test, y_train, y_test = train_test_split(\\     df.drop(['user_id', 'age', 'is_male'], axis = 1), df['is_male'], test_size = 0.33, random_state = SPLIT_SEED) clf = CatBoostClassifier() clf.fit(x_train, y_train, verbose = False) print(f'GINI \u043f\u043e \u043f\u043e\u043b\u0443 {2 * m.roc_auc_score(y_test, clf.predict_proba(x_test)[:,1]) - 1:2.3f}')<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0443\u0436 \u043f\u043b\u043e\u0445\u043e! \u041d\u043e \u043c\u044b \u043f\u043e\u0447\u0442\u0438 \u0434\u043e\u0435\u0445\u0430\u043b\u0438 \u0434\u043e \u041f\u0430\u0432\u0435\u043b\u0435\u0446\u043a\u043e\u0439.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0446\u0435\u043d\u043a\u0443 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443<\/h3>\n<pre><code class=\"python\">import seaborn as sns import matplotlib.pyplot as plt import plotly.express as px  %matplotlib inline sns.set_style('darkgrid')<\/code><\/pre>\n<pre><code class=\"python\">def age_bucket(x):     return bisect.bisect_left([18,25,35,45,55,65], x)<\/code><\/pre>\n<pre><code class=\"python\">df = usr_targets.merge(usr_emb, how = 'inner', on = ['user_id']) df = df[df['age'] != 'NA'] df = df.dropna() df['age'] = df['age'].map(age_bucket) sns.histplot(df['age'], bins = 7)<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<pre><code class=\"python\">x_train, x_test, y_train, y_test = train_test_split(\\     df.drop(['user_id', 'age', 'is_male'], axis = 1), \\     df['age'], test_size = 0.33, random_state = SPLIT_SEED)  clf = CatBoostClassifier() clf.fit(x_train, y_train, verbose = False) print(m.classification_report(y_test, clf.predict(x_test), \\     target_names = ['&lt;18', '18-25','25-34', '35-44', '45-54', '55-65', '65+']))<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h3>\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c, \u0447\u0442\u043e \u043f\u043e\u043b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u0432\u043e\u0437\u0440\u0430\u0441\u0442.<br \/>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u0441\u043a\u043e\u0440 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u043e\u0439\u0434\u0443\u0442 Gini \u043f\u043e \u043f\u043e\u043b\u0443 (\u043e\u0442 0 \u0434\u043e 1) \u0438 f1 weighted \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0443 \u2013 \u0441 \u0432\u0435\u0441\u043e\u043c \u0434\u0432\u0430:<\/p>\n<h4>\u0418\u0442\u043e\u0433\u043e \u043e\u0431\u0449\u0438\u0439 \u0441\u043a\u043e\u0440: 0.665 + 2 * 0.41 = 1.485<\/h4>\n<p>\u0414\u043b\u044f \u043f\u043e\u0435\u0437\u0434\u043a\u0438 \u043e\u0442 \u0420\u0435\u0447\u043d\u043e\u0433\u043e \u0434\u043e \u0422\u0435\u0445\u043d\u043e\u043f\u0430\u0440\u043a\u0430 \u0442\u0435\u0440\u043f\u0438\u043c\u043e. =) <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435! \u0415\u0441\u043b\u0438 \u0436\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u2013 <strong>\u0436\u0434\u0435\u043c \u0432\u0430\u0441 \u043d\u0430 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f\u0445 \u043f\u043e Machine Learning 30 \u044f\u043d\u0432\u0430\u0440\u044f<\/strong>, \u044d\u0442\u043e \u0442\u0443\u0440\u043d\u0438\u0440 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043f\u043e\u043b\u0430\/\u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 cookie \u043e\u0442 \u041c\u0422\u0421 Digital. \u041f\u0440\u0438\u0437\u043e\u0432\u043e\u0439 \u0444\u043e\u043d\u0434 MTC ML Cup \u2013 <strong>650 000 \u0440\u0443\u0431\u043b\u0435\u0439<\/strong>: \u043f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442 350 000 \u0440\u0443\u0431\u043b\u0435\u0439, \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u0435\u043b\u044c \u0441\u0435\u0440\u0435\u0431\u0440\u0430 \u2013 200 000 \u0440\u0443\u0431\u043b\u0435\u0439, \u0430 \u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0440\u0438\u0437\u0435\u0440 \u0441\u0442\u0430\u043d\u0435\u0442 \u0431\u043e\u0433\u0430\u0447\u0435 \u043d\u0430 100 000 \u0440\u0443\u0431\u043b\u0435\u0439. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0443\u0436\u0435 \u043e\u0442\u043a\u0440\u044b\u0442\u0430, \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0430\u043d\u043a\u0435\u0442\u0430 \u0434\u043b\u044f \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u043e\u0432 \u0438 <a href=\"https:\/\/ods.ai\/competitions\/mtsmlcup\">\u0432\u0441\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 <\/a>\u2013 <a href=\"https:\/\/ods.ai\/competitions\/mtsmlcup\">\u043d\u0430 \u0441\u0430\u0439\u0442\u0435<\/a>. \u0423\u0432\u0438\u0434\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u0438!<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0443\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f! \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0438\u043d\u044b\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u043b\u0438 \u0436\u0435 \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0435 \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e \u043f\u0430\u0440\u044b \u043f\u0435\u0440\u0435\u0433\u043e\u043d\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0441\u0442\u0430\u043d\u0446\u0438\u044f\u043c\u0438 \u043c\u0435\u0442\u0440\u043e \u2013 <strong>\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0438\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445!<\/strong><\/p>\n<h3>P.S.<\/h3>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u044b\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0442\u0430\u0431\u043b\u0438\u0447\u043a\u0430\u043c\u0438 \u0432\u043c\u0435\u0441\u0442\u043e Pandas \u0438 PyArrow:<br \/><a href=\"https:\/\/github.com\/pola-rs\/polars\">Polars<\/a><br \/><a href=\"https:\/\/github.com\/rapidsai\/cudf\">CuDF<\/a><\/p>\n<p>\u0418 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f RecSys:<br \/><a href=\"https:\/\/github.com\/MobileTeleSystems\/RecTools\">MTS RecTools<\/a><br \/><a href=\"https:\/\/making.lyst.com\/lightfm\/docs\/home.html\">LightFM<\/a><br \/><a href=\"https:\/\/nvidia-merlin.github.io\/Transformers4Rec\/main\/index.html\">Transformers4Rec<\/a><br \/><a href=\"https:\/\/github.com\/THUwangcy\/ReChorus\">ReChorus<\/a><br \/><a href=\"https:\/\/recbole.io\/\">RecBole<\/a><\/p>\n<\/p>\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\/company\/ru_mts\/blog\/709602\/\"> https:\/\/habr.com\/ru\/company\/ru_mts\/blog\/709602\/<\/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-344059","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344059","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=344059"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/344059\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=344059"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=344059"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=344059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}