{"id":351037,"date":"2023-07-31T15:02:59","date_gmt":"2023-07-31T15:02:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=351037"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=351037","title":{"rendered":"<span>\u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 SVD<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>Collaborative Filtering<\/strong>\u00a0&#8212; \u043f\u043e\u0434\u0445\u043e\u0434, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445 \u043c\u0435\u0436\u0434\u0443 <strong>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 (users)<\/strong> \u0438 <strong>\u0442\u043e\u0432\u0430\u0440\u043e\u043c (items)<\/strong>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u0438\u043b\u0438 \u0442\u043e\u0432\u0430\u0440\u0430\u0445. <\/p>\n<p>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442 \u043d\u0430 \u0434\u0432\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438: <\/p>\n<ul>\n<li>\n<p><strong>\u042f\u0432\u043d\u043e\u0435<\/strong> <strong>\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0435\u0439\u0442\u0438\u043d\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u043e\u0432\u0430\u0440\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0435\u044f\u0432\u043d\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435.<\/strong> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0438\u043a, \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0438\u043b\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0430 \u0442\u043e\u0432\u0430\u0440\u0430 \u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430.<\/p>\n<\/li>\n<\/ul>\n<p><strong>User-item matrix<\/strong>\u00a0\u2014 \u044d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 &#8212; \u0442\u043e\u0432\u0430\u0440, \u0430 \u043a\u0430\u0436\u0434\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u044f\u0447\u0435\u0439\u043a\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043a\u0443\u043f\u0438\u043b \u0442\u043e\u0432\u0430\u0440, \u0438\u043b\u0438 \u043e\u0446\u0435\u043d\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0442\u043e\u0432\u0430\u0440\u0443. <strong>User-item matrix<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \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 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432.  \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e <strong>user-item matrix<\/strong> &#8212; \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0438 \u0440\u0430\u0437\u0440\u044f\u0436\u0435\u043d\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430.  <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ef6\/964\/e81\/ef6964e814cdb9f94d032704d4ecec16.png\" alt=\"User-item matrix\u00a0\" title=\"User-item matrix\u00a0\" width=\"1055\" height=\"1009\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ef6\/964\/e81\/ef6964e814cdb9f94d032704d4ecec16.png\"\/><\/p>\n<div><figcaption><strong>User-item matrix<\/strong>\u00a0<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 <a href=\"https:\/\/translated.turbopages.org\/proxy_u\/en-ru.ru.0832cecd-64b5506e-d08cf623-74722d776562\/https\/en.wikipedia.org\/wiki\/Matrix_factorization_(recommender_systems)\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u0430\u0442\u0440\u0438\u0447\u043d\u0443\u044e \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e<\/u><\/a> (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <strong>user-item matrix<\/strong> \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0442\u0440\u0438\u0446 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u0438\u0434\u0430). <\/p>\n<p>\u0427\u0430\u0441\u0442\u043e \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u0430\u044f \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u0433\u0434\u0435 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. <\/p>\n<p>\u0422\u0430\u043a \u0434\u0435\u043b\u043e \u043e\u0431\u0441\u0442\u043e\u0438\u0442 \u0441\u00a0<a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%B5%D1%82%D0%BE%D0%B4_%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D1%8B%D1%85_%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%BD%D0%B5%D0%BD%D1%82\" rel=\"noopener noreferrer nofollow\"><u>\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u044b\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c (PCA)<\/u><\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%B8%D0%BD%D0%B3%D1%83%D0%BB%D1%8F%D1%80%D0%BD%D0%BE%D0%B5_%D1%80%D0%B0%D0%B7%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e (SVD)<\/u><\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"R_{m \\times n} = U_{m \\times m} \\Sigma_{m \\times n} V^{T}_{n \\times n}\" alt=\"R_{m \\times n} = U_{m \\times m} \\Sigma_{m \\times n} V^{T}_{n \\times n}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cd1\/8d6\/bd0\/cd18d6bd0f5629f6ea1413e4acfbcc49.svg\" width=\"209\" height=\"22\"\/><\/p>\n<p>\u0433\u0434\u0435<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"R\" alt=\"R\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/73d\/80e\/c53\/73d80ec53bc6d4116c39b29a3eafdd75.svg\" width=\"15\" height=\"17\"\/> \u2014 <em>user-item matrix<\/em><strong>, <\/strong><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\Sigma\" alt=\"\\Sigma\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f60\/241\/4eb\/f602414eb1f32ed34244c241207157bf.svg\" width=\"14\" height=\"17\"\/>  \u2014 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0441 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"U\" alt=\"U\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dd1\/152\/ec4\/dd1152ec494f4fa846725eae5692dd25.svg\" width=\"15\" height=\"17\"\/> \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"V\" alt=\"V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/209\/965\/e5b\/209965e5b1e1bd2fb748f1230e647e01.svg\" width=\"15\" height=\"17\"\/> \u2014 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"U^T U = I\" alt=\"U^T U = I\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5cb\/ef9\/071\/5cbef9071f5def3d2b926659d6e33a3d.svg\" width=\"77\" height=\"21\"\/>.<\/p>\n<p>PCA \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0442\u0435\u0440\u044f\u0432 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0432\u0435\u0434\u0435\u043d\u043e \u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044e SVD \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e <em>SVD<\/em> \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"R\" alt=\"R\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a44\/03b\/e68\/a4403be681695590af8bfecc18e9b7cd.svg\" width=\"15\" height=\"17\"\/>, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0443\u043c\u043c\u044b \u0432\u0437\u0430\u0438\u043c\u043d\u043e \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"R\" alt=\"R\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f67\/810\/c3b\/f67810c3b925cd79a5b5e20adc24a115.svg\" width=\"15\" height=\"17\"\/>, \u0430 \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"R\" alt=\"R\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/32f\/18a\/301\/32f18a301414b7094539f29b65699b2e.svg\" width=\"15\" height=\"17\"\/> \u2014 \u0432 \u0432\u0438\u0434\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u043d\u0430 \u044d\u0442\u0438 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0441 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430\u043c\u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda_i\" alt=\"\\lambda_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/201\/597\/130\/201597130e5ab438060178453f709739.svg\" width=\"18\" height=\"20\"\/>.<\/p>\n<p>\u041e\u0441\u0442\u0430\u0432\u0438\u0432 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"d\" alt=\"d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b94\/d29\/daa\/b94d29daada055239b9793d4658c0ad7.svg\" width=\"10\" height=\"17\"\/>-\u043f\u0435\u0440\u0432\u044b\u0445 (\u0433\u043b\u0430\u0432\u043d\u044b\u0445) \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (<img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"\\lambda_i\" alt=\"\\lambda_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cc5\/4cf\/67d\/cc54cf67d0155e26a50c60885ac382d2.svg\" width=\"18\" height=\"20\"\/>) \u0432 SVD \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0438\u0435 \u043a <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"R\" alt=\"R\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d6d\/3d4\/2db\/d6d3d42dbe0f4c0734241ad8973b8bfc.svg\" width=\"15\" height=\"17\"\/> \u043f\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9D%D0%BE%D1%80%D0%BC%D0%B0_%D0%BC%D0%B0%D1%82%D1%80%D0%B8%D1%86%D1%8B\" rel=\"noopener noreferrer nofollow\">\u043d\u043e\u0440\u043c\u0435 \u0424\u0440\u043e\u0431\u0435\u043d\u0438\u0443\u0441\u0430<\/a>.<\/p>\n<p>\u0417\u0430 &#171;\u0421\u043a\u0440\u044b\u0442\u044b\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u043c&#187; \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f SVD \u0438 PCA.<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 SVD \u0438 PCA.<\/p>\n<pre><code class=\"python\">import numpy as np from matplotlib import image from matplotlib import pyplot as plt import cv2<\/code><\/pre>\n<pre><code class=\"python\">img = image.imread(\"photo.jpg\") plt.imshow(img) plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/de0\/d1b\/7b4\/de0d1b7b44a567ab5122dec136fb17b6.png\" width=\"259\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/de0\/d1b\/7b4\/de0d1b7b44a567ab5122dec136fb17b6.png\"\/><\/figure>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u043c\u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e. <\/p>\n<pre><code class=\"python\">gray_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) plt.imshow(gray_img, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/14b\/c41\/d33\/14bc41d337a4b473a867784cfc0238d3.png\" width=\"259\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/14b\/c41\/d33\/14bc41d337a4b473a867784cfc0238d3.png\"\/><\/figure>\n<pre><code class=\"python\">gray_img.shape  (558, 563)<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c SVD \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <\/p>\n<pre><code class=\"python\">U, lmbd, V = np.linalg.svd(gray_img) U.shape, lmbd.shape, V.shape  ((558, 558), (558,), (563, 563))<\/code><\/pre>\n<pre><code class=\"python\">S = np.zeros((U.shape[1], V.shape[0]))  S[ : U.shape[1], : U.shape[1]] = np.diag(lmbd) S.shape  (558, 563)<\/code><\/pre>\n<p>\u0412\u0435\u0440\u043d\u0435\u043c \u043a\u0430\u043a \u0431\u044b\u043b\u043e, \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c<\/p>\n<pre><code class=\"python\">plt.imshow(U @ S @ V, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/79b\/d2a\/3a6\/79bd2a3a66e5496d5f805d946193440f.png\" width=\"259\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/79b\/d2a\/3a6\/79bd2a3a66e5496d5f805d946193440f.png\"\/><\/figure>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 100 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">d = 100 U_crop = U[:, :d] S_crop = S[:d, :d] V_crop = V[:d, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/522\/8d8\/2aa\/5228d82aaba02c3b600c20c3e7ea0a71.png\" width=\"259\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/522\/8d8\/2aa\/5228d82aaba02c3b600c20c3e7ea0a71.png\"\/><\/figure>\n<p>\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c, \u0437\u0430\u0442\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u043b\u0435\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438!<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 50 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<pre><code class=\"python\">d = 50 U_crop = U[:, :d] S_crop = S[:d, :d] V_crop = V[:d, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d49\/40d\/ab9\/d4940dab9fc7b8c7d46885b5c4e4a1de.png\" width=\"259\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d49\/40d\/ab9\/d4940dab9fc7b8c7d46885b5c4e4a1de.png\"\/><\/figure>\n<p>\u041e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0435 10 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<pre><code class=\"python\">d = 10 U_crop = U[:, :d] S_crop = S[:d, :d] V_crop = V[:d, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/86d\/7fa\/a4b\/86d7faa4b10464a1b49a65812a49f21e.png\" alt=\"\" title=\"\" width=\"259\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/86d\/7fa\/a4b\/86d7faa4b10464a1b49a65812a49f21e.png\"\/><\/figure>\n<p>\u0421\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0435 S \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e: \u0447\u0435\u043c \u0431\u043b\u0438\u0436\u0435 \u043a \u043d\u0430\u0447\u0430\u043b\u0443, \u0442\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432\u0430\u0436\u043d\u0435\u0435 \u0438 \u0441\u0438\u043b\u044c\u043d\u0435\u0435 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.  <\/p>\n<p>\u0423\u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0435 5 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<pre><code>k = 5U_crop = U[:, k:] S_crop = S[k:, k:] V_crop = V[k:, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6d0\/5e6\/9f3\/6d05e69f3ae2862c1be8f47ff27369ba.png\" width=\"259\" height=\"252\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6d0\/5e6\/9f3\/6d05e69f3ae2862c1be8f47ff27369ba.png\"\/><\/figure>\n<p>\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0445\u0443\u0436\u0435.<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0430\u0448\u0443 <em>user-item matrix<\/em> \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043c\u0430\u0442\u0440\u0438\u0446:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"R_{m \\times n} = P_{m \\times n} Q_{n \\times n}\" alt=\"R_{m \\times n} = P_{m \\times n} Q_{n \\times n}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/797\/3d0\/b79\/7973d0b795d6c92384a97a3d73c03c57.svg\" width=\"162\" height=\"20\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"P = U_{m \\times m} \\Sigma_{m \\times d}\" alt=\"P = U_{m \\times m} \\Sigma_{m \\times d}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9f4\/eb6\/8ce\/9f4eb68ce570b788985edc6d457373c3.svg\" width=\"135\" height=\"20\"\/><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"Q = V_{d \\times n}\" alt=\"Q = V_{d \\times n}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/85b\/f41\/16e\/85bf4116e317b4fe6c886def285503e3.svg\" width=\"80\" height=\"20\"\/><\/p>\n<p><strong>\u0422\u043e\u0433\u0434\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7f0\/a7f\/b15\/7f0a7fb159c3633601fcbd4ceadd1fd8.svg\" width=\"7\" height=\"16\"\/>\u2011a\u044f \u0441\u0442\u0440\u043e\u043a\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"U\" alt=\"U\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cb7\/4cb\/205\/cb74cb205effbdb0a4ff0435857dda95.svg\" width=\"15\" height=\"17\"\/>\u00a0\u2014 \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i\" alt=\"i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a7b\/56a\/8d3\/a7b56a8d38b2f130e194b401519f5e42.svg\" width=\"7\" height=\"16\"\/>\u2011\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"j\" alt=\"j\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4b4\/4eb\/f5a\/4b44ebf5ad9c669abb89447da22e35c0.svg\" width=\"8\" height=\"19\"\/>\u2011\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"V\" alt=\"V\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/245\/6ba\/93d\/2456ba93d13b695f2c6d0bd5ef005211.svg\" width=\"15\" height=\"17\"\/>\u00a0\u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0442\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"j\" alt=\"j\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d1c\/128\/67e\/d1c12867e60e7484dee99361e5c951cb.svg\" width=\"8\" height=\"19\"\/>\u2011\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430.<\/strong> <strong>\u0418\u0445 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 (\u0440\u0435\u0439\u0442\u0438\u043d\u0433) \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"R[i][j] = \\langle P[i, :], Q[:, j] \\rangle\" alt=\"R[i][j] = \\langle P[i, :], Q[:, j] \\rangle\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6a9\/284\/5c9\/6a92845c9d50d6712f87c6ed2efc6767.svg\" width=\"194\" height=\"22\"\/><\/p>\n<p>\u041c\u0430\u0442\u0440\u0438\u0446\u044b <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P\" alt=\"P\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9d6\/941\/6c5\/9d69416c532e92b7487093d21c329dad.svg\" width=\"14\" height=\"17\"\/> \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q\" alt=\"Q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/70c\/bb8\/2df\/70cbb82dfbaa7bf67b0eb425bd990ff8.svg\" width=\"15\" height=\"20\"\/> \u043d\u0430\u0439\u0434\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Loss\" alt=\"Loss\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fee\/ea8\/412\/feeea8412de61122404147d374ba670c.svg\" width=\"41\" height=\"17\"\/> \u0432\u043e\u0437\u044c\u043c\u0435\u043c <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"RMSE\" alt=\"RMSE\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2fa\/72a\/a24\/2fa72aa241769ef55f67cb29a60a47ac.svg\" width=\"62\" height=\"17\"\/> \u0431\u0435\u0437 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"RMSE = \\frac{1}{\\lvert D \\rvert} \\sum_{(i,j) \\in D} (\\hat{R}_{i, j} - R_{i, j})^2 =     \\frac{1}{\\lvert D \\rvert} \\sum_{(i, j) \\in D} (P_{i} Q_{j} - R_{i, j})^2\" alt=\"RMSE = \\frac{1}{\\lvert D \\rvert} \\sum_{(i,j) \\in D} (\\hat{R}_{i, j} - R_{i, j})^2 =     \\frac{1}{\\lvert D \\rvert} \\sum_{(i, j) \\in D} (P_{i} Q_{j} - R_{i, j})^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5cb\/2af\/1a3\/5cb2af1a31f1174b3d267a9c76d75b3b.svg\" width=\"506\" height=\"56\"\/><\/p>\n<p>\u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0432 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043f\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"P\" alt=\"P\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3c6\/758\/5c6\/3c67585c68036dcc153059d72e7d7a43.svg\" width=\"14\" height=\"17\"\/> \u0438 \u043f\u043e <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"Q\" alt=\"Q\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/724\/5eb\/71c\/7245eb71c7760bdb604de89f83405f3d.svg\" width=\"15\" height=\"20\"\/>, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"\\begin{cases}     P[i][k] = P[i][k] - \\frac{2}{\\lvert D \\rvert} \\cdot \\sum_{(i,j) \\in D} (\\hat{R}_{i,j} - R_{i,j}) \\cdot Q[k][i]     \\\\     Q[k][i] = Q[k][i] - \\frac{2}{\\lvert D \\rvert} \\cdot \\sum_{(i,j) \\in D} (\\hat{R}_{i,j} - R_{i,j}) \\cdot P[i][k] \\end{cases}\" alt=\"\\begin{cases}     P[i][k] = P[i][k] - \\frac{2}{\\lvert D \\rvert} \\cdot \\sum_{(i,j) \\in D} (\\hat{R}_{i,j} - R_{i,j}) \\cdot Q[k][i]     \\\\     Q[k][i] = Q[k][i] - \\frac{2}{\\lvert D \\rvert} \\cdot \\sum_{(i,j) \\in D} (\\hat{R}_{i,j} - R_{i,j}) \\cdot P[i][k] \\end{cases}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b92\/763\/e46\/b92763e46e7290fc931b7439c4e16607.svg\" width=\"452\" height=\"66\"\/><\/p>\n<p>k \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u0442 \u043e\u0442 1 \u0434\u043e d, \u0433\u0434\u0435 d &#8212; \u0447\u0438\u0441\u043b\u043e \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u041f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u041f\u0443\u0441\u0442\u044c \u043d\u0430\u043c \u0437\u0430\u0434\u0430\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0438 \u0438\u0445 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u043c \u0444\u0438\u043b\u044c\u043c\u0430\u043c. \u0417\u0430\u0434\u0430\u0447\u0430 &#8212; \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 user-item matrix.<\/p>\n<pre><code class=\"python\">import numpy as np import pandas as pd<\/code><\/pre>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0444\u0438\u043b\u044c\u043c\u044b:<\/p>\n<pre><code class=\"python\">k = 10 # \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430  movies = ['\u0424\u0430\u043d\u0442\u0430\u0437\u0438\u044f', '\u0412\u0410\u041b\u041b-\u0418', '\u041f\u0438\u043d\u043e\u043a\u043a\u0438\u043e', '\u0411\u0435\u043c\u0431\u0438' , '\u0428\u0440\u044d\u043a', '\u0414\u0430\u043c\u0431\u043e', '\u0421\u043f\u0430\u0441\u0430\u0442\u0435\u043b\u0438', '\u0413\u0435\u0440\u043a\u0443\u043b\u0435\u0441', '\u041a\u0443\u043d\u0433-\u0444\u0443 \u041f\u0430\u043d\u0434\u0430'] m_movies = len(movies)  users = ['\u0410\u043d\u0434\u0440\u0435\u0439', '\u0410\u043d\u044f', '\u0410\u043b\u0438\u0441\u0430', '\u0412\u0430\u043d\u044f', '\u041b\u0435\u0448\u0430', '\u041e\u043a\u0441\u0430\u043d\u0430', '\u0421\u0430\u0448\u0430', '\u041f\u0430\u0448\u0430', '\u0421\u0435\u043d\u044f', '\u0413\u0440\u0438\u0448\u0430']         n_users = len(users)<\/code><\/pre>\n<p>\u041e\u0446\u0435\u043d\u043a\u0438 \u0440\u0430\u0441\u043a\u0438\u0434\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u0440\u0430 user-movie \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u043b\u0430\u0441\u044c <\/p>\n<pre><code class=\"python\">RANDOMSEED = 42 np.random.seed(42)  N = np.random.randint(50, 60) # \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0446\u0435\u043d\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e  ind_users, ind_movies, rating = [], [], [] user_movie = [] # \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u0440\u0430 user-movie \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u043b\u0438\u0441\u044c for _ in range(N):     user = np.random.randint(0, n_users)     movie = np.random.randint(0, m_movies)     if not [user, movie] in user_movie:         ind_users.append(user)         ind_movies.append(movie)         rating.append(np.random.randint(1, k)) # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0444\u0438\u043b\u044c\u043c\u0443         user_movie.append([user, movie])          N = len(user_movie)  def get_user_item_matrix(n_users, m_movies, ind_users, ind_movies, rating):     R = [[0] * m_movies for _ in range(n_users)]     N = len(ind_users)     for i in range(N):         R[ind_users[i]][ind_movies[i]] = rating[i]     R = np.array(R)     return R  R = get_user_item_matrix(n_users, m_movies, ind_users, ind_movies, rating)  pd.DataFrame(R, users, movies) <\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/382\/45d\/dea\/38245ddea8a6c226611b2b7d0d352343.png\" width=\"925\" height=\"397\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/382\/45d\/dea\/38245ddea8a6c226611b2b7d0d352343.png\"\/><\/figure>\n<p>\u041e\u0448\u0438\u0431\u043a\u0443 \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0430\u043a: <\/p>\n<pre><code class=\"python\">def MSE(R, U, V):     mse = 0     for ind in range(N):         i = ind_users[ind]         j = ind_movies[ind]         mse += ( R[i][j] - np.dot(U[i,:], V[:,j]) )**2 \/ N     return mse<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a c \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c step. \u0421\u0434\u0435\u043b\u0430\u0435\u043c n_iters \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code class=\"python\">def SVD(ind_users, ind_movies, R, d, step, n_iters):          # \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f     P = np.random.rand(R.shape[0], d)     Q = np.random.rand(d, R.shape[1])      start_mse = MSE(R, P, Q)          # \u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a     for n in range(n_iters):         ind = np.random.randint(0, N)         i = ind_users[ind]         j = ind_movies[ind]                  for k in range(0, d):             P[i, k] = P[i, k] + step * (R[i][j] - P[i, :] @ Q[:, j]) * Q[k, j]              Q[k, j] = Q[k, j] + step * (R[i][j] - P[i, :] @ Q[:, j]) * P[i, k]           mse = MSE(R, P, Q)     return P, Q, start_mse, mse  P, Q, start_mse, mse = SVD(ind_users, ind_movies, R, 3, 0.1, 3000) <\/code><\/pre>\n<pre><code class=\"python\">start_mse, mse  (22.327189007469947, 0.9592817343783187)<\/code><\/pre>\n<p>\u0421\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u043c user-item matrix<\/p>\n<pre><code class=\"python\">R_pred = np.zeros((R.shape[0], R.shape[1]))  for i in range(n_users):     for j in range(m_movies):         R_pred[i][j] = round(P[i,:] @ Q[:,j], 2)  pd.DataFrame(R_pred, users, movies)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/63a\/efc\/ef0\/63aefcef0d122ac07bdc2b61d6405d39.png\" width=\"914\" height=\"411\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/63a\/efc\/ef0\/63aefcef0d122ac07bdc2b61d6405d39.png\"\/><\/figure>\n<pre><code># \u0412\u044b\u0432\u043e\u0434 \u0435\u0449\u0435 \u0440\u0430\u0437 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f pd.DataFrame(R, users, movies)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4f5\/36e\/ba5\/4f536eba57b58e18e7baac7c9a14719c.png\" width=\"925\" height=\"413\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4f5\/36e\/ba5\/4f536eba57b58e18e7baac7c9a14719c.png\"\/><\/figure>\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\/751470\/\"> https:\/\/habr.com\/ru\/articles\/751470\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><strong>Collaborative Filtering<\/strong>\u00a0&#8212; \u043f\u043e\u0434\u0445\u043e\u0434, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u0445 \u043c\u0435\u0436\u0434\u0443 <strong>\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 (users)<\/strong> \u0438 <strong>\u0442\u043e\u0432\u0430\u0440\u043e\u043c (items)<\/strong>, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u0438\u043b\u0438 \u0442\u043e\u0432\u0430\u0440\u0430\u0445. <\/p>\n<p>\u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442 \u043d\u0430 \u0434\u0432\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438: <\/p>\n<ul>\n<li>\n<p><strong>\u042f\u0432\u043d\u043e\u0435<\/strong> <strong>\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435<\/strong>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0435\u0439\u0442\u0438\u043d\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u043e\u0432\u0430\u0440\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0435\u044f\u0432\u043d\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435.<\/strong> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0438\u043a, \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440 \u0438\u043b\u0438 \u043f\u043e\u043a\u0443\u043f\u043a\u0430 \u0442\u043e\u0432\u0430\u0440\u0430 \u043d\u0435 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0440\u0435\u0439\u0442\u0438\u043d\u0433\u0430.<\/p>\n<\/li>\n<\/ul>\n<p><strong>User-item matrix<\/strong>\u00a0\u2014 \u044d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 &#8212; \u0442\u043e\u0432\u0430\u0440, \u0430 \u043a\u0430\u0436\u0434\u0430\u044f \u044f\u0447\u0435\u0439\u043a\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438 \u0442\u043e\u0432\u0430\u0440\u043e\u043c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u044f\u0447\u0435\u0439\u043a\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043a\u0443\u043f\u0438\u043b \u0442\u043e\u0432\u0430\u0440, \u0438\u043b\u0438 \u043e\u0446\u0435\u043d\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043b \u0442\u043e\u0432\u0430\u0440\u0443. <strong>User-item matrix<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \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 \u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0442\u043e\u0432\u0430\u0440\u043e\u0432.  \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e <strong>user-item matrix<\/strong> &#8212; \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0438 \u0440\u0430\u0437\u0440\u044f\u0436\u0435\u043d\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430.  <\/p>\n<figure class=\"full-width\">\n<div><figcaption><strong>User-item matrix<\/strong>\u00a0<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442 <a href=\"https:\/\/translated.turbopages.org\/proxy_u\/en-ru.ru.0832cecd-64b5506e-d08cf623-74722d776562\/https\/en.wikipedia.org\/wiki\/Matrix_factorization_(recommender_systems)\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u0430\u0442\u0440\u0438\u0447\u043d\u0443\u044e \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e<\/u><\/a> (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <strong>user-item matrix<\/strong> \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043c\u0430\u0442\u0440\u0438\u0446 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0432\u0438\u0434\u0430). <\/p>\n<p>\u0427\u0430\u0441\u0442\u043e \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u0430\u044f \u0444\u0430\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u0433\u0434\u0435 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. <\/p>\n<p>\u0422\u0430\u043a \u0434\u0435\u043b\u043e \u043e\u0431\u0441\u0442\u043e\u0438\u0442 \u0441\u00a0<a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9C%D0%B5%D1%82%D0%BE%D0%B4_%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D1%8B%D1%85_%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%BD%D0%B5%D0%BD%D1%82\" rel=\"noopener noreferrer nofollow\"><u>\u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043d\u044b\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u043e\u043c (PCA)<\/u><\/a>\u00a0\u0438\u00a0<a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D0%B8%D0%BD%D0%B3%D1%83%D0%BB%D1%8F%D1%80%D0%BD%D0%BE%D0%B5_%D1%80%D0%B0%D0%B7%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\"><u>\u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e (SVD)<\/u><\/a>.<\/p>\n<p>\u0433\u0434\u0435 \u2014 <em>user-item matrix<\/em><strong>, <\/strong>  \u2014 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0441 \u043d\u0435\u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438,  \u0438  \u2014 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 .<\/p>\n<p>PCA \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0442\u0435\u0440\u044f\u0432 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0412\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u0432\u0435\u0434\u0435\u043d\u043e \u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044e SVD \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u043b\u0438 \u043a \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2014 \u044d\u0442\u043e <em>SVD<\/em> \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0443\u043c\u043c\u044b \u0432\u0437\u0430\u0438\u043c\u043d\u043e \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432 , \u0430 \u0441\u0430\u043c\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b  \u2014 \u0432 \u0432\u0438\u0434\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u043d\u0430 \u044d\u0442\u0438 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0441 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430\u043c\u0438 .<\/p>\n<p>\u041e\u0441\u0442\u0430\u0432\u0438\u0432 -\u043f\u0435\u0440\u0432\u044b\u0445 (\u0433\u043b\u0430\u0432\u043d\u044b\u0445) \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 () \u0432 SVD \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0438\u0435 \u043a  \u043f\u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9D%D0%BE%D1%80%D0%BC%D0%B0_%D0%BC%D0%B0%D1%82%D1%80%D0%B8%D1%86%D1%8B\" rel=\"noopener noreferrer nofollow\">\u043d\u043e\u0440\u043c\u0435 \u0424\u0440\u043e\u0431\u0435\u043d\u0438\u0443\u0441\u0430<\/a>.<\/p>\n<p>\u0417\u0430 &#171;\u0421\u043a\u0440\u044b\u0442\u044b\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u043c&#187; \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f SVD \u0438 PCA.<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 SVD \u0438 PCA.<\/p>\n<pre><code class=\"python\">import numpy as np from matplotlib import image from matplotlib import pyplot as plt import cv2<\/code><\/pre>\n<pre><code class=\"python\">img = image.imread(\"photo.jpg\") plt.imshow(img) plt.show()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0447\u0435\u0440\u043d\u043e-\u0431\u0435\u043b\u043e\u043c\u0443 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044e. <\/p>\n<pre><code class=\"python\">gray_img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) plt.imshow(gray_img, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<pre><code class=\"python\">gray_img.shape  (558, 563)<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c SVD \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 <\/p>\n<pre><code class=\"python\">U, lmbd, V = np.linalg.svd(gray_img) U.shape, lmbd.shape, V.shape  ((558, 558), (558,), (563, 563))<\/code><\/pre>\n<pre><code class=\"python\">S = np.zeros((U.shape[1], V.shape[0]))  S[ : U.shape[1], : U.shape[1]] = np.diag(lmbd) S.shape  (558, 563)<\/code><\/pre>\n<p>\u0412\u0435\u0440\u043d\u0435\u043c \u043a\u0430\u043a \u0431\u044b\u043b\u043e, \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c<\/p>\n<pre><code class=\"python\">plt.imshow(U @ S @ V, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 100 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">d = 100 U_crop = U[:, :d] S_crop = S[:d, :d] V_crop = V[:d, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c, \u0437\u0430\u0442\u043e \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u043b\u0435\u043d\u043e \u043f\u0430\u043c\u044f\u0442\u0438!<\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u044b\u0435 50 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<pre><code class=\"python\">d = 50 U_crop = U[:, :d] S_crop = S[:d, :d] V_crop = V[:d, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u041e\u0441\u0442\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0432\u044b\u0435 10 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<pre><code class=\"python\">d = 10 U_crop = U[:, :d] S_crop = S[:d, :d] V_crop = V[:d, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u0421\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0435 S \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e: \u0447\u0435\u043c \u0431\u043b\u0438\u0436\u0435 \u043a \u043d\u0430\u0447\u0430\u043b\u0443, \u0442\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432\u0430\u0436\u043d\u0435\u0435 \u0438 \u0441\u0438\u043b\u044c\u043d\u0435\u0435 \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f.  <\/p>\n<p>\u0423\u0431\u0435\u0440\u0435\u043c \u043f\u0435\u0440\u0432\u044b\u0435 5 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<pre><code>k = 5U_crop = U[:, k:] S_crop = S[k:, k:] V_crop = V[k:, :]  plt.imshow(U_crop @ S_crop @ V_crop, cmap='gray') plt.show()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u041a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0445\u0443\u0436\u0435.<\/p>\n<\/div>\n<\/details>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u043d\u0430\u0448\u0443 <em>user-item matrix<\/em> \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043c\u0430\u0442\u0440\u0438\u0446:<\/p>\n<p><strong>\u0422\u043e\u0433\u0434\u0430 \u2011a\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u00a0\u2014 \u044d\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u2011\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u2011\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u00a0\u2014 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0442\u0435 \u2011\u0433\u043e \u0442\u043e\u0432\u0430\u0440\u0430.<\/strong> <strong>\u0418\u0445 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 (\u0440\u0435\u0439\u0442\u0438\u043d\u0433) \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f:<\/strong><\/p>\n<p>\u041c\u0430\u0442\u0440\u0438\u0446\u044b  \u0438  \u043d\u0430\u0439\u0434\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435  \u0432\u043e\u0437\u044c\u043c\u0435\u043c  \u0431\u0435\u0437 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b:<\/p>\n<p>\u041f\u043e\u0441\u0447\u0438\u0442\u0430\u0432 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043f\u043e  \u0438 \u043f\u043e , \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0444\u043e\u0440\u043c\u0443\u043b\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432:<\/p>\n<p>k \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u0442 \u043e\u0442 1 \u0434\u043e d, \u0433\u0434\u0435 d &#8212; \u0447\u0438\u0441\u043b\u043e \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u041f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u041f\u0443\u0441\u0442\u044c \u043d\u0430\u043c \u0437\u0430\u0434\u0430\u043d\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0438 \u0438\u0445 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u043c \u0444\u0438\u043b\u044c\u043c\u0430\u043c. \u0417\u0430\u0434\u0430\u0447\u0430 &#8212; \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0435 \u044f\u0447\u0435\u0439\u043a\u0438 user-item matrix.<\/p>\n<pre><code class=\"python\">import numpy as np import pandas as pd<\/code><\/pre>\n<p>\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u0444\u0438\u043b\u044c\u043c\u044b:<\/p>\n<pre><code class=\"python\">k = 10 # \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430  movies = ['\u0424\u0430\u043d\u0442\u0430\u0437\u0438\u044f', '\u0412\u0410\u041b\u041b-\u0418', '\u041f\u0438\u043d\u043e\u043a\u043a\u0438\u043e', '\u0411\u0435\u043c\u0431\u0438' , '\u0428\u0440\u044d\u043a', '\u0414\u0430\u043c\u0431\u043e', '\u0421\u043f\u0430\u0441\u0430\u0442\u0435\u043b\u0438', '\u0413\u0435\u0440\u043a\u0443\u043b\u0435\u0441', '\u041a\u0443\u043d\u0433-\u0444\u0443 \u041f\u0430\u043d\u0434\u0430'] m_movies = len(movies)  users = ['\u0410\u043d\u0434\u0440\u0435\u0439', '\u0410\u043d\u044f', '\u0410\u043b\u0438\u0441\u0430', '\u0412\u0430\u043d\u044f', '\u041b\u0435\u0448\u0430', '\u041e\u043a\u0441\u0430\u043d\u0430', '\u0421\u0430\u0448\u0430', '\u041f\u0430\u0448\u0430', '\u0421\u0435\u043d\u044f', '\u0413\u0440\u0438\u0448\u0430']         n_users = len(users)<\/code><\/pre>\n<p>\u041e\u0446\u0435\u043d\u043a\u0438 \u0440\u0430\u0441\u043a\u0438\u0434\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u0421 \u0443\u0447\u0435\u0442\u043e\u043c \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u0440\u0430 user-movie \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u043b\u0430\u0441\u044c <\/p>\n<pre><code class=\"python\">RANDOMSEED = 42 np.random.seed(42)  N = np.random.randint(50, 60) # \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0446\u0435\u043d\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e  ind_users, ind_movies, rating = [], [], [] user_movie = [] # \u0447\u0442\u043e\u0431\u044b \u043f\u0430\u0440\u0430 user-movie \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u043b\u0438\u0441\u044c for _ in range(N):     user = np.random.randint(0, n_users)     movie = np.random.randint(0, m_movies)     if not [user, movie] in user_movie:         ind_users.append(user)         ind_movies.append(movie)         rating.append(np.random.randint(1, k)) # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0444\u0438\u043b\u044c\u043c\u0443         user_movie.append([user, movie])          N = len(user_movie)  def get_user_item_matrix(n_users, m_movies, ind_users, ind_movies, rating):     R = [[0] * m_movies for _ in range(n_users)]     N = len(ind_users)     for i in range(N):         R[ind_users[i]][ind_movies[i]] = rating[i]     R = np.array(R)     return R  R = get_user_item_matrix(n_users, m_movies, ind_users, ind_movies, rating)  pd.DataFrame(R, users, movies) <\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u041e\u0448\u0438\u0431\u043a\u0443 \u0431\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u0430\u043a: <\/p>\n<pre><code class=\"python\">def MSE(R, U, V):     mse = 0     for ind in range(N):         i = ind_users[ind]         j = ind_movies[ind]         mse += ( R[i][j] - np.dot(U[i,:], V[:,j]) )**2 \/ N     return mse<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a c \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0448\u0430\u0433\u043e\u043c step. \u0421\u0434\u0435\u043b\u0430\u0435\u043c n_iters \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code class=\"python\">def SVD(ind_users, ind_movies, R, d, step, n_iters):          # \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u0442\u0440\u0438\u0446 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f     P = np.random.rand(R.shape[0], d)     Q = np.random.rand(d, R.shape[1])      start_mse = MSE(R, P, Q)          # \u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a     for n in range(n_iters):         ind = np.random.randint(0, N)         i = ind_users[ind]         j = ind_movies[ind]                  for k in range(0, d):             P[i, k] = P[i, k] + step * (R[i][j] - P[i, :] @ Q[:, j]) * Q[k, j]              Q[k, j] = Q[k, j] + step * (R[i][j] - P[i, :] @ Q[:, j]) * P[i, k]           mse = MSE(R, P, Q)     return P, Q, start_mse, mse  P, Q, start_mse, mse = SVD(ind_users, ind_movies, R, 3, 0.1, 3000) <\/code><\/pre>\n<pre><code class=\"python\">start_mse, mse  (22.327189007469947, 0.9592817343783187)<\/code><\/pre>\n<p>\u0421\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u043c user-item matrix<\/p>\n<pre><code class=\"python\">R_pred = np.zeros((R.shape[0], R.shape[1]))  for i in range(n_users):     for j in range(m_movies):         R_pred[i][j] = round(P[i,:] @ Q[:,j], 2)  pd.DataFrame(R_pred, users, movies)<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<pre><code># \u0412\u044b\u0432\u043e\u0434 \u0435\u0449\u0435 \u0440\u0430\u0437 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f pd.DataFrame(R, users, movies)<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\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\/751470\/\"> https:\/\/habr.com\/ru\/articles\/751470\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-351037","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351037","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=351037"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/351037\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=351037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=351037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=351037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}