{"id":358131,"date":"2024-05-21T00:05:13","date_gmt":"2024-05-21T00:05:13","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=358131"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-05-21T00:05:13","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=358131","title":{"rendered":"<span>\u041a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u043a\u0438\u043d\u043e<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/593\/9f3\/e97\/5939f3e972e5dc27b3e6be9c4f89e811.jpg\" width=\"1280\" height=\"698\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/593\/9f3\/e97\/5939f3e972e5dc27b3e6be9c4f89e811.jpg\" data-blurred=\"true\"\/><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em> <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0435 \u0432\u0430\u0448 \u043b\u044e\u0431\u0438\u043c\u044b\u0439 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u043e\u0432, \u0442\u043e\u0447\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432\u0430\u0448\u0438\u043c \u0432\u043a\u0443\u0441\u0430\u043c &#8212; \u044d\u0442\u043e \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u043e\u0435 \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u0438\u0441\u043a\u0430\u043b\u0438.<\/p>\n<p>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0442 \u0436\u0438\u0437\u043d\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c, \u043d\u043e \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u044e\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0434\u043e\u0445\u043e\u0434\u044b \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439.<\/p>\n<h2>\u0421\u0431\u043e\u0440 \u0438 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<ol>\n<li>\n<p><strong>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u0438 \u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445:<\/strong> <\/p>\n<ul>\n<li>\n<p>\u0416\u0443\u0440\u043d\u0430\u043b\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (\u043b\u043e\u0433\u0438) \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u0441\u0430\u0439\u0442\u0435 \u0438\u043b\u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043b\u043e\u0433\u0430\u043c\u0438 import pandas as pd  # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0436\u0443\u0440\u043d\u0430\u043b\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 user_activity_log = pd.read_csv('user_activity.log') <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0435:<\/strong> <\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0442\u0430\u043b\u043e\u0433 \u0444\u0438\u043b\u044c\u043c\u043e\u0432, \u0441\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u0438\u043b\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430, \u0436\u0430\u043d\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0444\u0438\u043b\u044c\u043c\u0430\u0445:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0444\u0438\u043b\u044c\u043c\u0430\u0445 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 import sqlite3  conn = sqlite3.connect('movies.db') query = \"SELECT * FROM movies\" movies_data = pd.read_sql_query(query, conn) <\/code><\/pre>\n<h4>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0431\u043e\u0440\u0430 \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0421\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0432\u0430\u0436\u043d\u044b\u0439 \u044d\u0442\u0430\u043f. \u0412\u0430\u0436\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0445 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043a\u043b\u044e\u0447\u0430\u044f API, \u0432\u0435\u0431-\u0441\u043a\u0440\u0430\u043f\u0438\u043d\u0433, \u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API import requests  api_url = \"https:\/\/api.example.com\/data\" response = requests.get(api_url)  if response.status_code == 200:     data = response.json()     # \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 else:     print(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.\") <\/code><\/pre>\n<p>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, NoSQL \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449 \u0438\u043b\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Amazon S3.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 SQLite \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f SQLite \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 import sqlite3  conn = sqlite3.connect('recommendation_data.db') data.to_sql('user_activity', conn, if_exists='replace') <\/code><\/pre>\n<h4>\u041c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/h4>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u043b\u044f \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445. <\/p>\n<ol>\n<li>\n<p><strong>\u0423\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432 \u0438 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432:<\/strong> \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043a\u0430\u0437\u0438\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">data = data.drop_duplicates() <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u0428\u043a\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445:<\/strong> \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0430\u0436\u043d\u0430 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438 \u0438\u0437\u0431\u0435\u0433\u0430\u043d\u0438\u044f \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">from sklearn.preprocessing import MinMaxScaler  scaler = MinMaxScaler() data['rating'] = scaler.fit_transform(data['rating'].values.reshape(-1, 1)) <\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432:<\/strong> \u0412\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0436\u0430\u043d\u0440\u044b \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438\u043b\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"python\">from sklearn.feature_extraction.text import TfidfVectorizer  tfidf_vectorizer = TfidfVectorizer() tfidf_matrix = tfidf_vectorizer.fit_transform(data['description']) <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435, \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u044d\u0442\u0430\u043f\u0443 &#8212; \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<h2>\u041c\u0435\u0442\u043e\u0434\u044b \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0446\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0441\u0430\u0439\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0422\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430:<\/p>\n<ol>\n<li>\n<p><strong>\u0410\u043d\u0430\u043b\u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 ratings = np.random.randint(1, 6, 1000)  # \u0421\u0442\u0440\u043e\u0438\u043c \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f plt.hist(ratings, bins=5, alpha=0.75, rwidth=0.85, color='b') plt.xlabel('\u0420\u0435\u0439\u0442\u0438\u043d\u0433') plt.ylabel('\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0446\u0435\u043d\u043e\u043a') plt.title('\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439') plt.show() <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d06\/1eb\/922\/d061eb9229418729ff819db369340f99.png\" width=\"631\" height=\"452\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d06\/1eb\/922\/d061eb9229418729ff819db369340f99.png\"\/><\/figure>\n<ol start=\"2\">\n<li>\n<p><strong>\u041a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430\u043c\u0438 \u0434\u0432\u0443\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u043c\u043e\u0432 data = {     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A': [4, 3, 5, 2, 1],     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B': [5, 4, 4, 1, 2] } df = pd.DataFrame(data)  # \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u043e\u0446\u0435\u043d\u043a\u0430\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 correlation_matrix = df.corr()  print(correlation_matrix) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code class=\"yaml\">                \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A  \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A          1.0000          0.7698 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B          0.7698          1.0000<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0435\u0430\u043d\u0441\u043e\u0432 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0435\u0430\u043d\u0441\u043e\u0432 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 data = {     '\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430': ['2023-09-13 18:30:00', '2023-09-13 19:45:00', '2023-09-14 14:15:00'],     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c': ['\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A'] } df = pd.DataFrame(data)  # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 datetime df['\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430'] = pd.to_datetime(df['\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430'])  # \u0413\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0430\u043d\u0441\u0430\u043c\u0438 user_sessions = df.groupby('\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c')['\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430'].diff().mean()  print(user_sessions) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code>0 days 19:45:00<\/code><\/pre>\n<h4>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430\u043c\u0438. \u0412\u043e\u0442 \u0442\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0446\u0435\u043d\u043e\u043a:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import numpy as np from sklearn.cluster import KMeans  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432 ratings = np.random.randint(1, 6, (100, 5))  # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 K-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 kmeans = KMeans(n_clusters=3) kmeans.fit(ratings)  # \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 print(kmeans.cluster_centers_) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code>[[2.65217391 3.13043478 4.43478261 2.65217391 4.43478261]  [4.26829268 2.70731707 3.26829268 3.34146341 2.07317073]  [2.02777778 3.41666667 1.72222222 3.08333333 3.16666667]]<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0436\u0430\u043d\u0440\u043e\u0432 \u0444\u0438\u043b\u044c\u043c\u043e\u0432:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.cluster import KMeans  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0436\u0430\u043d\u0440\u0430\u043c\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 data = {     '\u0424\u0438\u043b\u044c\u043c': ['\u0424\u0438\u043b\u044c\u043c 1', '\u0424\u0438\u043b\u044c\u043c 2', '\u0424\u0438\u043b\u044c\u043c 3'],     '\u0416\u0430\u043d\u0440\u044b': ['\u043a\u043e\u043c\u0435\u0434\u0438\u044f', '\u0431\u043e\u0435\u0432\u0438\u043a', '\u0434\u0440\u0430\u043c\u0430'] } df = pd.DataFrame(data)  # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0436\u0430\u043d\u0440\u044b \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e TF-IDF tfidf_vectorizer = TfidfVectorizer() tfidf_matrix = tfidf_vectorizer.fit_transform(df['\u0416\u0430\u043d\u0440\u044b'])  # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 K-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043f\u043e \u0436\u0430\u043d\u0440\u0430\u043c kmeans = KMeans(n_clusters=2) kmeans.fit(tfidf_matrix.toarray())  # \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c print(kmeans.labels_) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code>[1 0 0]<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043e\u0446\u0435\u043d\u043e\u043a:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd from sklearn.cluster import KMeans from sklearn.preprocessing import StandardScaler  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 data = {     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c': ['\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c C'],     '\u0424\u0438\u043b\u044c\u043c 1': [4, 2, 5],     '\u0424\u0438\u043b\u044c\u043c 2': [3, 4, 1],     '\u0424\u0438\u043b\u044c\u043c 3': [5, 2, 3] } df = pd.DataFrame(data)  # \u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 scaler = StandardScaler() scaled_data = scaler.fit_transform(df.iloc[:, 1:])  # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 K-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 kmeans = KMeans(n_clusters=2) kmeans.fit(scaled_data)  # \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c print(kmeans.labels_) <\/code><\/pre>\n<h4>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445. <\/p>\n<h4>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0438\u0433\u0440\u0430\u0435\u0442 \u0432\u0430\u0436\u043d\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0445 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u044f\u0434\u0430 \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432:<\/strong><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd import numpy as np import matplotlib.pyplot as plt  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432 date_rng = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D') user_ratings = np.random.randint(1, 6, size=(len(date_rng)))  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c DataFrame df = pd.DataFrame({'Date': date_rng, 'User_Rating': user_ratings}) df.set_index('Date', inplace=True)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 plt.figure(figsize=(12, 6)) plt.plot(df.index, df['User_Rating'], marker='o') plt.title('\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432') plt.xlabel('\u0414\u0430\u0442\u0430') plt.ylabel('\u041e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f') plt.grid(True) plt.show() <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d3e\/db7\/b88\/d3edb7b88c298c1f0cfd54c0dd6f4b04.png\" width=\"1001\" height=\"545\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d3e\/db7\/b88\/d3edb7b88c298c1f0cfd54c0dd6f4b04.png\"\/><\/figure>\n<ol start=\"2\">\n<li>\n<p><strong>\u0412\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0435\u0437\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/strong><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0435\u0437\u043e\u043d\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0438\u043c.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u0421\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0438\u043c \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0435\u0437\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 window_size = 7  # \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430 df['Smoothed_Rating'] = df['User_Rating'].rolling(window=window_size).mean()  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 plt.figure(figsize=(12, 6)) plt.plot(df.index, df['Smoothed_Rating'], label=f'Smoothed (Window Size={window_size})', color='red') plt.title('\u0421\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432') plt.xlabel('\u0414\u0430\u0442\u0430') plt.ylabel('\u0421\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430') plt.grid(True) plt.legend() plt.show() <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7c3\/424\/8d3\/7c34248d37c90f84fcd491ae61254b86.png\" width=\"646\" height=\"333\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7c3\/424\/8d3\/7c34248d37c90f84fcd491ae61254b86.png\"\/><\/figure>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u044e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<h2>\u041c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439<\/h2>\n<p>\u041a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439.<\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f<\/strong> \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0438\u0434\u0435\u0435, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u044f\u0432\u0438\u043b\u0438 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c, \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0445\u043e\u0436\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a \u043e\u0446\u0435\u043d\u043a\u0438, \u043e\u0442\u0437\u044b\u0432\u044b \u0438\u043b\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u043e\u0432. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Python <code>surprise<\/code>:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">from surprise import Dataset, Reader from surprise import KNNBasic from surprise.model_selection import cross_validate  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 reader = Reader(rating_scale=(1, 5)) data = Dataset.load_from_df(df[['user_id', 'movie_id', 'rating']], reader)  # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 sim_options = {'name': 'cosine', 'user_based': False} algo = KNNBasic(sim_options=sim_options)  # \u041e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0440\u043e\u0441\u0441-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 cross_validate(algo, data, measures=['RMSE', 'MAE'], cv=5, verbose=True) <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u041a\u043e\u043d\u0442\u0435\u043d\u0442\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f<\/strong> \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0436\u0430\u043d\u0440, \u0430\u043a\u0442\u0435\u0440\u044b, \u0440\u0435\u0436\u0438\u0441\u0441\u0435\u0440\u044b \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0436\u0438\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0436\u0430\u043d\u0440\u0430:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">def content_based_recommendations(user_profile, movies, top_n=10):     # \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0444\u0438\u043b\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0444\u0438\u043b\u044c\u043c\u0430\u043c\u0438     similarities = cosine_similarity(user_profile, movies)          # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0442\u043e\u043f N \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439     top_indices = similarities.argsort()[-top_n:][::-1]     recommended_movies = [movies[i] for i in top_indices]     return recommended_movies <\/code><\/pre>\n<h4>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u044b\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438<\/h4>\n<p>\u041c\u0430\u0442\u0440\u0438\u0447\u043d\u044b\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043c\u043e\u0449\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<ol>\n<li>\n<p><strong>\u041c\u0430\u0442\u0440\u0438\u0447\u043d\u044b\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/strong> &#8212; \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c \u043d\u0430 \u0434\u0432\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438-\u0444\u0430\u043a\u0442\u043e\u0440\u044b \u0438 \u0444\u0430\u043a\u0442\u043e\u0440\u044b-\u043a\u043e\u043d\u0442\u0435\u043d\u0442. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0434\u043b\u044f \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u044b\u0445 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Alternating Least Squares (ALS):<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">from pyspark.ml.recommendation import ALS from pyspark.ml.evaluation import RegressionEvaluator  # \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 ALS als = ALS(maxIter=5, regParam=0.01, userCol=\"user_id\", itemCol=\"movie_id\", ratingCol=\"rating\")  # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 model = als.fit(train_data)  # \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 predictions = model.transform(test_data)  # \u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 evaluator = RegressionEvaluator(metricName=\"rmse\", labelCol=\"rating\", predictionCol=\"prediction\") rmse = evaluator.evaluate(predictions) <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u041d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0435 \u0441\u0435\u0442\u0438<\/strong> \u0441\u0442\u0430\u043b\u0438 \u0432\u0441\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0441\u0432\u043e\u0435\u0439 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c. \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Embedding, Flatten, Dense  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 model = Sequential() model.add(Embedding(input_dim=num_users, output_dim=50, input_length=1)) model.add(Flatten()) model.add(Dense(1, activation='linear'))  # \u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 model.compile(optimizer='adam', loss='mean_squared_error')  # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 model.fit([user_ids, movie_ids], ratings, epochs=5, batch_size=64) <\/code><\/pre>\n<h4>\u041e\u0446\u0435\u043d\u043a\u0430 \u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/h4>\n<p>\u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0438\u0433\u0440\u0430\u0435\u0442 \u0432\u0430\u0436\u043d\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0441\u0438\u0441\u0442\u0435\u043c. \u041e\u0434\u0438\u043d \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 &#8212; \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a RMSE (\u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430) \u0438\u043b\u0438 MAE (\u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430), \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u043c\u0435\u0440\u0438\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041f\u043e\u0441\u043b\u0435 \u043e\u0446\u0435\u043d\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0438\u0445 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043e\u0431\u043e\u0433\u0430\u0449\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u0440\u0438\u043a \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<pre><code class=\"python\">from surprise import accuracy from surprise.model_selection import GridSearchCV  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0442\u043a\u0438 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 param_grid = {'n_epochs': [5, 10, 15], 'lr_all': [0.002, 0.005, 0.01], 'reg_all': [0.4, 0.6, 0.8]}  # \u041f\u043e\u0434\u0431\u043e\u0440 \u043b\u0443\u0447\u0448\u0438\u0445 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 gs = GridSearchCV(SVD, param_grid, measures=['rmse', 'mae'], cv=3) gs.fit(data)  # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043b\u0443\u0447\u0448\u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 best_params = gs.best_params['rmse'] best_rmse = gs.best_score['rmse'] <\/code><\/pre>\n<p>\u041c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0433\u0440\u0430\u0435\u0442 \u0446\u0435\u043d\u0442\u0440\u0430\u043b\u044c\u043d\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438. <\/p>\n<h2>\u041f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439<\/h2>\n<p>\u041f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f &#8212; \u044d\u0442\u043e \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0438 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0438\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u043a\u0443\u0441\u0430\u043c \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430\u043c. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043e\u043f\u044b\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0434\u0435\u043b\u0430\u044f \u0441\u0435\u0440\u0432\u0438\u0441 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441\u043a\u043b\u043e\u043d\u043d\u044b \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u0434\u043e\u043b\u044c\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 \u0438\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0446\u0435\u043d\u044f\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u044f \u0443\u0447\u0435\u0442 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u043e\u0432 \u0438 \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439. \u0412\u043e\u0442 \u043a\u0430\u043a \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Python:<\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u043e\u0432 \u0438 \u043e\u0446\u0435\u043d\u043e\u043a def user_profile(user_id, user_history):     user_profile = {}     for movie_id, rating in user_history:         user_profile[movie_id] = rating     return user_profile  # \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f def personalized_recommendations(user_id, user_history, all_movies):     user_profile_data = user_profile(user_id, user_history)     recommended_movies = []      for movie_id in all_movies:         if movie_id not in user_profile_data:             recommended_movies.append(movie_id)          recommended_movies.sort(key=lambda movie_id: user_profile_data.get(movie_id, 0), reverse=True)     return recommended_movies <\/code><\/pre>\n<h4>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043b\u044f \u0443\u0447\u0435\u0442\u0430 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439<\/h4>\n<p>\u0414\u043b\u044f \u0443\u0447\u0435\u0442\u0430 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u041e\u0434\u0438\u043d \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 &#8212; \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 &#171;RankNet&#187; \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 TensorFlow:<\/p>\n<pre><code class=\"python\">from tensorflow import keras from tensorflow.keras import layers  # \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 RankNet def create_ranknet_model(input_dim):     model = keras.Sequential()     model.add(layers.Dense(64, activation='relu', input_dim=input_dim))     model.add(layers.Dense(32, activation='relu'))     model.add(layers.Dense(1, activation='linear'))     return model  # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 RankNet def train_ranknet_model(model, X, y, epochs=10):     model.compile(loss='mse', optimizer='adam')     model.fit(X, y, epochs=epochs, batch_size=32) <\/code><\/pre>\n<h4>\u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u041e\u0431\u0440\u0430\u0442\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 &#8212; \u044d\u0442\u043e \u0446\u0435\u043d\u043d\u044b\u0439 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u0432\u044f\u0437\u044c, \u0442\u0430\u043a\u0443\u044e \u043a\u0430\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043e\u0446\u0435\u043d\u043a\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438\u043b\u0438 \u0444\u0438\u0434\u0431\u0435\u043a \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438:<\/p>\n<pre><code class=\"python\"># \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043d\u043e\u0432\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f def update_recommendation_model(model, user_id, movie_id, new_rating):     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     user_history = get_user_history(user_id)      # \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     user_history.append((movie_id, new_rating))      # \u041f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439     user_profile_data = user_profile(user_id, user_history)     personalized_recommendations = personalized_recommendations(user_id, user_history, all_movies)      # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043d\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435     model.update_with_user_data(user_id, user_profile_data, personalized_recommendations) <\/code><\/pre>\n<p>\u041f\u043e\u0434\u0432\u0435\u0434\u0435\u043c \u0438\u0442\u043e\u0433: \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0438\u0433\u0440\u0430\u0435\u0442 \u043a\u0440\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u0434\u0435\u043b\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u0443\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0443\u0447\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043f\u043e\u0432\u044b\u0448\u0430\u044f \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0430\u0443\u0434\u0438\u0442\u043e\u0440\u0438\u0438 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435.<\/p>\n<h2>\u041e\u0446\u0435\u043d\u043a\u0430 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/h2>\n<p>\u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u0442\u044a\u0435\u043c\u043b\u0435\u043c\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0432\u0430\u0448\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a:<\/p>\n<ol>\n<li>\n<p><strong>RMSE (Root Mean Square Error)<\/strong>: \u042d\u0442\u0430 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u0427\u0435\u043c \u0431\u043b\u0438\u0436\u0435 RMSE \u043a \u043d\u0443\u043b\u044e, \u0442\u0435\u043c \u043b\u0443\u0447\u0448\u0435.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">from sklearn.metrics import mean_squared_error import numpy as np  # \u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f RMSE actual_ratings = [4, 3, 5, 2, 1] predicted_ratings = [3.8, 2.9, 4.9, 2.2, 1.2] rmse = np.sqrt(mean_squared_error(actual_ratings, predicted_ratings)) <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>Precision \u0438 Recall<\/strong>: \u042d\u0442\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438\u0437 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u044b \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439. Precision \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u0430 Recall &#8212; \u043f\u043e\u043b\u043d\u043e\u0442\u0443.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f Precision \u0438 Recall relevant_items = [1, 2, 3, 4, 5] recommended_items = [1, 3, 6, 7, 8] precision = len(set(relevant_items) &amp; set(recommended_items)) \/ len(recommended_items) recall = len(set(relevant_items) &amp; set(recommended_items)) \/ len(relevant_items) <\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>MAP (Mean Average Precision)<\/strong>: \u042d\u0442\u0430 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0440\u0430\u043d\u0436\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f MAP def average_precision(relevant_items, recommended_items):     # \u0420\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c Average Precision \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     precision_at_k = []     for k in range(1, len(recommended_items) + 1):         if recommended_items[k - 1] in relevant_items:             precision_at_k.append(len(set(relevant_items) &amp; set(recommended_items[:k])) \/ k)     return sum(precision_at_k) \/ len(relevant_items)  # \u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Average Precision \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 average_precisions = [average_precision(user['relevant_items'], user['recommended_items']) for user in users] map_score = sum(average_precisions) \/ len(users) <\/code><\/pre>\n<h4>\u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 A\/B-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h4>\n<p>\u041f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 A\/B-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0440\u0435\u0430\u043a\u0446\u0438\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439. \u042d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043d\u043e\u0432\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f A\/B-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"python\">import random  # \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0433\u0440\u0443\u043f\u043f\u044b A \u0438 B users = get_all_users() group_a_users = random.sample(users, len(users) \/\/ 2) group_b_users = list(set(users) - set(group_a_users))  # \u0412 \u0433\u0440\u0443\u043f\u043f\u0435 A \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u0440\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 # \u0412 \u0433\u0440\u0443\u043f\u043f\u0435 B \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439  # \u0421\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 <\/code><\/pre>\n<h4>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438<\/h4>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 &#8212; \u044d\u0442\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0438 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439. \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0444\u0438\u0434\u0431\u0435\u043a, \u0442\u0430\u043a\u043e\u0439 \u043a\u0430\u043a \u043e\u0446\u0435\u043d\u043a\u0438, \u043e\u0442\u0437\u044b\u0432\u044b \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435, \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0441\u0432\u044f\u0437\u0438:<\/p>\n<pre><code class=\"python\">def update_recommendation_model(model, user_id, movie_id, new_rating):     # \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     user_history = get_user_history(user_id)      # \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f     user_history.append((movie_id, new_rating))      # \u041f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0444\u0438\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439     user_profile_data = user_profile(user_id, user_history)     personalized_recommendations = personalized_recommendations(user_id, user_history, all_movies)      # \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043d\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435     model.update_with_user_data(user_id, user_profile_data, personalized_recommendations) <\/code><\/pre>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0438\u0441\u0442\u0435\u043c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0435 \u0441\u0442\u0440\u0435\u043c\u043b\u0435\u043d\u0438\u0435 \u043a \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u0443, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u044f\u0435\u0442 \u043a\u0430\u043a \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u0430\u043a \u0438 \u0430\u043c\u0431\u0438\u0446\u0438\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432.  <\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u043f\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u043a\u0443\u0440\u0441\u0430\u0445 OTUS. \u0412 <a href=\"https:\/\/otus.pw\/smQd\/\">\u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a> \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432\u0441\u044e \u043b\u0438\u043d\u0435\u0439\u043a\u0443 \u043a\u0443\u0440\u0441\u043e\u0432 \u043f\u043e \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0435. \u0410 \u0432 <a href=\"https:\/\/otus.pw\/KfuV\/\">\u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440\u0435<\/a> \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/otus.pw\/KfuV\/\">\u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438<\/a> \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0435 \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e.<\/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\/articles\/769026\/\"> https:\/\/habr.com\/ru\/articles\/769026\/<\/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<figure class=\"full-width\"><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em> <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0435 \u0432\u0430\u0448 \u043b\u044e\u0431\u0438\u043c\u044b\u0439 \u0441\u0442\u0440\u0438\u043c\u0438\u043d\u0433\u043e\u0432\u044b\u0439 \u0441\u0435\u0440\u0432\u0438\u0441, \u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u0430\u043c\u0438 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438 \u0441\u0435\u0440\u0438\u0430\u043b\u043e\u0432, \u0442\u043e\u0447\u043d\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432\u0430\u0448\u0438\u043c \u0432\u043a\u0443\u0441\u0430\u043c &#8212; \u044d\u0442\u043e \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u043e\u0435 \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u0448 \u0441\u0435\u0440\u0432\u0438\u0441 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0432\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0438 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u0438\u0441\u043a\u0430\u043b\u0438.<\/p>\n<p>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0442 \u0436\u0438\u0437\u043d\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c, \u043d\u043e \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u044e\u0442 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0443\u0434\u043e\u0432\u043b\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0434\u043e\u0445\u043e\u0434\u044b \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439.<\/p>\n<h2>\u0421\u0431\u043e\u0440 \u0438 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<ol>\n<li>\n<p><strong>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u0438 \u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445:<\/strong> <\/p>\n<ul>\n<li>\n<p>\u0416\u0443\u0440\u043d\u0430\u043b\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (\u043b\u043e\u0433\u0438) \u043d\u0430 \u0432\u0430\u0448\u0435\u043c \u0441\u0430\u0439\u0442\u0435 \u0438\u043b\u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u0440\u043e\u0444\u0438\u043b\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Python \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043b\u043e\u0433\u0430\u043c\u0438 import pandas as pd  # \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0436\u0443\u0440\u043d\u0430\u043b\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 user_activity_log = pd.read_csv('user_activity.log') <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0435:<\/strong> <\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0442\u0430\u043b\u043e\u0433 \u0444\u0438\u043b\u044c\u043c\u043e\u0432, \u0441\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u0438\u043b\u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430, \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0441\u043b\u043e\u0432\u0430, \u0436\u0430\u043d\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0444\u0438\u043b\u044c\u043c\u0430\u0445:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0444\u0438\u043b\u044c\u043c\u0430\u0445 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 import sqlite3  conn = sqlite3.connect('movies.db') query = \"SELECT * FROM movies\" movies_data = pd.read_sql_query(query, conn) <\/code><\/pre>\n<h4>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0431\u043e\u0440\u0430 \u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>\u0421\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 &#8212; \u044d\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u0432\u0430\u0436\u043d\u044b\u0439 \u044d\u0442\u0430\u043f. \u0412\u0430\u0436\u043d\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0438\u0445 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u043a\u043b\u044e\u0447\u0430\u044f API, \u0432\u0435\u0431-\u0441\u043a\u0440\u0430\u043f\u0438\u043d\u0433, \u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c API import requests  api_url = \"https:\/\/api.example.com\/data\" response = requests.get(api_url)  if response.status_code == 200:     data = response.json()     # \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 else:     print(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.\") <\/code><\/pre>\n<p>\u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, NoSQL \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449 \u0438\u043b\u0438 \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Amazon S3.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 SQLite \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f SQLite \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 import sqlite3  conn = sqlite3.connect('recommendation_data.db') data.to_sql('user_activity', conn, if_exists='replace') <\/code><\/pre>\n<h4>\u041c\u0435\u0442\u043e\u0434\u044b \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430<\/h4>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u0442\u044c \u043a \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0434\u043b\u044f \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445. <\/p>\n<ol>\n<li>\n<p><strong>\u0423\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u043e\u0432 \u0438 \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432:<\/strong> \u041f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043a\u0430\u0437\u0438\u0442\u044c \u0430\u043d\u0430\u043b\u0438\u0437, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u044b.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0434\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">data = data.drop_duplicates() <\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u0428\u043a\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445:<\/strong> \u041d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0430\u0436\u043d\u0430 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438 \u0438\u0437\u0431\u0435\u0433\u0430\u043d\u0438\u044f \u0438\u0441\u043a\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">from sklearn.preprocessing import MinMaxScaler  scaler = MinMaxScaler() data['rating'] = scaler.fit_transform(data['rating'].values.reshape(-1, 1)) <\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>\u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432:<\/strong> \u0412\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0436\u0430\u043d\u0440\u044b \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u0438\u043b\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"python\">from sklearn.feature_extraction.text import TfidfVectorizer  tfidf_vectorizer = TfidfVectorizer() tfidf_matrix = tfidf_vectorizer.fit_transform(data['description']) <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u0435, \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u044d\u0442\u0430\u043f\u0443 &#8212; \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<h2>\u041c\u0435\u0442\u043e\u0434\u044b \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0446\u0435\u043d\u043d\u044b\u0435 \u0438\u043d\u0441\u0430\u0439\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c. \u0422\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430:<\/p>\n<ol>\n<li>\n<p><strong>\u0410\u043d\u0430\u043b\u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 ratings = np.random.randint(1, 6, 1000)  # \u0421\u0442\u0440\u043e\u0438\u043c \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f plt.hist(ratings, bins=5, alpha=0.75, rwidth=0.85, color='b') plt.xlabel('\u0420\u0435\u0439\u0442\u0438\u043d\u0433') plt.ylabel('\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0446\u0435\u043d\u043e\u043a') plt.title('\u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439') plt.show() <\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<ol start=\"2\">\n<li>\n<p><strong>\u041a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430\u043c\u0438 \u0434\u0432\u0443\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u043c\u043e\u0432 data = {     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A': [4, 3, 5, 2, 1],     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B': [5, 4, 4, 1, 2] } df = pd.DataFrame(data)  # \u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043b\u044f\u0446\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u043e\u0446\u0435\u043d\u043a\u0430\u043c\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 correlation_matrix = df.corr()  print(correlation_matrix) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code class=\"yaml\">                \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A  \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A          1.0000          0.7698 \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B          0.7698          1.0000<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0435\u0430\u043d\u0441\u043e\u0432 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0435\u0430\u043d\u0441\u043e\u0432 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 data = {     '\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430': ['2023-09-13 18:30:00', '2023-09-13 19:45:00', '2023-09-14 14:15:00'],     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c': ['\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A'] } df = pd.DataFrame(data)  # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442 datetime df['\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430'] = pd.to_datetime(df['\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430'])  # \u0413\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0430\u043d\u0441\u0430\u043c\u0438 user_sessions = df.groupby('\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c')['\u0412\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430'].diff().mean()  print(user_sessions) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code>0 days 19:45:00<\/code><\/pre>\n<h4>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043f\u043e\u0445\u043e\u0436\u0438\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430\u043c\u0438. \u0412\u043e\u0442 \u0442\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0446\u0435\u043d\u043e\u043a:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import numpy as np from sklearn.cluster import KMeans  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432 ratings = np.random.randint(1, 6, (100, 5))  # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 K-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 kmeans = KMeans(n_clusters=3) kmeans.fit(ratings)  # \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 print(kmeans.cluster_centers_) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code>[[2.65217391 3.13043478 4.43478261 2.65217391 4.43478261]  [4.26829268 2.70731707 3.26829268 3.34146341 2.07317073]  [2.02777778 3.41666667 1.72222222 3.08333333 3.16666667]]<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0436\u0430\u043d\u0440\u043e\u0432 \u0444\u0438\u043b\u044c\u043c\u043e\u0432:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.cluster import KMeans  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0436\u0430\u043d\u0440\u0430\u043c\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 data = {     '\u0424\u0438\u043b\u044c\u043c': ['\u0424\u0438\u043b\u044c\u043c 1', '\u0424\u0438\u043b\u044c\u043c 2', '\u0424\u0438\u043b\u044c\u043c 3'],     '\u0416\u0430\u043d\u0440\u044b': ['\u043a\u043e\u043c\u0435\u0434\u0438\u044f', '\u0431\u043e\u0435\u0432\u0438\u043a', '\u0434\u0440\u0430\u043c\u0430'] } df = pd.DataFrame(data)  # \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u0436\u0430\u043d\u0440\u044b \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e TF-IDF tfidf_vectorizer = TfidfVectorizer() tfidf_matrix = tfidf_vectorizer.fit_transform(df['\u0416\u0430\u043d\u0440\u044b'])  # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 K-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043f\u043e \u0436\u0430\u043d\u0440\u0430\u043c kmeans = KMeans(n_clusters=2) kmeans.fit(tfidf_matrix.toarray())  # \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c print(kmeans.labels_) <\/code><\/pre>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/strong><\/p>\n<pre><code>[1 0 0]<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0438 \u043e\u0446\u0435\u043d\u043e\u043a:<\/strong><\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd from sklearn.cluster import KMeans from sklearn.preprocessing import StandardScaler  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0438\u0441\u0442\u043e\u0440\u0438\u0435\u0439 \u043e\u0446\u0435\u043d\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 data = {     '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c': ['\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c A', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c B', '\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c C'],     '\u0424\u0438\u043b\u044c\u043c 1': [4, 2, 5],     '\u0424\u0438\u043b\u044c\u043c 2': [3, 4, 1],     '\u0424\u0438\u043b\u044c\u043c 3': [5, 2, 3] } df = pd.DataFrame(data)  # \u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 scaler = StandardScaler() scaled_data = scaler.fit_transform(df.iloc[:, 1:])  # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 K-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 kmeans = KMeans(n_clusters=2) kmeans.fit(scaled_data)  # \u0412\u044b\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c print(kmeans.labels_) <\/code><\/pre>\n<h4>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432\u044b\u044f\u0432\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445. <\/p>\n<h4>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439<\/h4>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0438\u0433\u0440\u0430\u0435\u0442 \u0432\u0430\u0436\u043d\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0445 \u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u044f\u0434\u0430 \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432:<\/strong><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u043e\u0446\u0435\u043d\u043a\u0438 \u0444\u0438\u043b\u044c\u043c\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">import pandas as pd import numpy as np import matplotlib.pyplot as plt  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432 date_rng = pd.date_range(start='2023-01-01', end='2023-12-31', freq='D') user_ratings = np.random.randint(1, 6, size=(len(date_rng)))  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c DataFrame df = pd.DataFrame({'Date': date_rng, 'User_Rating': user_ratings}) df.set_index('Date', inplace=True)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 plt.figure(figsize=(12, 6)) plt.plot(df.index, df['User_Rating'], marker='o') plt.title('\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432') plt.xlabel('\u0414\u0430\u0442\u0430') plt.ylabel('\u041e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f') plt.grid(True) plt.show() <\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<ol start=\"2\">\n<li>\n<p><strong>\u0412\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0435\u0437\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439:<\/strong><\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0435\u0437\u043e\u043d\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0438\u043c.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\"># \u0421\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c \u0441\u0440\u0435\u0434\u043d\u0438\u043c \u0434\u043b\u044f \u0432\u044b\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0435\u0437\u043e\u043d\u043d\u044b\u0445 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u043e\u0432 window_size = 7  # \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u043a\u043d\u0430 df['Smoothed_Rating'] = df['User_Rating'].rolling(window=window_size).mean()  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 plt.figure(figsize=(12, 6)) plt.plot(df.index, df['Smoothed_Rating'], label=f'Smoothed (Window Size={window_size})', color='red') plt.title('\u0421\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0440\u044f\u0434 \u043e\u0446\u0435\u043d\u043e\u043a \u0444\u0438\u043b\u044c\u043c\u043e\u0432') plt.xlabel('\u0414\u0430\u0442\u0430') plt.ylabel('\u0421\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430') plt.grid(True) plt.legend() plt.show() <\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0440\u044f\u0434\u043e\u0432 \u0438 \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u044d\u0432\u043e\u043b\u044e\u0446\u0438\u044e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<h2>\u041c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439<\/h2>\n<p>\u041a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u0438 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0434\u0432\u0430 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0439.<\/p>\n<ol>\n<li>\n<p><strong>\u041a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f<\/strong> \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0438\u0434\u0435\u0435, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u044f\u0432\u0438\u043b\u0438 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u043c, \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u0445\u043e\u0436\u0438\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441 \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u043e\u043c, \u0442\u0430\u043a\u0438\u043c \u043a\u0430\u043a \u043e\u0446\u0435\u043d\u043a\u0438, \u043e\u0442\u0437\u044b\u0432\u044b \u0438\u043b\u0438 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u043e\u0432. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Python <code>surprise<\/code>:<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">from surprise import Dataset, Reader from surprise import KNNBasic from surprise.model_selection import cross_validate  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 reader = Reader(rating_scale=(1, 5)) data = Dataset.load_from_df(df[['user_id', 'movie_id', 'rating']], reader)  # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043e\u043b\u043b\u0430\u0431\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 sim_options = {'name': 'cosine',<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-358131","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/358131","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=358131"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/358131\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=358131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=358131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=358131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}