{"id":442986,"date":"2024-12-26T03:50:18","date_gmt":"2024-12-26T03:50:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=442986"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-12-26T03:50:18","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=442986","title":{"rendered":"<span>\u041c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435: \u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c K-means. \u0422\u0435\u043e\u0440\u0438\u044f \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u0421 \u043d\u0443\u043b\u044f<\/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\/w1560\/getpro\/habr\/upload_files\/859\/2c6\/7ca\/8592c67ca845654285ec2708054360c0.png\" width=\"857\" height=\"464\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/859\/2c6\/7ca\/8592c67ca845654285ec2708054360c0.png\"\/><\/figure>\n<p>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0440\u0430\u0437\u0431\u043e\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u043d\u0430 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435.<\/p>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435: \u0438\u0434\u0435\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u0430\u043a \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043a\u0438 \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c Python \u0438 \u0440\u0430\u0437\u0431\u043e\u0440 \u043a\u043e\u0434\u0430.<\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c K-means \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 k \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0442\u0430\u043a\u0438\u0445, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 \u0441 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u043c \u0446\u0435\u043d\u0442\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u0426\u0435\u043b\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u2014 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u043e\u0447\u0435\u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043e\u0442 \u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0431\u0435\u0437 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f), \u0442\u043e \u0435\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0430\u043c, \u0431\u0435\u0437 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0438. \u0423\u0447\u0435\u043d\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0430\u043c \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u043d\u043e \u0443\u0447\u0435\u043d\u0438\u043a \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u043c\u0443, \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u043d\u0430 k \u043a\u043b\u0430\u0441\u0441\u043e\u0432). \u0417\u0430\u0442\u0435\u043c \u0443\u0447\u0435\u043d\u0438\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e \u0438\u0445 \u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438, \u043d\u0430 k \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0431\u043b\u0438\u0437\u043a\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0443\u0447\u0435\u043d\u0438\u043a \u043e\u0442\u043d\u043e\u0441\u0438\u0442 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443.<\/p>\n<h2>\u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u041f\u0443\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 n \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 (\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432) <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_i = (x_{i1}, ..., x_{ik})\" alt=\"x_i = (x_{i1}, ..., x_{ik})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eca\/7a7\/630\/eca7a7630d7157d12d1a409c5361d96c.svg\" width=\"153\" height=\"22\"\/>, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"i=1,...,n\" alt=\"i=1,...,n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/954\/f0a\/939\/954f0a9395504216a37dc31defdc81a8.svg\" width=\"98\" height=\"20\"\/>, k &#8212; \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u2014 \u0446\u0435\u043d\u0442\u0440\u044b \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p><strong>\u0418\u0434\u0435\u044f \u043c\u0435\u0442\u043e\u0434\u0430 K-means<\/strong>. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 k, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u0445\u043e\u0442\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f k \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u0438 \u0446\u0435\u043d\u0442\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c\u0443 \u0446\u0435\u043d\u0442\u0440\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f (\u043e\u0431\u044b\u0447\u043d\u043e \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e) \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043a\u0430\u0436\u0434\u044b\u043c \u0446\u0435\u043d\u0442\u0440\u043e\u043c.<\/p>\n<p>\u0426\u0435\u043d\u0442\u0440\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443. \u042d\u0442\u043e\u0442 \u0448\u0430\u0433 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0446\u0435\u043d\u0442\u0440\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0443\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u0434\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u043c \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0438\u0431\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439.<\/p>\n<p>\u0421\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440\u044b \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u043f\u043e\u0442\u043e\u043c, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432, \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 (\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443).<\/p>\n<h2>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u0447\u0435\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b<\/h2>\n<p>\u041d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 (\u043a\u043b\u0430\u0441\u0441\u0443) \u043e\u043d\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f. \u041c\u043e\u0434\u0435\u043b\u044c\u044e KNN \u0431\u0443\u0434\u0443\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u043e\u0447\u0435\u043a \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043d\u044b\u0435 \u0432\u0441\u0435\u043c \u0442\u043e\u0447\u043a\u0430\u043c \u0438\u0445 \u043c\u0435\u0442\u043a\u0438.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043e\u0431\u0449\u0438\u0445 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044f\u0445 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043f\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0443, \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0432\u0438\u0434\u043d\u043e, \u0432 \u043a\u0430\u043a\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0446\u0435\u043d\u0442\u0440\u044b \u044d\u0442\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0441\u0435\u043c\u0438 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0420\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a-\u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0434\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<p> \u0415\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u044d\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"d(a, b) = \\sqrt{\\sum_{i = 1}^{n} (a_i - b_i)^2}\" alt=\"d(a, b) = \\sqrt{\\sum_{i = 1}^{n} (a_i - b_i)^2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6a3\/29f\/3f0\/6a329f3f0a56758ce808598bc886ef48.svg\" width=\"208\" height=\"63\"\/><\/p>\n<p>a \u0438 b \u2014 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432), <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"a_i\" alt=\"a_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/965\/0ea\/546\/9650ea546a6da631206fc07936d18cd8.svg\" width=\"17\" height=\"15\"\/> \u0438 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"b_i\" alt=\"b_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/661\/2e5\/4f7\/6612e54f7d8654204a344edea5ff969b.svg\" width=\"15\" height=\"20\"\/> &#8212; \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 (\u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438), n \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0435 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442).<\/p>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0442\u0430\u043a\u043e\u0432\u043e, \u0447\u0442\u043e \u043e\u043d \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0439 \u0442\u043e\u0447\u0435\u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"S = \\sum_{i=1}^{n} \\sum_{j = 1}^{p} (x_{ij} - c_{kj})^2\" alt=\"S = \\sum_{i=1}^{n} \\sum_{j = 1}^{p} (x_{ij} - c_{kj})^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a9f\/e41\/744\/a9fe41744e9a8ebb320ba8da55a5b344.svg\" width=\"194\" height=\"61\"\/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"n\" alt=\"n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/442\/b30\/874\/442b30874167ff7b35ca5ee9fa9fe069.svg\" width=\"12\" height=\"12\"\/> \u2014 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"p\" alt=\"p\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/756\/5e4\/9b2\/7565e49b26ba39166e4327a4b65e8504.svg\" width=\"11\" height=\"15\"\/> \u2014 \u0447\u0438\u0441\u043b\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 (\u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442), <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"c\" alt=\"c\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/9a2\/83d\/37e\/9a283d37e55b1eb07d50a7c46904a7bb.svg\" width=\"9\" height=\"12\"\/> \u2014 \u0446\u0435\u043d\u0442\u0440 k-\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_i\" alt=\"x_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bc2\/2a5\/b8e\/bc22a5b8e043e434f2cb08afc61c7309.svg\" width=\"18\" height=\"15\"\/> &#8212; i-\u044f \u0442\u043e\u0447\u043a\u0430 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_{ij}\" alt=\"x_{ij}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/244\/073\/cf9\/244073cf9ffb10be308f65a6b115e97b.svg\" width=\"24\" height=\"17\"\/> &#8212; j-\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_i\" alt=\"x_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/761\/5c2\/7d4\/7615c27d49044b6ac8bce71324acb120.svg\" width=\"18\" height=\"15\"\/>. \u042d\u0442\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u0438 \u0435\u0441\u0442\u044c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e, \u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/673\/4d2\/ba9\/6734d2ba925cd771c78ba7c1d0603966.png\" alt=\"\u041a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0447\u0435\u0440\u043d\u044b\u0435 \u2014 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445\" title=\"\u041a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0447\u0435\u0440\u043d\u044b\u0435 \u2014 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445\" width=\"480\" height=\"270\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/673\/4d2\/ba9\/6734d2ba925cd771c78ba7c1d0603966.png\"\/><\/p>\n<div><figcaption>\u041a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0447\u0435\u0440\u043d\u044b\u0435 \u2014 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0435\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0435 \u0432\u0441\u0435\u0433\u043e, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u041a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u2014 \u044d\u0442\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435, \u0447\u0435\u0440\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u2014 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 (\u043c\u0435\u0442\u043a\u0430 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0439 \u043a\u0440\u0430\u0441\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438).<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u043a\u0438, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443. \u0421\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0442\u043e\u0447\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u043f\u043e\u0442\u043e\u043c \u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula\" source=\"C_{new, j} = \\frac{1}{n} \\sum_{i = 1}^{n} x_{ij}, j = 1,...,p\" alt=\"C_{new, j} = \\frac{1}{n} \\sum_{i = 1}^{n} x_{ij}, j = 1,...,p\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8d6\/164\/023\/8d61640231ce06ece6e29bf347a92216.svg\" width=\"260\" height=\"57\"\/><\/p>\n<p>p \u2014 \u0447\u0438\u0441\u043b\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442, C \u2014 \u0446\u0435\u043d\u0442\u0440 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, j \u2014 \u043d\u043e\u043c\u0435\u0440 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b (\u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430) \u043e\u0431\u044a\u0435\u043a\u0442\u0430, n \u2014 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 C, <img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"x_{ij}\" alt=\"x_{ij}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ca3\/b7e\/dc6\/ca3b7edc6936fb1c2ea830615e823b81.svg\" width=\"24\" height=\"17\"\/> &#8212; j-\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 i-\u0439 \u0442\u043e\u0447\u043a\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 C. \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b j.<\/p>\n<h2>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/h2>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c K-means \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044f. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0441\u0442\u0440\u044f\u0442\u044c \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0435, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0435\u043c \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0446\u0435\u043d\u0442\u0440\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u044b \u0437\u0430\u043d\u043e\u0432\u043e.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 k, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \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 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0446\u0435\u043d\u0442\u0440\u043e\u0432. \u0420\u0430\u0437\u043d\u044b\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c.<\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c K-means \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438.<\/p>\n<p>K-means \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c\u0438 \u043d\u0430\u0431\u043e\u0440\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c K-means \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 K-means \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u044b \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e make_blobs \u0438\u0437 sklearn. \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u0442\u043e\u0447\u0435\u043a (\u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432), \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442) \u0438 \u0447\u0438\u0441\u043b\u043e \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<pre><code class=\"python\">from sklearn.datasets import make_blobs from matplotlib import pyplot as plt  data, labels = make_blobs(n_samples=20, centers=2, n_features=2, random_state=0) data = data.round(2)  print(list(labels)) points = [tuple(point) for point in data] print(points)  x1_list = data[labels==0, 0] x2_list = data[labels==1, 0] y1_list = data[labels==0, 1] y2_list = data[labels==1, 1]  plt.scatter(x=x1_list, y=y1_list, color='red') plt.scatter(x=x2_list, y=y2_list, color='green') plt.show()<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u043e\u0447\u0435\u043a \u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0435\u0442\u043e\u043a \u2014 \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u0430\u044f \u0442\u043e\u0447\u043a\u0430 (0 \u0438\u043b\u0438 1 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432). \u0414\u0435\u043b\u0430\u0435\u043c \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0447\u0435\u043a \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c. \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3a9\/442\/519\/3a9442519c80911db06eaf3eafceedfc.png\" alt=\"\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0432\u0435\u0440\u043a\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u043a, \u0441\u043d\u0438\u0437\u0443 \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0447\u0435\u043a\" title=\"\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0432\u0435\u0440\u043a\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u043a, \u0441\u043d\u0438\u0437\u0443 \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0447\u0435\u043a\" width=\"407\" height=\"223\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3a9\/442\/519\/3a9442519c80911db06eaf3eafceedfc.png\"\/><\/p>\n<div><figcaption>\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0432\u0435\u0440\u043a\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u043a, \u0441\u043d\u0438\u0437\u0443 \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0447\u0435\u043a<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430. \u041c\u0430\u0441\u0441\u0438\u0432 data \u2014 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u0435\u0440\u0432\u0430\u044f \u043e\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0447\u0435\u043a, \u0441\u0430\u043c\u0438 \u0442\u043e\u0447\u043a\u0438 (\u043e\u0431\u044a\u0435\u043a\u0442\u044b), \u0432\u0442\u043e\u0440\u0430\u044f \u043e\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u043e\u0447\u0435\u043a, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u0442\u043e\u0447\u0435\u043a, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 (\u043a 0 \u0438\u043b\u0438 \u043a 1), \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a 0 \u0438\u043b\u0438 \u043a 1 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443 (\u043a \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 x \u0438\u043b\u0438 \u043a \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 y).<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0438\u0441\u0443\u0435\u043c \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b7a\/7d9\/908\/b7a7d9908f956621d9cc8ec22255f9bc.png\" alt=\"\u0420\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438\" title=\"\u0420\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438\" width=\"545\" height=\"401\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b7a\/7d9\/908\/b7a7d9908f956621d9cc8ec22255f9bc.png\"\/><\/p>\n<div><figcaption>\u0420\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c90\/d60\/a0d\/c90d60a0d7956ba499f4cbc4205d5b35.png\" alt=\"\u041d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438\" title=\"\u041d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438\" width=\"556\" height=\"400\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c90\/d60\/a0d\/c90d60a0d7956ba499f4cbc4205d5b35.png\"\/><\/p>\n<div><figcaption>\u041d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0432\u0438\u0434\u043d\u043e 2 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f (\u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0438 \u0437\u0435\u043b\u0435\u043d\u044b\u043c, \u0440\u0438\u0441\u0443\u043d\u043e\u043a \u0441\u0432\u0435\u0440\u0445\u0443). \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0432\u0430 \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u043c\u0438 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438, \u043f\u0435\u0440\u0432\u044b\u0439 \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 (1, 5), \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 (2.5, 1). \u041d\u043e \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u043b\u0438, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0435\u0433\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 (\u0440\u0438\u0441\u0443\u043d\u043e\u043a \u0441\u043d\u0438\u0437\u0443), \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u0445 3, 4 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435. \u041d\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u0430\u043b\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u0435\u043c \u0431\u044b\u043b\u043e \u0431\u044b \u043b\u0435\u0433\u0447\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u044b.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u0434\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0435\u043d\u0442\u0440\u043e\u0432 k \u0438 \u0442\u043e\u0447\u043a\u0438 \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0427\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0430\u0432\u043d\u043e 2, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u043f\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0443.<\/p>\n<pre><code class=\"python\">target_labels = [0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0] points = [(1.84, 3.56), (1.01, -0.52), (1.29, 3.45), (1.93, 4.15),           (2.84, 3.33), (1.42, 4.64), (0.87, 4.71), (2.21, 1.28),           (4.33, -0.56), (-1.58, 4.96), (2.1, 0.71), (1.17, -1.08),           (3.59, 2.37), (1.12, 5.76), (1.67, 0.6), (3.29, 2.1),           (1.71, 1.05), (0.35, 2.85), (2.47, 4.1), (1.74, 4.43)]  centers = [(1, 5), (2.5, 1)]  # \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043e\u043d\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043f\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0443<\/code><\/pre>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0435\u043d\u0442\u0440\u0430 \u043e\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043a\u0438.<\/p>\n<pre><code class=\"python\">def euclidean_distances_to_centers(point):     dists = []      for center in centers:         distance = 0          for i in range(2):             distance += (point[i] - center[i]) ** 2          dists.append(distance)      return dists<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0446\u0435\u043d\u0442\u0440\u0443 \u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a dists.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441.<\/p>\n<pre><code class=\"python\">def get_min_item_idx(distances):  # \u043d\u0430\u0439\u0442\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442     min_dist, min_item_idx = 1000000, 0      for idx, dist in enumerate(distances):         if dist &lt; min_dist:             min_dist = dist             min_item_idx = idx      return min_item_idx<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0447\u0435\u043a \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a clusters.<\/p>\n<pre><code class=\"python\">clusters = [[], []]  def update_centers():     for cluster_idx, cluster in enumerate(clusters):         cluster_mean_value = [0, 0]          for point in cluster:             for i, feature in enumerate(point):                 cluster_mean_value[i] += feature          for i in range(2):             cluster_mean_value[i] = cluster_mean_value[i] \/ len(cluster)          centers[cluster_idx] = cluster_mean_value<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 (\u0441\u043f\u0438\u0441\u043a\u0443 \u0442\u043e\u0447\u0435\u043a), \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0437\u0430\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u0442\u0440\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e cluster_mean_value. \u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 \u0442\u043e\u0447\u043a\u0438, \u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0443 \u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438. \u041f\u043e\u0442\u043e\u043c \u0434\u0435\u043b\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0441\u0443\u043c\u043c\u044b \u043d\u0430 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 \u2014 \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u043d\u043e\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0446\u0438\u043a\u043b \u0434\u043b\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432.<\/p>\n<pre><code class=\"python\">labels = []  for _ in range(100):     clusters = [[], []]     labels = []      for point in points:         dists = euclidean_distances_to_centers(point)         min_item_idx = get_min_item_idx(dists)  # \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u043b\u0430\u0441\u0440\u0435\u0440\u0430         clusters[min_item_idx].append(point)  # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u0447\u043a\u0443 \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440         labels.append(min_item_idx)      update_centers()  print(labels)<\/code><\/pre>\n<pre><code>output: [0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0]<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 \u0437\u0430\u043d\u043e\u0432\u043e, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438, \u043f\u043e\u0442\u043e\u043c, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f, \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c \u0446\u0435\u043d\u0442\u0440\u044b. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a\u0438\u0435 \u043c\u0435\u0442\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c.<\/p>\n<p>\u042d\u0442\u043e \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u0414\u0430\u043b\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435, \u043a\u0430\u043a\u043e\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"python\">import numpy as np from matplotlib import pyplot as plt  data = np.array(points) labels = np.array(labels)  x1_list = data[labels==0, 0] x2_list = data[labels==1, 0] y1_list = data[labels==0, 1] y2_list = data[labels==1, 1]  plt.scatter(x=x1_list, y=y1_list, color='red') plt.scatter(x=x2_list, y=y2_list, color='green') plt.show()<\/code><\/pre>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0447\u0442\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d78\/866\/abc\/d78866abcd1f86d923d578c78a37b784.png\" alt=\"\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445\" title=\"\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445\" width=\"577\" height=\"410\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d78\/866\/abc\/d78866abcd1f86d923d578c78a37b784.png\"\/><\/p>\n<div><figcaption>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/figcaption><\/div>\n<\/figure>\n<h2>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445. \u041f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<pre><code class=\"python\">def euclidean(point1, point2):     return sum([(point1[i] - point2[i]) ** 2 for i in range(len(point1))])   def euclidean_distances(cur_point, points):     dists = []      for point in points:         dists.append(euclidean(cur_point, point))      return dists<\/code><\/pre>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441. \u0414\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432.<\/p>\n<pre><code class=\"python\">class KMeans:     def __init__(self, features_num):         self.features_num = features_num         self.centers = []         self.clusters = [[] for _ in range(features_num)]<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u0430\u0435\u043c 2 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u044b.<\/p>\n<pre><code class=\"python\">def set_centers(self, centers):     self.centers = centers  def init_centers(self, points, k):     min_value = np.min(points, axis=0) * 100     max_value = np.max(points, axis=0) * 100     self.centers = []      for _ in range(k):         x = randint(min_value[0], max_value[0]) \/ 100         y = randint(min_value[1], max_value[1]) \/ 100         self.centers.append([x, y])<\/code><\/pre>\n<p>\u0426\u0435\u043d\u0442\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432 \u0442\u043e\u0447\u043a\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0438 \u043c\u043e\u0434\u0443\u043b\u0438.<\/p>\n<pre><code class=\"python\">import numpy as np from random import randint<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432. \u0422\u0443\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0431\u044b\u043b\u043e.<\/p>\n<pre><code class=\"python\">def _update_centers_(self):     for cluster_idx, cluster in enumerate(self.clusters):         cluster_mean_value = [0, 0]              for point in cluster:             for i, feature in enumerate(point):                 cluster_mean_value[i] += feature              for i in range(2):             cluster_mean_value[i] = cluster_mean_value[i] \/ len(cluster)              self.centers[cluster_idx] = cluster_mean_value<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0447\u0442\u0438 \u0442\u043e\u0439 \u0436\u0435. \u0415\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0443\u0431\u0440\u0430\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e min_dist \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"python\"># \u043d\u0430\u0439\u0442\u0438 \u0438\u043d\u0434\u0435\u043a\u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 def get_min_item_idx(distances):     min_item_idx = 0      for idx, dist in enumerate(distances):         if dist &lt; distances[min_item_idx]:             min_item_idx = idx      return min_item_idx<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u0435\u0442\u043e\u0434 fit, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u0442\u0440\u043e\u0432.<\/p>\n<pre><code class=\"python\">def fit(self, points, epochs):     labels = []      for _ in range(epochs):         self.clusters = [[] for _ in range(self.features_num)]         labels = []          for point in points:             dists = euclidean_distances(point, self.centers)             min_item_idx = get_min_item_idx(dists)  # \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u043b\u0430\u0441\u0440\u0435\u0440\u0430             self.clusters[min_item_idx].append(point)             labels.append(min_item_idx)          self._update_centers_()      return self.clusters, labels<\/code><\/pre>\n<p>\u0422\u0443\u0442 \u0442\u043e\u0436\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0441\u043f\u0438\u0441\u043a\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u043c\u0435\u0442\u043e\u043a \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c.<\/p>\n<pre><code class=\"python\">kmeans = KMeans(features_num=2) kmeans.set_centers(centers) clusters, labels = kmeans.fit(points, 10)  print(labels)<\/code><\/pre>\n<pre><code>output: [0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0]<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041c\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438 \u0442\u0435\u043e\u0440\u0438\u044e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u2014 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0441\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u0438 \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438. \u0421\u0434\u0435\u043b\u0430\u043b\u0438 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438, \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u043d\u0443\u043b\u044f \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c python, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u043b\u0438 \u043a\u043e\u0434, \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u043c \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u0443\u0440\u043e\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0438 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u043c \u0441 \u043d\u0443\u043b\u044f. \u0422\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u043e\u0432 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043e\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043a \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0432 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p><a href=\"https:\/\/github.com\/neuromancertdi\/tdi-project\/tree\/main\/%D0%9C%D0%B0%D1%88%D0%B8%D0%BD%D0%BD%D0%BE%D0%B5%20%D0%BE%D0%B1%D1%83%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\/KMeans\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430<\/a> \u043d\u0430 \u043f\u0430\u043f\u043a\u0443 \u0441 \u043a\u043e\u0434\u043e\u043c \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0413\u0438\u0442\u0425\u0430\u0431.<\/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\/868542\/\"> https:\/\/habr.com\/ru\/articles\/868542\/<\/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>\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435, \u0434\u043e\u0440\u043e\u0433\u0438\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0440\u0430\u0437\u0431\u043e\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u043d\u0430 \u043d\u0438\u0437\u043a\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435.<\/p>\n<p>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435: \u0438\u0434\u0435\u044f \u043c\u0435\u0442\u043e\u0434\u0430, \u043a\u0430\u043a \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043a\u0438 \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0430 \u0447\u0438\u0441\u0442\u043e\u043c Python \u0438 \u0440\u0430\u0437\u0431\u043e\u0440 \u043a\u043e\u0434\u0430.<\/p>\n<h2>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c K-means \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0430 \u043d\u0430 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 k \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0442\u0430\u043a\u0438\u0445, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 \u0441 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u043c \u0446\u0435\u043d\u0442\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u0426\u0435\u043b\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u2014 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0442\u043e\u0447\u0435\u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043e\u0442 \u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0431\u0435\u0437 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f), \u0442\u043e \u0435\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u0430\u043c, \u0431\u0435\u0437 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0438. \u0423\u0447\u0435\u043d\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u0430\u043c \u043e\u0442\u043d\u0435\u0441\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c, \u043d\u043e \u0443\u0447\u0435\u043d\u0438\u043a \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u044d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0435\u043c\u0443, \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b (\u043d\u0430 k \u043a\u043b\u0430\u0441\u0441\u043e\u0432). \u0417\u0430\u0442\u0435\u043c \u0443\u0447\u0435\u043d\u0438\u043a \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e \u0438\u0445 \u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438, \u043d\u0430 k \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0431\u043b\u0438\u0437\u043a\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0443\u0447\u0435\u043d\u0438\u043a \u043e\u0442\u043d\u043e\u0441\u0438\u0442 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443.<\/p>\n<h2>\u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p>\u041f\u0443\u0441\u0442\u044c \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 n \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 (\u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432) , , k &#8212; \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. \u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u2014 \u0446\u0435\u043d\u0442\u0440\u044b \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p><strong>\u0418\u0434\u0435\u044f \u043c\u0435\u0442\u043e\u0434\u0430 K-means<\/strong>. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 k, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u0445\u043e\u0442\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f k \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u0438 \u0446\u0435\u043d\u0442\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c\u0443 \u0446\u0435\u043d\u0442\u0440\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f (\u043e\u0431\u044b\u0447\u043d\u043e \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e) \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043a\u0430\u0436\u0434\u044b\u043c \u0446\u0435\u043d\u0442\u0440\u043e\u043c.<\/p>\n<p>\u0426\u0435\u043d\u0442\u0440\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a, \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443. \u042d\u0442\u043e\u0442 \u0448\u0430\u0433 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0446\u0435\u043d\u0442\u0440\u044b \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0443\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0438\u043b\u0438 \u0434\u043e \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u044f \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438. \u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u043c \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0438\u0431\u043e \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0435\u0439.<\/p>\n<p>\u0421\u0443\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0439\u0442\u0438 \u0446\u0435\u043d\u0442\u0440\u044b \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u043f\u043e\u0442\u043e\u043c, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432, \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u0443\u0442\u0435\u043c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 (\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443).<\/p>\n<h2>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u0447\u0435\u043a \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b<\/h2>\n<p>\u041d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 (\u043a\u043b\u0430\u0441\u0441\u0443) \u043e\u043d\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f. \u041c\u043e\u0434\u0435\u043b\u044c\u044e KNN \u0431\u0443\u0434\u0443\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0430 \u0442\u043e\u0447\u0435\u043a \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043d\u044b\u0435 \u0432\u0441\u0435\u043c \u0442\u043e\u0447\u043a\u0430\u043c \u0438\u0445 \u043c\u0435\u0442\u043a\u0438.<\/p>\n<p>\u0417\u0430\u0434\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438, \u043d\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u043d\u0430 \u043a\u0430\u043a\u0438\u0445-\u0442\u043e \u043e\u0431\u0449\u0438\u0445 \u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044f\u0445 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e. \u041c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043f\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0443, \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0432\u0438\u0434\u043d\u043e, \u0432 \u043a\u0430\u043a\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u0446\u0435\u043d\u0442\u0440\u044b \u044d\u0442\u0438\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u0435\u0439.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0432\u0441\u0435\u043c\u0438 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0420\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0432 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a-\u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0434\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<p> \u0415\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u044d\u0442\u043e\u0439 \u0444\u043e\u0440\u043c\u0443\u043b\u0435:<\/p>\n<p>a \u0438 b \u2014 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0432\u0435\u043a\u0442\u043e\u0440\u044b \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432),  \u0438  &#8212; \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 (\u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438), n \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0435 (\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442).<\/p>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0442\u0430\u043a\u043e\u0432\u043e, \u0447\u0442\u043e \u043e\u043d \u0441\u0442\u0440\u0435\u043c\u0438\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0443\u043c\u043c\u0443 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0439 \u0442\u043e\u0447\u0435\u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043e\u0442 \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432:<\/p>\n<p> \u2014 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435,  \u2014 \u0447\u0438\u0441\u043b\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 (\u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442),  \u2014 \u0446\u0435\u043d\u0442\u0440 k-\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430,  &#8212; i-\u044f \u0442\u043e\u0447\u043a\u0430 \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435,  &#8212; j-\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 . \u042d\u0442\u0430 \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u043f\u043e \u0441\u0443\u0442\u0438 \u0438 \u0435\u0441\u0442\u044c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e, \u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445.<\/p>\n<figure class=\"\">\n<div><figcaption>\u041a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0447\u0435\u0440\u043d\u044b\u0435 \u2014 \u0442\u043e\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0438 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0435\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0435 \u0432\u0441\u0435\u0433\u043e, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430. \u041a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u2014 \u044d\u0442\u043e \u043a\u0440\u0430\u0441\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0435, \u0447\u0435\u0440\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u2014 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u0436\u0434\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 (\u043c\u0435\u0442\u043a\u0430 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0439 \u043a\u0440\u0430\u0441\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438).<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u043a\u0438, \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443. \u0421\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u0442\u043e\u0447\u043a\u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u043f\u043e\u0442\u043e\u043c \u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u043e\u0431\u0449\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a:<\/p>\n<p>p \u2014 \u0447\u0438\u0441\u043b\u043e \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442, C \u2014 \u0446\u0435\u043d\u0442\u0440 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, j \u2014 \u043d\u043e\u043c\u0435\u0440 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b (\u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430) \u043e\u0431\u044a\u0435\u043a\u0442\u0430, n \u2014 \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435 C,  &#8212; j-\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430 i-\u0439 \u0442\u043e\u0447\u043a\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 C. \u041d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b j.<\/p>\n<h2>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430<\/h2>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c K-means \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0430 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u043e\u0433\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044f. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0441\u0442\u0440\u044f\u0442\u044c \u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c \u043c\u0438\u043d\u0438\u043c\u0443\u043c\u0435, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0435\u043c \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0446\u0435\u043d\u0442\u0440\u043e\u0432. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043d\u0442\u0440\u044b \u0437\u0430\u043d\u043e\u0432\u043e.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 k, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \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 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432.<\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0446\u0435\u043d\u0442\u0440\u043e\u0432. \u0420\u0430\u0437\u043d\u044b\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u0430\u0437\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c.<\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c K-means \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438.<\/p>\n<p>K-means \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c\u0438 \u043d\u0430\u0431\u043e\u0440\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c K-means \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430\u0445 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 K-means \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0449\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0442\u0449\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>\u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u044b \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u043e\u0434\u043d\u043e\u0442\u0438\u043f\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e make_blobs \u0438\u0437 sklearn. \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u0442\u043e\u0447\u0435\u043a \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u0442\u043e\u0447\u0435\u043a (\u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432), \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (\u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442) \u0438 \u0447\u0438\u0441\u043b\u043e \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b.<\/p>\n<pre><code class=\"python\">from sklearn.datasets import make_blobs from matplotlib import pyplot as plt  data, labels = make_blobs(n_samples=20, centers=2, n_features=2, random_state=0) data = data.round(2)  print(list(labels)) points = [tuple(point) for point in data] print(points)  x1_list = data[labels==0, 0] x2_list = data[labels==1, 0] y1_list = data[labels==0, 1] y2_list = data[labels==1, 1]  plt.scatter(x=x1_list, y=y1_list, color='red') plt.scatter(x=x2_list, y=y2_list, color='green') plt.show()<\/code><\/pre>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u043e\u0447\u0435\u043a \u0438 \u043e\u0434\u043d\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043c\u0435\u0442\u043e\u043a \u2014 \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u0430\u044f \u0442\u043e\u0447\u043a\u0430 (0 \u0438\u043b\u0438 1 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0446\u0435\u043d\u0442\u0440\u043e\u0432). \u0414\u0435\u043b\u0430\u0435\u043c \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0447\u0435\u043a \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u043c. \u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0444\u0430\u0439\u043b.<\/p>\n<figure class=\"\">\n<div><figcaption>\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421\u0432\u0435\u0440\u043a\u0443 \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u0435\u0442\u043e\u043a, \u0441\u043d\u0438\u0437\u0443 \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u043e\u0447\u0435\u043a<\/figcaption><\/div>\n<\/figure>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u0430\u0441\u0441\u0438\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430. \u041c\u0430\u0441\u0441\u0438\u0432 data \u2014 \u0434\u0432\u0443\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u0435\u0440\u0432\u0430\u044f \u043e\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u043e\u0447\u0435\u043a, \u0441\u0430\u043c\u0438 \u0442\u043e\u0447\u043a\u0438 (\u043e\u0431\u044a\u0435\u043a\u0442\u044b), \u0432\u0442\u043e\u0440\u0430\u044f \u043e\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u043e\u0447\u0435\u043a, \u0442\u043e \u0435\u0441\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442 \u0442\u043e\u0447\u0435\u043a, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 (\u043a 0 \u0438\u043b\u0438 \u043a 1), \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a 0 \u0438\u043b\u0438 \u043a 1 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443 (\u043a \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 x \u0438\u043b\u0438 \u043a \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435 y).<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0438\u0441\u0443\u0435\u043c \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435.<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u0420\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438<\/figcaption><\/div>\n<\/figure>\n<figure class=\"full-width\">\n<div><figcaption>\u041d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0432\u0438\u0434\u043d\u043e 2 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441\u043a\u043e\u043f\u043b\u0435\u043d\u0438\u044f (\u043a\u0440\u0430\u0441\u043d\u044b\u043c \u0438 \u0437\u0435\u043b\u0435\u043d\u044b\u043c, \u0440\u0438\u0441\u0443\u043d\u043e\u043a \u0441\u0432\u0435\u0440\u0445\u0443). \u041c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0432\u0430 \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u043c\u0438 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438, \u043f\u0435\u0440\u0432\u044b\u0439 \u0441 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0430\u043c\u0438 (1, 5), \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 (2.5, 1). \u041d\u043e \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043d\u0435 \u0437\u043d\u0430\u043b\u0438, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0435\u0433\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 (\u0440\u0438\u0441\u0443\u043d\u043e\u043a \u0441\u043d\u0438\u0437\u0443), \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u0445 3, 4 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0435. \u041d\u043e \u0437\u0434\u0435\u0441\u044c \u043c\u0430\u043b\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u0435\u043c \u0431\u044b\u043b\u043e \u0431\u044b \u043b\u0435\u0433\u0447\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u0438\u0445 \u0446\u0435\u043d\u0442\u0440\u044b.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u0434\u0430\u0435\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0435\u043d\u0442\u0440\u043e\u0432 k \u0438 \u0442\u043e\u0447\u043a\u0438 \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0427\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0440\u0430\u0432\u043d\u043e 2, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u043f\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0443.<\/p>\n<pre><code class=\"python\">target_labels = [0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0] points = [(1.84, 3.56), (1.01, -0.52), (1.29, 3.45), (1.93, 4.15),           (2.84, 3.33), (1.42, 4.64), (0.87, 4.71), (2.21, 1.28),           (4.33, -0.56), (-1.58, 4.96), (2.1, 0.71), (1.17, -1.08),           (3.59, 2.37), (1.12, 5.76), (1.67, 0.6), (3.29, 2.1),           (1.71, 1.05), (0.35, 2.85), (2.47, 4.1), (1.74, 4.43)]  centers = [(1, 5), (2.5, 1)]  # \u0446\u0435\u043d\u0442\u0440\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043e\u043d\u0438 \u0432\u044b\u0431\u0440\u0430\u043d\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043f\u043e \u0433\u0440\u0430\u0444\u0438\u043a\u0443<\/code><\/pre>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0446\u0435\u043d\u0442\u0440\u0430 \u043e\u0442 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u043e\u0447\u043a\u0438.<\/p>\n<pre><code class=\"python\">def euclidean_distances_to_centers(point):     dists = []      for center in centers:         distance = 0          for i in range(2):             distance += (point[i] - center[i]) ** 2          dists.append(distance)      return dists<\/code><\/pre>\n<p>\u041f\u0440\u043e\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0446\u0435\u043d\u0442\u0440\u0443 \u0438 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u0435, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a dists.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0442\u043e \u0435\u0441\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441.<\/p>\n<pre><code class=\"python\">def get_min_item_idx(distances):  # \u043d\u0430\u0439\u0442\u0438 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442     min_dist, min_item_idx = 1000000, 0      for idx, dist in enumerate(distances):         if dist &lt; min_dist:             min_dist = dist             min_item_idx = idx      return min_item_idx<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u0435\u043b\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u0447\u0435\u043a \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c, \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u044d\u0442\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a clusters.<\/p>\n<pre><code class=\"python\">clusters = [[], []]  def update_centers():     for cluster_idx, cluster in enumerate(clusters):         cluster_mean_value = [0, 0]          for point in cluster:             for i, feature in enumerate(point):                 cluster_mean_value[i] += feature          for <\/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-442986","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/442986","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=442986"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/442986\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=442986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=442986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=442986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}