{"id":284716,"date":"2017-04-10T15:05:05","date_gmt":"2017-04-10T11:05:05","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=284716"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=284716","title":{"rendered":"\u041e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u043a\u0443\u0440\u0441 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f. \u0422\u0435\u043c\u0430 7. \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f: PCA \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f"},"content":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c! \u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0441\u0435\u0434\u044c\u043c\u0443\u044e \u0442\u0435\u043c\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f!<\/p>\n<p>  <img decoding=\"async\" align=\"right\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5be\/e8a\/297\/5bee8a297a98ce38da75f0a775f5eb3a.png\"\/>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435 \u043c\u044b \u043f\u043e\u0441\u0432\u044f\u0442\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f (unsupervised learning), \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (PCA \u2014 principal component analysis) \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0412\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u0437\u0430\u0447\u0435\u043c \u0441\u043d\u0438\u0436\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0445\u043e\u0436\u0438\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439 \u0441\u0435\u0440\u0438\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<ol>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/322626\/\">\u041f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 Pandas<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/323210\/\">\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 c Python<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/322534\/\">\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f, \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/323890\/\">\u041b\u0438\u043d\u0435\u0439\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/324402\/\">\u041a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438: \u0431\u044d\u0433\u0433\u0438\u043d\u0433, \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043b\u0435\u0441. \u041a\u0440\u0438\u0432\u044b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/325422\/\">\u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u0431\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0438 \u0433\u0435\u043e\u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/325654\/\">\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f: PCA, \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/a><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<p>  <\/p>\n<h3 id=\"plan-etoy-stati\">\u041f\u043b\u0430\u043d \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438<\/h3>\n<p>  <\/p>\n<ol>\n<li>\u041c\u0435\u0442\u043e\u0434 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (PCA)<br \/> \n<ul>\n<li>\u0418\u043d\u0442\u0443\u0438\u0446\u0438\u044f, \u0442\u0435\u043e\u0440\u0438\u044f \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/li>\n<li>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/li>\n<\/ul>\n<\/li>\n<li>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<br \/> \n<ul>\n<li>K-means<\/li>\n<li>Affinity Propagation<\/li>\n<li>\u0421\u043f\u0435\u043a\u0442\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/li>\n<li>\u0410\u0433\u043b\u043e\u043c\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/li>\n<li>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/li>\n<\/ul>\n<\/li>\n<li>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/li>\n<\/ol>\n<p>  <\/p>\n<h2 id=\"0-vvedenie\">0. \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f \u043e\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0439 \u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0439 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0442. \u041e\u0442 \u044d\u0442\u043e\u0433\u043e \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u2014 \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435\u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u0438\u043c\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0451\u043c\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0445 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0447\u0430\u0442\u044c \u0440\u0443\u043a\u0430\u043c\u0438 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0430 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445 \u044d\u0442\u043e \u043d\u0435\u044f\u0441\u043d\u043e\u0441\u0442\u044c \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0438\u0437-\u0437\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u0436\u0435 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u0438 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u0440\u0438\u043a, \u043a\u0430\u043a \u0432 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435 \u0432 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u044f\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0438, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0435\u0451 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043f\u043e\u043c\u043e\u0449\u044c \u0432 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 t-SNE, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043a\u0443\u0440\u0441\u0430. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435 \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u0443\u0431\u0440\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0443 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u043e\u043b\u0435\u0435 &quot;\u043f\u0435\u0440\u0435\u0432\u0430\u0440\u0438\u0432\u0430\u0435\u043c\u044b\u043c\u0438&quot; \u0434\u043b\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<h2 id=\"1-metod-glavnyh-komponent-pca\">1. \u041c\u0435\u0442\u043e\u0434 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (PCA)<\/h2>\n<p>  <\/p>\n<h3 id=\"intuiciya-teoriya-i-osobennosti-primeneniya\">\u0418\u043d\u0442\u0443\u0438\u0446\u0438\u044f, \u0442\u0435\u043e\u0440\u0438\u044f \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (Principal Component Analysis) \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u0441\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438 \u0438\u0445 \u043d\u0430 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432.<\/p>\n<p>  <img decoding=\"async\" align=\"right\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/bb6\/fe7\/f06\/bb6fe7f06e114bcc9c354a1cb025b966.png\" width=\"400\"\/>  <\/p>\n<p>\u0412 \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0431\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u0430\u0448\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043a\u0430\u043a \u043d\u0435\u043a\u0438\u0439 \u044d\u043b\u043b\u0438\u043f\u0441\u043e\u0438\u0434 \u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438 \u043d\u0430\u0448 \u043d\u043e\u0432\u044b\u0439 \u0431\u0430\u0437\u0438\u0441 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u0441\u044f\u043c\u0438 \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u043b\u0438\u043f\u0441\u043e\u0438\u0434\u0430. \u042d\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0431\u0430\u0437\u0438\u0441\u0430 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u043f\u0440\u043e\u0435\u0446\u0438\u0440\u0443\u0435\u043c, \u0431\u0443\u0434\u0443\u0442 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u044d\u043b\u043b\u0438\u043f\u0441\u043e\u0438\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u043d\u043e \u043d\u0430\u0448\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043b\u0435\u0436\u0430\u0442 \u0432 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u0442\u044c &quot;\u043b\u0438\u0448\u043d\u0435\u0435&quot; \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0432 \u043d\u043e\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0432\u0434\u043e\u043b\u044c \u043e\u0441\u0435\u0439 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044d\u043b\u043b\u0438\u043f\u0441\u043e\u0438\u0434 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u0435\u0435 \u0440\u0430\u0441\u0442\u044f\u043d\u0443\u0442. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c &quot;\u0436\u0430\u0434\u043d\u043e&quot;, \u0432\u044b\u0431\u0438\u0440\u0430\u044f \u043f\u043e-\u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0431\u0430\u0437\u0438\u0441\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0441\u044c \u044d\u043b\u043b\u0438\u043f\u0441\u043e\u0438\u0434\u0430 \u0438\u0437 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f, \u0432\u0434\u043e\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439.<\/p>\n<p>  <\/p>\n<blockquote><p>&quot;To deal with hyper-planes in a 14 dimensional space, visualize a 3D space and say &#8216;fourteen&#8217; very loudly. Everyone does it.&quot; \u2014 Geoffrey Hinton<\/p><\/blockquote>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438:<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/17e\/d16\/be1\/17ed16be17023e4cd19584781c333593.svg\" alt=\"$n$\" data-tex=\"inline\"\/><\/math> \u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/bcf\/ea5\/ca6\/bcfea5ca66fa5e0357105b724018ce64.svg\" alt=\"$k, k \\leq n$\" data-tex=\"inline\"\/><\/math>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0442\u043e\u043f-<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math> \u043e\u0441\u0435\u0439 \u0442\u0430\u043a\u043e\u0433\u043e \u044d\u043b\u043b\u0438\u043f\u0441\u043e\u0438\u0434\u0430, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0443\u0431\u044b\u0432\u0430\u043d\u0438\u044e \u043f\u043e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0432\u0434\u043e\u043b\u044c \u043e\u0441\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0438 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438. \u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438, \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5f2\/643\/6c9\/5f26436c907286ef0a55ffe9da9ee07d.svg\" alt=\"$X_i$\" data-tex=\"inline\"\/><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/64c\/23b\/586\/64c23b5864ad56c181cabe436604ec0e.svg\" alt=\"$X_j$\" data-tex=\"inline\"\/><\/math> \u0438\u0445 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 <\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e02\/0c5\/a8d\/e020c5a8dd469de6d09f07a284d9ea55.svg\" alt=\"$cov(X_i, X_j) = E[(X_i - \\mu_i) (X_j - \\mu_j)] = E[X_i X_j] - \\mu_i \\mu_j$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/85e\/64d\/b3f\/85e64db3f26299bcefde2a81911ea91a.svg\" alt=\"$\\mu_i$\" data-tex=\"inline\"\/><\/math> \u2014 \u043c\u0430\u0442\u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/721\/95b\/0db\/72195b0dbc8d5e1fbd3b06fd91ae2dba.svg\" alt=\"$i$\" data-tex=\"inline\"\/><\/math>-\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430.<br \/>  \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043e\u0442\u043c\u0435\u0442\u0438\u043c, \u0447\u0442\u043e \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430 \u0438 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0441 \u0441\u0430\u043c\u0438\u043c \u0441\u043e\u0431\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u0430 \u0435\u0433\u043e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443, \u0433\u0434\u0435 \u043d\u0430 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 \u043b\u0435\u0436\u0430\u0442 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u0430 \u0432\u043d\u0435 \u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u0438 \u2014 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u0430\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. \u0412 \u043c\u0430\u0442\u0440\u0438\u0447\u043d\u043e\u043c \u0432\u0438\u0434\u0435, \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/462\/6ac\/609\/4626ac609ce7f68057caefb73e1aac35.svg\" alt=\"$\\mathbf{X}$\" data-tex=\"inline\"\/><\/math> \u044d\u0442\u043e \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439, \u043d\u0430\u0448\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/dc5\/c99\/719\/dc5c997190bb6e75036abf909ec36fbc.svg\" alt=\"$\\Sigma = E[(\\mathbf{X} - E[\\mathbf{X}]) (\\mathbf{X} - E[\\mathbf{X}])^{T}]$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u2014 \u0443 \u043c\u0430\u0442\u0440\u0438\u0446 \u043a\u0430\u043a \u0443 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u0430\u043a \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 (eigenvalues \u0438 eigenvectors). \u042d\u0442\u0438 \u0448\u0442\u0443\u043a\u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b \u0442\u0435\u043c, \u0447\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043d\u0430\u0448\u0435\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u043c \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u0438 \u043b\u0438\u0448\u044c \u0443\u043c\u043d\u043e\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0422\u043e \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u044d\u0442\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 \u043a\u0430\u043a \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c, \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043d\u0430 \u043c\u0435\u0441\u0442\u0435 \u0438\u043b\u0438 &quot;\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0435\u0431\u044f&quot;. \u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2ff\/479\/70a\/2ff47970af6850903a417ec2ba13a917.svg\" alt=\"$w_i$\" data-tex=\"inline\"\/><\/math> \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e33\/e62\/c83\/e33e62c83bbd4f036b920cb52d342349.svg\" alt=\"$\\lambda_i$\" data-tex=\"inline\"\/><\/math> \u0434\u043b\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u044b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/749\/e40\/4d3\/749e404d3939aee57b53359df78745e6.svg\" alt=\"$M$\" data-tex=\"inline\"\/><\/math> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/009\/651\/fef\/009651fefc7443330c812654166bc5e6.svg\" alt=\"$M w_i = \\lambda_i w_i$\" data-tex=\"inline\"\/><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041c\u0430\u0442\u0440\u0438\u0446\u0443 \u043a\u043e\u0432\u0430\u0440\u0438\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/462\/6ac\/609\/4626ac609ce7f68057caefb73e1aac35.svg\" alt=\"$\\mathbf{X}$\" data-tex=\"inline\"\/><\/math> \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b4e\/ed0\/a4a\/b4eed0a4ac40a935f2dd601003654cb6.svg\" alt=\"$\\mathbf{X}^{T} \\mathbf{X}$\" data-tex=\"inline\"\/><\/math>. \u0418\u0437 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9E%D1%82%D0%BD%D0%BE%D1%88%D0%B5%D0%BD%D0%B8%D0%B5_%D0%A0%D1%8D%D0%BB%D0%B5%D1%8F\">\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u0420\u0435\u043b\u0435\u044f<\/a> \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0430\u0440\u0438\u0430\u0446\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432\u0434\u043e\u043b\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u044d\u0442\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0433\u043b\u0430\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u0438 \u0441\u043f\u0440\u043e\u0435\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u043e\u043f-<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math> \u0448\u0442\u0443\u043a \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u044d\u0442\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0435 \u0448\u0430\u0433\u0438 \u043f\u0440\u043e\u0441\u0442\u044b \u0434\u043e \u0431\u0435\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u2014 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u043d\u0430\u0448\u0443 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u044d\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0440\u0442\u043e\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0431\u0430\u0437\u0438\u0441\u0435 \u044d\u0442\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u043b\u0438 \u043c\u044b \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u043d\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043c\u044b \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0432 \u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u043d\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b. \u0415\u0441\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0431\u044b\u043b\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430, \u043c\u044b \u043f\u043e\u0442\u0435\u0440\u044f\u0435\u043c \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0438.<\/p>\n<p>  <\/p>\n<h3 id=\"primery-ispolzovaniya\">\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/h3>\n<p>  <\/p>\n<h3 id=\"nabor-dannyh-po-cvetkam-irisa\">\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0446\u0432\u0435\u0442\u043a\u0430\u043c \u0438\u0440\u0438\u0441\u0430<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u043f\u043e\u043a\u0440\u0443\u0442\u0438\u043c \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0438\u0440\u0438\u0441\u0430\u043c\u0438 \u043f\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 scikit-learn.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt import seaborn as sns; sns.set(style='white') %matplotlib inline from sklearn import decomposition from sklearn import datasets from mpl_toolkits.mplot3d import Axes3D  # \u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043d\u0430\u0448\u0438 \u0438\u0440\u0438\u0441\u043a\u0438 iris = datasets.load_iris() X = iris.data y = iris.target  # \u0417\u0430\u0432\u0435\u0434\u0451\u043c \u043a\u0440\u0430\u0441\u0438\u0432\u0443\u044e \u0442\u0440\u0451\u0445\u043c\u0435\u0440\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 fig = plt.figure(1, figsize=(6, 5)) plt.clf() ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134)  plt.cla()  for name, label in [('Setosa', 0), ('Versicolour', 1), ('Virginica', 2)]:     ax.text3D(X[y == label, 0].mean(),               X[y == label, 1].mean() + 1.5,               X[y == label, 2].mean(), name,               horizontalalignment='center',               bbox=dict(alpha=.5, edgecolor='w', facecolor='w')) # \u041f\u043e\u043c\u0435\u043d\u044f\u0435\u043c \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0446\u0432\u0435\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u043c\u0443 y_clr = np.choose(y, [1, 2, 0]).astype(np.float) ax.scatter(X[:, 0], X[:, 1], X[:, 2], c=y_clr, cmap=plt.cm.spectral)  ax.w_xaxis.set_ticklabels([]) ax.w_yaxis.set_ticklabels([]) ax.w_zaxis.set_ticklabels([])<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/81a\/df2\/7b7\/81adf27b70c741e29841d1cff3064992.png\" width=\"400\"\/>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e PCA \u0443\u043b\u0443\u0447\u0448\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043b\u043e\u0445\u043e \u0441\u043f\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0443 \u043d\u0435\u0451 \u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score, roc_auc_score  # \u0412\u044b\u0434\u0435\u043b\u0438\u043c \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=.3,                                                      stratify=y,                                                      random_state=42)  # \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0451\u043c \u043d\u0435\u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 clf = DecisionTreeClassifier(max_depth=2, random_state=42) clf.fit(X_train, y_train) preds = clf.predict_proba(X_test) print('Accuracy: {:.5f}'.format(accuracy_score(y_test,                                                  preds.argmax(axis=1))))<\/code><\/pre>\n<p>  <\/p>\n<pre><code>Out: Accuracy: 0.88889<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0441\u043d\u0438\u0437\u0438\u043b\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0434\u043e 2D:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u041f\u0440\u043e\u0433\u043e\u043d\u0438\u043c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432 sklearn PCA pca = decomposition.PCA(n_components=2) X_centered = X - X.mean(axis=0) pca.fit(X_centered) X_pca = pca.transform(X_centered)  # \u0418 \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0442\u043e\u0447\u043a\u0438 \u0432 \u043d\u0430\u0448\u0435\u043c \u043d\u043e\u0432\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 plt.plot(X_pca[y == 0, 0], X_pca[y == 0, 1], 'bo', label='Setosa') plt.plot(X_pca[y == 1, 0], X_pca[y == 1, 1], 'go', label='Versicolour') plt.plot(X_pca[y == 2, 0], X_pca[y == 2, 1], 'ro', label='Virginica') plt.legend(loc=0);<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/05c\/df6\/4b4\/05cdf64b44514a0f9617e8e1a0688ea9.png\" width=\"400\"\/>  <\/p>\n<pre><code class=\"python\"># \u041f\u043e\u0432\u0442\u043e\u0440\u0438\u043c \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443. X_train, X_test, y_train, y_test = train_test_split(X_pca, y, test_size=.3,                                                      stratify=y,                                                      random_state=42)  clf = DecisionTreeClassifier(max_depth=2, random_state=42) clf.fit(X_train, y_train) preds = clf.predict_proba(X_test) print('Accuracy: {:.5f}'.format(accuracy_score(y_test,                                                  preds.argmax(axis=1))))<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u043e\u0437\u0440\u043e\u0441\u0448\u0443\u044e \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code>Out: Accuracy: 0.91111<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u043e\u0437\u0440\u043e\u0441\u043b\u043e \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u0433\u0434\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e \u0432\u0434\u043e\u043b\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430, \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 PCA \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438 \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0439 \u043d\u0430 \u0438\u0445 \u043e\u0441\u043d\u043e\u0432\u0435.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 2 \u0433\u043b\u0430\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c PCA-\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043d\u0430 \u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0432 \u0434\u0430\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043d\u0438 &quot;\u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e\u0442&quot;.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">for i, component in enumerate(pca.components_):     print(&quot;{} component: {}% of initial variance&quot;.format(i + 1,            round(100 * pca.explained_variance_ratio_[i], 2)))     print(&quot; + &quot;.join(&quot;%.3f x %s&quot; % (value, name)                      for value, name in zip(component,                                             iris.feature_names)))<\/code><\/pre>\n<p>  <\/p>\n<pre><code>1 component: 92.46% of initial variance 0.362 x sepal length (cm) + -0.082 x sepal width (cm) + 0.857 x petal length (cm) + 0.359 x petal width (cm) 2 component: 5.3% of initial variance 0.657 x sepal length (cm) + 0.730 x sepal width (cm) + -0.176 x petal length (cm) + -0.075 x petal width (cm)<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"nabor-dannyh-po-rukopisnym-cifram\">\u041d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u043c \u0446\u0438\u0444\u0440\u0430\u043c<\/h4>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u043c \u0446\u0438\u0444\u0440\u0430\u043c. \u041c\u044b \u0441 \u043d\u0438\u043c \u0443\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0432 3 <a href=\"https:\/\/habrahabr.ru\/company\/ods\/blog\/322534\/#derevya-resheniy-i-metod-blizhayshih-sosedey-v-zadache-raspoznavaniya-rukopisnyh-cifr-mnist\">\u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043f\u0440\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">digits = datasets.load_digits() X = digits.data y = digits.target<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u044d\u0442\u0438 \u0446\u0438\u0444\u0440\u044b \u2013 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0435\u0441\u044f\u0442\u044c. \u041a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0435\u0439 8 x 8 (\u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0431\u0435\u043b\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0438\u043a\u0441\u0435\u043b\u044f). \u0414\u0430\u043b\u0435\u0435 \u044d\u0442\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 &quot;\u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f&quot; \u0432 \u0432\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u0438\u043d\u044b 64, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># f, axes = plt.subplots(5, 2, sharey=True, figsize=(16,6)) plt.figure(figsize=(16, 6)) for i in range(10):     plt.subplot(2, 5, i + 1)     plt.imshow(X[i,:].reshape([8,8]));<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/a3d\/d4f\/7ac\/a3dd4f7acc494b32913a329f5c88878a.png\" alt=\"mnist\"\/><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f, \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0437\u0434\u0435\u0441\u044c \u2013 64. \u041d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043d\u0438\u0437\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u0434\u043e 2 \u0438 \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0430 \u0433\u043b\u0430\u0437 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0435 \u0446\u0438\u0444\u0440\u044b \u043d\u0435\u043f\u043b\u043e\u0445\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">pca = decomposition.PCA(n_components=2) X_reduced = pca.fit_transform(X)  print('Projecting %d-dimensional data to 2D' % X.shape[1])  plt.figure(figsize=(12,10)) plt.scatter(X_reduced[:, 0], X_reduced[:, 1], c=y,              edgecolor='none', alpha=0.7, s=40,             cmap=plt.cm.get_cmap('nipy_spectral', 10)) plt.colorbar() plt.title('MNIST. PCA projection')<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e03\/cad\/705\/e03cad70566941a2984f485dd6b069e2.png\" alt=\"pca\"\/><\/p>\n<p>  <\/p>\n<p>\u041d\u0443, \u043f\u0440\u0430\u0432\u0434\u0430, \u0441 t-SNE \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0443 PCA \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u2013 \u043e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0435 \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. \u0417\u0430\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0430 \u044d\u0442\u043e\u043c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e t-SNE \u0434\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">%%time  from sklearn.manifold import TSNE tsne = TSNE(random_state=17)  X_tsne = tsne.fit_transform(X)  plt.figure(figsize=(12,10)) plt.scatter(X_tsne[:, 0], X_tsne[:, 1], c=y,              edgecolor='none', alpha=0.7, s=40,             cmap=plt.cm.get_cmap('nipy_spectral', 10)) plt.colorbar() plt.title('MNIST. t-SNE projection')<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/1cf\/a69\/7c9\/1cfa697c919349c2afae344f566e0b03.png\" alt=\"tsne\"\/><\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c 90% \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c 21 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443, \u0442\u043e \u0435\u0441\u0442\u044c \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0441 64 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u043e 21.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">pca = decomposition.PCA().fit(X)  plt.figure(figsize=(10,7)) plt.plot(np.cumsum(pca.explained_variance_ratio_), color='k', lw=2) plt.xlabel('Number of components') plt.ylabel('Total explained variance') plt.xlim(0, 63) plt.yticks(np.arange(0, 1.1, 0.1)) plt.axvline(21, c='b') plt.axhline(0.9, c='r') plt.show();<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c34\/039\/bb7\/c34039bb7993434e84ce3c5933a539cf.png\" alt=\"variance\"\/><\/p>\n<p>  <\/p>\n<h2 id=\"2-klasterizaciya\">2. \u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u0430\u044f \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430 \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043d\u0430\u0448\u0435 \u0436\u0435\u043b\u0430\u043d\u0438\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c: &quot;\u0412\u043e\u0442 \u0442\u0443\u0442 \u0443 \u043c\u0435\u043d\u044f \u043d\u0430\u0441\u044b\u043f\u0430\u043d\u044b \u0442\u043e\u0447\u043a\u0438. \u042f \u0432\u0438\u0436\u0443, \u0447\u0442\u043e \u043e\u043d\u0438 \u0441\u0432\u0430\u043b\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043a\u0443\u0447\u043a\u0438 \u0432\u043c\u0435\u0441\u0442\u0435. \u0411\u044b\u043b\u043e \u0431\u044b \u043a\u0440\u0443\u0442\u043e \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u044d\u0442\u0438 \u0442\u043e\u0447\u043a\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u044c \u043a \u043a\u0443\u0447\u043a\u0430\u043c \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c, \u0432 \u043a\u0430\u043a\u0443\u044e \u043a\u0443\u0447\u043a\u0443 \u043e\u043d\u0430 \u043f\u0430\u0434\u0430\u0435\u0442.&quot; \u0418\u0437 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e, \u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043d\u0438 \u0432 \u043a\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0434\u0430\u043d\u043d\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e, \u043d\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0441\u0430\u043c\u044b\u0445 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/8b9\/ae5\/586\/8b9ae55861f22a2809e8b3a00ef815ad.png\"\/><\/div>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 scikit-learn  <\/p>\n<h3 id=\"k-means\">K-means<\/h3>\n<p>  <\/p>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0412\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/li>\n<li>\u0412\u044b\u0441\u044b\u043f\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math> \u0442\u043e\u0447\u0435\u043a (\u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u043e\u0432).<\/li>\n<li>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0443 \u043e\u043d\u0430 \u0431\u043b\u0438\u0436\u0435.<\/li>\n<li>\u041f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434 \u0432 \u0446\u0435\u043d\u0442\u0440 \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u043e\u0442\u043d\u0435\u0441\u043b\u0438 \u043a \u044d\u0442\u043e\u043c\u0443 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0443.<\/li>\n<li>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0434\u0432\u0430 \u0448\u0430\u0433\u0430 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u0440\u0430\u0437, \u043b\u0438\u0431\u043e \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440 \u043f\u043e\u043a\u0430 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u044b \u043d\u0435 &quot;\u0441\u043e\u0439\u0434\u0443\u0442\u0441\u044f&quot; (\u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0438\u0445 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f).<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0439 \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u0442\u043e\u0447\u0435\u043a \u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438, \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438 \u0440\u0438\u0441\u0443\u0435\u0442\u0441\u044f. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\"># \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u0441\u044b\u043f\u0435\u043c \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c \u0442\u0440\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0442\u043e\u0447\u0435\u043a X = np.zeros((150, 2))  np.random.seed(seed=42) X[:50, 0] = np.random.normal(loc=0.0, scale=.3, size=50) X[:50, 1] = np.random.normal(loc=0.0, scale=.3, size=50)  X[50:100, 0] = np.random.normal(loc=2.0, scale=.5, size=50) X[50:100, 1] = np.random.normal(loc=-1.0, scale=.2, size=50)  X[100:150, 0] = np.random.normal(loc=-1.0, scale=.2, size=50) X[100:150, 1] = np.random.normal(loc=2.0, scale=.5, size=50)  plt.figure(figsize=(5, 5)) plt.plot(X[:, 0], X[:, 1], 'bo');<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/565\/72b\/72f\/56572b72f3ef4cd3bcd4d926d35fe4de.png\" width=\"400\"\/>  <\/p>\n<pre><code class=\"python\"># \u0412 scipy \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f # \u043c\u0435\u0436\u0434\u0443 \u043f\u0430\u0440\u0430\u043c\u0438 \u0442\u043e\u0447\u0435\u043a \u0438\u0437 \u0434\u0432\u0443\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432, \u043f\u043e\u0434\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0435\u0439 \u043d\u0430 \u0432\u0445\u043e\u0434 from scipy.spatial.distance import cdist  # \u041f\u0440\u0438\u0431\u044c\u0451\u043c \u0440\u0430\u043d\u0434\u043e\u043c\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0430\u0441\u044b\u043f\u0435\u043c \u0442\u0440\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u044b \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 np.random.seed(seed=42) centroids = np.random.normal(loc=0.0, scale=1., size=6) centroids = centroids.reshape((3, 2))  cent_history = [] cent_history.append(centroids)  for i in range(3):     # \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0434\u043e \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434     distances = cdist(X, centroids)     # \u0421\u043c\u043e\u0442\u0440\u0438\u043c, \u0434\u043e \u043a\u0430\u043a\u043e\u0439 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u043e\u0447\u043a\u0435 \u0431\u043b\u0438\u0436\u0435 \u0432\u0441\u0435\u0433\u043e     labels = distances.argmin(axis=1)      # \u041f\u043e\u043b\u043e\u0436\u0438\u043c \u0432 \u043a\u0430\u0436\u0434\u0443\u044e \u043d\u043e\u0432\u0443\u044e \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0443 \u0433\u0435\u043e\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0446\u0435\u043d\u0442\u0440 \u0435\u0451 \u0442\u043e\u0447\u0435\u043a     centroids = centroids.copy()     centroids[0, :] = np.mean(X[labels == 0, :], axis=0)     centroids[1, :] = np.mean(X[labels == 1, :], axis=0)     centroids[2, :] = np.mean(X[labels == 2, :], axis=0)      cent_history.append(centroids)<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"python\"># \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u043c \u0432\u0441\u044e \u044d\u0442\u0443 \u043a\u0440\u0430\u0441\u043e\u0442\u0443 plt.figure(figsize=(8, 8)) for i in range(4):     distances = cdist(X, cent_history[i])     labels = distances.argmin(axis=1)      plt.subplot(2, 2, i + 1)     plt.plot(X[labels == 0, 0], X[labels == 0, 1], 'bo', label='cluster #1')     plt.plot(X[labels == 1, 0], X[labels == 1, 1], 'co', label='cluster #2')     plt.plot(X[labels == 2, 0], X[labels == 2, 1], 'mo', label='cluster #3')     plt.plot(cent_history[i][:, 0], cent_history[i][:, 1], 'rX')     plt.legend(loc=0)     plt.title('Step {:}'.format(i + 1));<\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/f86\/352\/e26\/f86352e26fed47119d2abb4bd4028666.png\" width=\"400\"\/>  <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0445\u043e\u0442\u044c \u043c\u044b \u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u044e\u0431\u043e\u0439 \u0434\u0440\u0443\u0433\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043e\u0436\u043d\u043e \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0448\u0430\u0433\u043e\u0432 \u0438\u043b\u0438 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u043c \u0441\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438, \u043d\u043e \u0438 \u0441 \u043c\u0435\u0442\u0440\u0438\u043a\u043e\u0439, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0438 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0414\u0440\u0443\u0433\u043e\u0439 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u044d\u0442\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043e\u043d \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044e \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. \u0412 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u0441\u043f\u0430\u0441\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432.<\/p>\n<p>  <\/p>\n<h4 id=\"vybor-chisla-klasterov-dlya-kmeans\">\u0412\u044b\u0431\u043e\u0440 \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0434\u043b\u044f kMeans<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0438\u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438.<br \/>  \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 kMeans \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0439 \u2013 \u0441\u0443\u043c\u043c\u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043e\u0432 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043e\u0442 \u0442\u043e\u0447\u0435\u043a \u0434\u043e \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/a0f\/166\/adf\/a0f166adfb18d6fb0e7491686eb2e6e9.svg\" alt=\"$ J(C) = \\sum_{k=1}^K\\sum_{i~\\in~C_k} ||x_i - \\mu_k|| \\rightarrow \\min\\limits_C,$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0437\u0434\u0435\u0441\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/daf\/e83\/7b2\/dafe837b2eb473c8c3a2240b85e4ca80.svg\" alt=\"$C$\" data-tex=\"inline\"\/><\/math> \u2013 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/c66\/881\/68c\/c6688168c78c959fb4e9040fda31393d.svg\" alt=\"$K$\" data-tex=\"inline\"\/><\/math>, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/606\/90f\/915\/60690f9155ac454e8934c769aa62fa67.svg\" alt=\"$\\mu_k$\" data-tex=\"inline\"\/><\/math> \u2013 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b6e\/e3e\/72c\/b6ee3e72cfe63a9e8b1b387c5fe62c06.svg\" alt=\"$C_k$\" data-tex=\"inline\"\/><\/math>.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0437\u0434\u0440\u0430\u0432\u044b\u0439 \u0441\u043c\u044b\u0441\u043b \u0432 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c: \u043c\u044b \u0445\u043e\u0442\u0438\u043c, \u0447\u0442\u043e\u0431\u044b \u0442\u043e\u0447\u043a\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0433\u0430\u043b\u0438\u0441\u044c \u043a\u0443\u0447\u043d\u043e \u0432\u043e\u0437\u043b\u0435 \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u0441\u0432\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u041d\u043e \u0432\u043e\u0442 \u043d\u0435\u0437\u0430\u0434\u0430\u0447\u0430: \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u043d\u0443\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0436\u0435, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438 \u0442\u043e\u0447\u0435\u043a (\u0442\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u0436\u0434\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u2013 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430).<br \/>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0432\u043e\u043f\u0440\u043e\u0441\u0430 (\u0432\u044b\u0431\u043e\u0440\u0430 \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432) \u0447\u0430\u0441\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u043e\u0439 \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u043e\u0439: \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442 \u0442\u043e \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/757\/91b\/07f\/75791b07f2db527bc58ac5e379f5a549.svg\" alt=\"$ J(C) $\" data-tex=\"inline\"\/><\/math> \u043f\u0430\u0434\u0430\u0435\u0442 &quot;\u0443\u0436\u0435 \u043d\u0435 \u0442\u0430\u043a \u0431\u044b\u0441\u0442\u0440\u043e&quot;. \u0418\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e: <\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/789\/735\/702\/7897357020600a8a51f24ce0fd0355fa.svg\" alt=\"$ D(k) = \\frac{|J(C_k) - J(C_{k+1})|}{|J(C_{k-1}) - J(C_k)|} \\rightarrow \\min\\limits_k $\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440.<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from sklearn.cluster import KMeans  func = [] for k in range(2, 8):     kmeans = KMeans(n_clusters=k, random_state=1).fit(X)     func.append(np.sqrt(kmeans.inertia_))  plt.plot(range(1, 8), inertia, marker='s'); plt.xlabel('$k$') plt.ylabel('$J(C_k)$');<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/1b0\/46d\/9bd\/1b046d9bd6684ff5a84a6a4e1480156e.png\" alt=\"elbow\"\/><\/p>\n<p>  <\/p>\n<p>\u0412\u0438\u0434\u0438\u043c, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/595\/a80\/db4\/595a80db4e17ecfe3d948205741f8219.svg\" alt=\"$J(C_k)$\" data-tex=\"inline\"\/><\/math> \u043f\u0430\u0434\u0430\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0438 \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0441 1 \u0434\u043e 2 \u0438 \u0441 2 \u0434\u043e 3 \u0438 \u0443\u0436\u0435 \u043d\u0435 \u0442\u0430\u043a \u0441\u0438\u043b\u044c\u043d\u043e \u2013 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math> \u0441 3 \u0434\u043e 4. \u0417\u043d\u0430\u0447\u0438\u0442, \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c 3 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430.<\/p>\n<p>  <\/p>\n<h4 id=\"slozhnosti\">\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438<\/h4>\n<p>  <\/p>\n<p>\u0421\u0430\u043c\u043e \u043f\u043e \u0441\u0435\u0431\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 K-means NP-\u0442\u0440\u0443\u0434\u043d\u043e\u0435 (NP-Hard, <a href=\"https:\/\/habrahabr.ru\/post\/132127\/\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> &quot;\u0415\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e P \u0438 NP&quot; \u043d\u0430 \u0425\u0430\u0431\u0440\u0435), \u0438 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b59\/99c\/bd8\/b5999cbd87881cf38f84f9b0b73a8284.svg\" alt=\"$d$\" data-tex=\"inline\"\/><\/math>, \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math> \u0438 \u0447\u0438\u0441\u043b\u0430 \u0442\u043e\u0447\u0435\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/17e\/d16\/be1\/17ed16be17023e4cd19584781c333593.svg\" alt=\"$n$\" data-tex=\"inline\"\/><\/math> \u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fa4\/cdc\/30b\/fa4cdc30bd647572843fcc72426a6bbe.svg\" alt=\"$O(n^{d k+1})$\" data-tex=\"inline\"\/><\/math>. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u0431\u043e\u043b\u0438 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u044d\u0432\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 MiniBatch K-means, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043d\u0435 \u0432\u0435\u0441\u044c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0446\u0435\u043b\u0438\u043a\u043e\u043c, \u0430 \u043b\u0438\u0448\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435 \u0435\u0433\u043e \u043f\u043e\u0440\u0446\u0438\u0438 (batch) \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u0430 \u0432\u0441\u044e \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0439 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0430 \u043e\u0442 \u0432\u0441\u0435\u0445 \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0445\u0441\u044f \u043a \u043d\u0435\u043c\u0443 \u0442\u043e\u0447\u0435\u043a. \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e K-means \u0438 \u0435\u0433\u043e MiniBatch \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"http:\/\/scikit-learn.org\/stable\/auto_examples\/cluster\/plot_mini_batch_kmeans.html\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 scikit-learn<\/a>.<\/p>\n<p>  <\/p>\n<p><a href=\"http:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.cluster.KMeans.html\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a> \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 scikit-learn \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u043e\u0439 \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u043b\u044e\u0448\u0435\u043a, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>n_init<\/code>, \u0447\u0442\u043e \u0434\u0430\u0441\u0442 \u0431\u043e\u043b\u0435\u0435 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u044b\u0435 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u044b \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043a\u043e\u0448\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u044d\u0442\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e, \u043d\u0435 \u0436\u0435\u0440\u0442\u0432\u0443\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h3 id=\"affinity-propagation\">Affinity Propagation<\/h3>\n<p>  <\/p>\n<p>\u0415\u0449\u0451 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u041a-\u0441\u0440\u0435\u0434\u043d\u0438\u0445, \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0432 \u0433\u0440\u0443\u043f\u043f\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043e\u043d\u0438 &quot;\u043e\u0431\u0449\u0430\u044e\u0442\u0441\u044f&quot;, \u0438\u043b\u0438 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0438 \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0432\u0435\u0434\u0451\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0443 &quot;\u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438&quot;, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/f95\/352\/e05\/f95352e05252cb90d4a1a8fb04446f7f.svg\" alt=\"$s(x_i, x_j) &gt; s(x_i, x_k)$\" data-tex=\"inline\"\/><\/math> \u0435\u0441\u043b\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/341\/dcf\/d5f\/341dcfd5f7bae56feb730788f817ab8f.svg\" alt=\"$x_i$\" data-tex=\"inline\"\/><\/math> \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/75f\/225\/49c\/75f22549c65d4782f1580b5c0b892084.svg\" alt=\"$x_j$\" data-tex=\"inline\"\/><\/math>, \u0447\u0435\u043c \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/0f2\/72d\/3b1\/0f272d3b1ebceb2087c5741d67873d5c.svg\" alt=\"$x_k$\" data-tex=\"inline\"\/><\/math>. \u041f\u0440\u043e\u0441\u0442\u044b\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u0432\u0430\u0434\u0440\u0430\u0442 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/d40\/8c4\/166\/d408c41668988f0401b85580477844ba.svg\" alt=\"$s(x_i, x_j) = - ||x_i - x_j||^{2}$\" data-tex=\"inline\"\/><\/math>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043f\u0438\u0448\u0435\u043c \u0441\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 &quot;\u043e\u0431\u0449\u0435\u043d\u0438\u044f&quot;. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0434\u0451\u043c \u0434\u0432\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0435 \u043d\u0443\u043b\u044f\u043c\u0438, \u043e\u0434\u043d\u0430 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/252\/da3\/d07\/252da3d072bb4faa7e8757c17a8d8010.svg\" alt=\"$r_{i,k}$\" data-tex=\"inline\"\/><\/math> \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u043e\u0440\u043e\u0448\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math>-\u0442\u043e\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u0442\u044c &quot;\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0434\u043b\u044f \u043f\u043e\u0434\u0440\u0430\u0436\u0430\u043d\u0438\u044f&quot; \u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/721\/95b\/0db\/72195b0dbc8d5e1fbd3b06fd91ae2dba.svg\" alt=\"$i$\" data-tex=\"inline\"\/><\/math>-\u0442\u043e\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 &quot;\u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432&quot;, \u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u2014 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2ec\/675\/ea4\/2ec675ea47a12f90e31b9bc31d8b9084.svg\" alt=\"$a_{i,k}$\" data-tex=\"inline\"\/><\/math> \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0431\u044b\u043b\u043e \u0431\u044b \u0434\u043b\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/721\/95b\/0db\/72195b0dbc8d5e1fbd3b06fd91ae2dba.svg\" alt=\"$i$\" data-tex=\"inline\"\/><\/math>-\u0442\u043e\u0433\u043e \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u0440\u0430\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math>-\u0442\u043e\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0430\u043a\u043e\u0433\u043e &quot;\u043f\u0440\u0438\u043c\u0435\u0440\u0430&quot;. \u0417\u0432\u0443\u0447\u0438\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u043e, \u043d\u043e \u0447\u0443\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 \u0443\u0432\u0438\u0434\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 &quot;\u043d\u0430 \u043f\u0430\u043b\u044c\u0446\u0430\u0445&quot;.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c:<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9f9\/750\/198\/9f9750198617908da2e78bda273b3e1a.svg\" alt=\"$r_{i,k} \\leftarrow s_(x_i, x_k) - \\max_{k&#39; \\neq k} \\left\\{ a_{i,k&#39;} + s(x_i, x_k&#39;) \\right\\}$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5f5\/15e\/b26\/5f515eb26cbca6eafd680557348e0755.svg\" alt=\"$a_{i,k} \\leftarrow \\min \\left( 0, r_{k,k} + \\sum_{i&#39; \\not\\in \\{i,k\\}} \\max(0, r_{i&#39;,k}) \\right), \\ \\ \\ i \\neq k$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/eda\/1d8\/aaf\/eda1d8aafd635de26ddbfaf6d12a43bb.svg\" alt=\"$a_{k,k} \\leftarrow \\sum_{i&#39; \\neq k} \\max(0, r_{i&#39;,k})$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<h3 id=\"spektralnaya-klasterizaciya\">\u0421\u043f\u0435\u043a\u0442\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u0421\u043f\u0435\u043a\u0442\u0440\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0444\u0438\u0442\u0430 \u043e\u0442 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u043c\u043d\u043e\u0433\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430. <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u044d\u0442\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 (adjacency matrix). \u041c\u043e\u0436\u043d\u043e \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043a\u0430\u043a \u0438 \u0434\u043b\u044f Affinity Propagation \u0432\u044b\u0448\u0435: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/16d\/a6d\/3bc\/16da6d3bc9b23cd92c5ccfd77877247f.svg\" alt=\"$A_{i, j} = - ||x_i - x_j||^{2}$\" data-tex=\"inline\"\/><\/math>. \u042d\u0442\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u044b\u0439 \u0433\u0440\u0430\u0444 \u0441 \u0432\u0435\u0440\u0448\u0438\u043d\u0430\u043c\u0438 \u0432 \u043d\u0430\u0448\u0438\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u044f\u0445 \u0438 \u0440\u0451\u0431\u0440\u0430\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u043e\u0439 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0441 \u0432\u0435\u0441\u043e\u043c, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043f\u043e\u0445\u043e\u0436\u0435\u0441\u0442\u0438 \u044d\u0442\u0438\u0445 \u0432\u0435\u0440\u0448\u0438\u043d. \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0439 \u0432\u044b\u0448\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438 \u0442\u043e\u0447\u0435\u043a, \u043b\u0435\u0436\u0430\u0449\u0438\u0445 \u043d\u0430 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438, \u044d\u0442\u0430 \u0448\u0442\u0443\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u2014 \u0434\u0432\u0435 \u0442\u043e\u0447\u043a\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0445\u043e\u0436\u0438, \u0435\u0441\u043b\u0438 \u0440\u0435\u0431\u0440\u043e \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043a\u043e\u0440\u043e\u0447\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0448 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0433\u0440\u0430\u0444 \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0442\u043e\u0447\u043a\u0438 \u0432 \u0434\u0432\u0443\u0445 \u0433\u0440\u0430\u0444\u0430\u0445 \u0431\u044b\u043b\u0438 \u0432 \u043e\u0431\u0449\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u043e\u0447\u043a\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0439\u0441\u044f &quot;\u0441\u0432\u043e\u0435\u0439&quot; \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u044b \u0433\u0440\u0430\u0444\u0430, \u0447\u0435\u043c \u043d\u0430 \u0442\u043e\u0447\u043a\u0438 \u0432 &quot;\u0434\u0440\u0443\u0433\u043e\u0439&quot; \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0435. \u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f Normalized cuts problem \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"http:\/\/people.eecs.berkeley.edu\/~malik\/papers\/SM-ncut.pdf\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>  <\/p>\n<h3 id=\"aglomerativnaya-klasterizaciya\">\u0410\u0433\u043b\u043e\u043c\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u043e\u0435 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0435\u0437 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u2014 \u0430\u0433\u043b\u043e\u043c\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f. \u0418\u043d\u0442\u0443\u0438\u0446\u0438\u044f \u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f: <\/p>\n<p>  <\/p>\n<ol>\n<li>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u044b\u0441\u044b\u043f\u0430\u0435\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u0442\u043e\u0447\u043a\u0443 \u0441\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440<\/li>\n<li>\u0421\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u043e\u043f\u0430\u0440\u043d\u044b\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u0442\u0440\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043f\u043e \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u043d\u0438\u044e<\/li>\n<li>\u0411\u0435\u0440\u0451\u043c \u043f\u0430\u0440\u0443 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u0438\u0445 \u0432 \u043e\u0434\u0438\u043d \u0438 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0446\u0435\u043d\u0442\u0440 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430<\/li>\n<li>\u041f\u043e\u0432\u0442\u043e\u0440\u044f\u0435\u043c \u043f. 2 \u0438 3 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u043a\u043b\u0435\u044f\u0442\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0442\u0435\u0440<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u0421\u0430\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0438\u0441\u043a\u0430 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u0435\u043a:<\/p>\n<p>  <\/p>\n<ol>\n<li>Single linkage \u2014 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043f\u043e\u043f\u0430\u0440\u043d\u044b\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432<br \/>  <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/caf\/1fd\/dd0\/caf1fddd0cf74278e468ada4b935277d.svg\" alt=\"$d(C_i, C_j) = min_{x_i \\in C_i, x_j \\in C_j} ||x_i - x_j||$\" data-tex=\"inline\"\/><\/math><\/li>\n<li>Complete linkage \u2014 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043f\u043e\u043f\u0430\u0440\u043d\u044b\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432<br \/>  <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5aa\/b5a\/843\/5aab5a8431fd973413b9a961affb87b2.svg\" alt=\"$d(C_i, C_j) = max_{x_i \\in C_i, x_j \\in C_j} ||x_i - x_j||$\" data-tex=\"inline\"\/><\/math><\/li>\n<li>Average linkage \u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043f\u043e\u043f\u0430\u0440\u043d\u044b\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432<br \/>  <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9ef\/516\/6cc\/9ef5166cc5d7b0023dfe55c20197baa6.svg\" alt=\"$d(C_i, C_j) = \\frac{1}{n_i n_j} \\sum_{x_i \\in C_i} \\sum_{x_j \\in C_j} ||x_i - x_j||$\" data-tex=\"inline\"\/><\/math><\/li>\n<li>Centroid linkage \u2014 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0446\u0435\u043d\u0442\u0440\u043e\u0438\u0434\u0430\u043c\u0438 \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432<br \/>  <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/740\/6cc\/d1d\/7406ccd1dd6fbcbdc7550e13b5b4f47e.svg\" alt=\"$d(C_i, C_j) = ||\\mu_i - \\mu_j||$\" data-tex=\"inline\"\/><\/math><\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0444\u0438\u0442 \u043f\u0435\u0440\u0432\u044b\u0445 \u0442\u0440\u0451\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u0447\u0435\u0442\u0432\u0451\u0440\u0442\u044b\u043c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u043e\u0441\u043b\u0435 \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e \u0441\u0438\u043b\u044c\u043d\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e \u0438\u0442\u043e\u0433\u0430\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438 \u0433\u043b\u044f\u0434\u044f \u043d\u0430 \u043d\u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043d\u0430 \u043a\u0430\u043a\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0430\u043c \u0431\u044b\u043b\u043e \u0431\u044b \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c. \u041b\u0438\u0431\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e\u043c \u043b\u043e\u043a\u0442\u044f, \u0447\u0442\u043e \u0438 \u0432 k-means.<\/p>\n<p>  <\/p>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e \u0434\u043b\u044f \u043d\u0430\u0441 \u0432 \u043f\u0438\u0442\u043e\u043d\u0435 \u0443\u0436\u0435 \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u0434\u0435\u043d\u0434\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0434\u043b\u044f \u0430\u0433\u043b\u043e\u043c\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0430\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0438\u0437 K-means:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from scipy.cluster import hierarchy from scipy.spatial.distance import pdist  X = np.zeros((150, 2))  np.random.seed(seed=42) X[:50, 0] = np.random.normal(loc=0.0, scale=.3, size=50) X[:50, 1] = np.random.normal(loc=0.0, scale=.3, size=50)  X[50:100, 0] = np.random.normal(loc=2.0, scale=.5, size=50) X[50:100, 1] = np.random.normal(loc=-1.0, scale=.2, size=50)  X[100:150, 0] = np.random.normal(loc=-1.0, scale=.2, size=50) X[100:150, 1] = np.random.normal(loc=2.0, scale=.5, size=50)  distance_mat = pdist(X) # pdist \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u043d\u0430\u043c \u0432\u0435\u0440\u0445\u043d\u0438\u0439 \u0442\u0440\u0435\u0443\u0433\u043e\u043b\u044c\u043d\u0438\u043a \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043f\u043e\u043f\u0430\u0440\u043d\u044b\u0445 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0439  Z = hierarchy.linkage(distance_mat, 'single') # linkage \u2014 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0433\u043b\u043e\u043c\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 plt.figure(figsize=(10, 5)) dn = hierarchy.dendrogram(Z, color_threshold=0.5)<\/code><\/pre>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/9c4\/f52\/c5e\/9c4f52c5eb43438aae47215e26b2dcf9.png\" alt=\"Dendrogram\"\/><\/p>\n<p>  <\/p>\n<h3 id=\"metriki-kachestva-klasterizacii\">\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/h3>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043e\u0446\u0435\u043d\u043a\u043e\u0439 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0442\u0430\u043a\u0438\u0435 \u043e\u0446\u0435\u043d\u043a\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0441\u0430\u043c\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u043a, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0441\u0430\u043c\u043e\u0433\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u044b \u043e\u0446\u0435\u043d\u043a\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0435 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443.<\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0434\u0435\u043b\u044f\u044e\u0442 <em>\u0432\u043d\u0435\u0448\u043d\u0438\u0435<\/em> \u0438 <em>\u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435<\/em> \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430. \u0412\u043d\u0435\u0448\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u043c \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u044e\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0441\u043d\u043e\u0432\u044b\u0432\u0430\u044f\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0445 \u043c\u0435\u0442\u0440\u0438\u043a.<\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043d\u0438\u0436\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u0432 <code>sklearn.metrics<\/code>.<\/p>\n<p>  <\/p>\n<p><strong>Adjusted Rand Index (ARI)<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0414\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0440\u0430 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0441\u0430\u043c\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u043a, \u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0442 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b. \u041f\u0443\u0441\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/644\/86c\/eab\/64486ceabd5fd2c0d8f3df3093ef55bc.svg\" alt=\"$N$\" data-tex=\"inline\"\/><\/math> \u2014 \u0447\u0438\u0441\u043b\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0432\u044b\u0431\u043e\u0440\u043a\u0435. \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0447\u0435\u0440\u0435\u0437 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/366\/a4b\/5c5\/366a4b5c5bdf260210b49a89f904efb9.svg\" alt=\"$a$\" data-tex=\"inline\"\/><\/math> \u2014 \u0447\u0438\u0441\u043b\u043e \u043f\u0430\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435, \u0447\u0435\u0440\u0435\u0437 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5d2\/218\/e72\/5d2218e7292f24a1ff72a7ba614d11e9.svg\" alt=\"$b$\" data-tex=\"inline\"\/><\/math> \u2014 \u0447\u0438\u0441\u043b\u043e \u043f\u0430\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438\u043c\u0435\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438 \u0438 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0445\u0441\u044f \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u0445. \u0422\u043e\u0433\u0434\u0430 Rand Index \u044d\u0442\u043e <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/213\/c41\/7a5\/213c417a5268c7da350b224f80072f1b.svg\" alt=\"$\\text{RI} = \\frac{2(a + b)}{n(n-1)}.$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  \u0422\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e \u0434\u043e\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044d\u0442\u0438 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f (\u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0435 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438) &quot;\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u044b&quot;. Rand Index (RI) \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u044c \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0439 \u043e\u0434\u043d\u043e\u0439 \u0438 \u0442\u043e\u0439 \u0436\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438. \u0427\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0442 \u0438\u043d\u0434\u0435\u043a\u0441 \u0434\u0430\u0432\u0430\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a \u043d\u0443\u043b\u044e \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0439 \u043f\u0440\u0438 \u043b\u044e\u0431\u043e\u043c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/644\/86c\/eab\/64486ceabd5fd2c0d8f3df3093ef55bc.svg\" alt=\"$N$\" data-tex=\"inline\"\/><\/math> \u0438 \u0447\u0438\u0441\u043b\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e. \u0422\u0430\u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f Adjusted Rand Index: <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6db\/b0c\/c29\/6dbb0cc2964c494e35adf68a8b297a66.svg\" alt=\"$\\text{ARI} = \\frac{\\text{RI} - E[\\text{RI}]}{\\max(\\text{RI}) - E[\\text{RI}]}.$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u0430 \u043c\u0435\u0440\u0430 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430, \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u043c\u0435\u0442\u043e\u043a. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u0430\u043d\u043d\u044b\u0439 \u0438\u043d\u0434\u0435\u043a\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0435\u0440\u043e\u0439 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f\u043c\u0438 \u0432\u044b\u0431\u043e\u0440\u043a\u0438. <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5d4\/58b\/e9e\/5d458be9ed7bc9cd4287c2b7db562db3.svg\" alt=\"$\\text{ARI}$\" data-tex=\"inline\"\/><\/math> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/7b7\/67e\/bf1\/7b767ebf15c29b116d9e6ca05734c433.svg\" alt=\"$[-1, 1]$\" data-tex=\"inline\"\/><\/math>. \u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 &quot;\u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u043c&quot; \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f\u043c \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a \u043d\u0443\u043b\u044e, \u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f\u043c, \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0432\u0430 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0441\u0445\u043e\u0436\u0438 (\u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u043f\u0440\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/e12\/e53\/378\/e12e53378efec6953520f66879c6822d.svg\" alt=\"$\\text{ARI} = 1$\" data-tex=\"inline\"\/><\/math>).<\/p>\n<p>  <\/p>\n<p><strong>Adjusted Mutual Information (AMI)<\/strong><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u043c\u0435\u0440\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0430 \u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5d4\/58b\/e9e\/5d458be9ed7bc9cd4287c2b7db562db3.svg\" alt=\"$\\text{ARI}$\" data-tex=\"inline\"\/><\/math>. \u041e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430, \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u043e\u0432\u043e\u043a \u043c\u0435\u0442\u043e\u043a. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 [\u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438](<a href=\"https:\/\/en.wikipedia.org\/wiki\/Entropy_(information_theory\">https:\/\/en.wikipedia.org\/wiki\/Entropy_(information_theory<\/a>), \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u043a\u0430\u043a \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f (\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u043a \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443 \u0440\u0430\u0432\u043d\u0430 \u0434\u043e\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043d\u0451\u043c). \u0418\u043d\u0434\u0435\u043a\u0441 $MI$ \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mutual_information\">\u0432\u0437\u0430\u0438\u043c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f<\/a> \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b. \u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e, \u0432\u0437\u0430\u0438\u043c\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u0434\u043e\u043b\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043e\u0431\u0449\u0435\u0439 \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439: \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u0431 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u043d\u0438\u0445 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0433\u043e.<\/p>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5d4\/58b\/e9e\/5d458be9ed7bc9cd4287c2b7db562db3.svg\" alt=\"$\\text{ARI}$\" data-tex=\"inline\"\/><\/math> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0434\u0435\u043a\u0441 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9b3\/f15\/9ea\/9b3f159eae4592435733759dfd95d883.svg\" alt=\"$\\text{AMI}$\" data-tex=\"inline\"\/><\/math>, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0440\u043e\u0441\u0442\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/810\/597\/c01\/810597c01937f43eee7a469d59893687.svg\" alt=\"$MI$\" data-tex=\"inline\"\/><\/math> \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041e\u043d \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/98c\/d33\/dce\/98cd33dce388730949b3d9a9dfcc8f9d.svg\" alt=\"$[0, 1]$\" data-tex=\"inline\"\/><\/math>. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a \u043d\u0443\u043b\u044e, \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439, \u0430 \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a \u0435\u0434\u0438\u043d\u0438\u0446\u0435 \u2013 \u043e\u0431 \u0438\u0445 \u0441\u0445\u043e\u0436\u0435\u0441\u0442\u0438 (\u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u043f\u0440\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/6bb\/bba\/b2d\/6bbbbab2d7cbf3ce0a392928ea4ba2df.svg\" alt=\"$\\text{AMI} = 1$\" data-tex=\"inline\"\/><\/math>).<\/p>\n<p>  <\/p>\n<p><strong>\u0413\u043e\u043c\u043e\u0433\u0435\u043d\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u043b\u043d\u043e\u0442\u0430, V-\u043c\u0435\u0440\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>\u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0440\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438 \u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043a\u0430\u043a \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f:<\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/ca7\/1f8\/18f\/ca71f818fd5a2858dc38be4d1b07379f.svg\" alt=\"$h = 1 - \\frac{H(C\\mid K)}{H(C)}, c = 1 - \\frac{H(K\\mid C)}{H(K)},$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  \u0437\u0434\u0435\u0441\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/c66\/881\/68c\/c6688168c78c959fb4e9040fda31393d.svg\" alt=\"$K$\" data-tex=\"inline\"\/><\/math> \u2014 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/daf\/e83\/7b2\/dafe837b2eb473c8c3a2240b85e4ca80.svg\" alt=\"$C$\" data-tex=\"inline\"\/><\/math> \u2014 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u044b. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2dd\/e59\/d44\/2dde59d44112ea10cc00261acdcb9434.svg\" alt=\"$h$\" data-tex=\"inline\"\/><\/math> \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b58\/414\/e96\/b58414e960548906adae5a204bed502e.svg\" alt=\"$c$\" data-tex=\"inline\"\/><\/math> \u2014 \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443. \u042d\u0442\u0438 \u043c\u0435\u0440\u044b \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u044b\u043c\u0438. \u041e\u0431\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/98c\/d33\/dce\/98cd33dce388730949b3d9a9dfcc8f9d.svg\" alt=\"$[0, 1]$\" data-tex=\"inline\"\/><\/math>, \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u042d\u0442\u0438 \u043c\u0435\u0440\u044b \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438, \u043a\u0430\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5d4\/58b\/e9e\/5d458be9ed7bc9cd4287c2b7db562db3.svg\" alt=\"$\\text{ARI}$\" data-tex=\"inline\"\/><\/math> \u0438\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/9b3\/f15\/9ea\/9b3f159eae4592435733759dfd95d883.svg\" alt=\"$\\text{AMI}$\" data-tex=\"inline\"\/><\/math>, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0447\u0438\u0441\u043b\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0438 \u043c\u0430\u043b\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0412 \u044d\u0442\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5d4\/58b\/e9e\/5d458be9ed7bc9cd4287c2b7db562db3.svg\" alt=\"$\\text{ARI}$\" data-tex=\"inline\"\/><\/math>. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0447\u0438\u0441\u043b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u043e\u043b\u0435\u0435 1000 \u0438 \u0447\u0438\u0441\u043b\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043c\u0435\u043d\u0435\u0435 10 \u0434\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043d\u0435 \u0442\u0430\u043a \u044f\u0432\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0430 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0443\u0447\u0451\u0442\u0430 \u043e\u0431\u0435\u0438\u0445 \u0432\u0435\u043b\u0438\u0447\u0438\u043d <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/2dd\/e59\/d44\/2dde59d44112ea10cc00261acdcb9434.svg\" alt=\"$h$\" data-tex=\"inline\"\/><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/b58\/414\/e96\/b58414e960548906adae5a204bed502e.svg\" alt=\"$c$\" data-tex=\"inline\"\/><\/math> \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432\u0432\u043e\u0434\u0438\u0442\u0441\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/aa1\/966\/998\/aa19669983960ff5360ddd59488ac1a4.svg\" alt=\"$V$\" data-tex=\"inline\"\/><\/math>-\u043c\u0435\u0440\u0430, \u043a\u0430\u043a \u0438\u0445 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0433\u0430\u0440\u043c\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0435:<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/58d\/27c\/337\/58d27c337f51c0b960e059a072e4780f.svg\" alt=\"$v = 2\\frac{hc}{h+c}.$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  <\/p>\n<p>\u041e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u043e\u0439 \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0445\u043e\u0436\u0438 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<p>  <\/p>\n<p><strong>\u0421\u0438\u043b\u0443\u044d\u0442<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u043c\u0435\u0442\u0440\u0438\u043a, \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442 \u0437\u043d\u0430\u043d\u0438\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0443 (\u043d\u0435\u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043d\u0443\u044e) \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u0438\u043b\u0443\u044d\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u0447\u0435\u0440\u0435\u0437 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/366\/a4b\/5c5\/366a4b5c5bdf260210b49a89f904efb9.svg\" alt=\"$a$\" data-tex=\"inline\"\/><\/math> \u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0437 \u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0447\u0435\u0440\u0435\u0437 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5d2\/218\/e72\/5d2218e7292f24a1ff72a7ba614d11e9.svg\" alt=\"$b$\" data-tex=\"inline\"\/><\/math> \u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0437 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 (\u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u0442 \u0442\u043e\u0433\u043e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u0435\u0436\u0438\u0442 \u0441\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442). \u0422\u043e\u0433\u0434\u0430 \u0441\u0438\u043b\u0443\u044d\u0442\u043e\u043c \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430: <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/1ac\/1da\/b15\/1ac1dab15e31116b37ca5ea0f33e3f0c.svg\" alt=\"$s = \\frac{b - a}{\\max(a, b)}.$\" data-tex=\"display\"\/><\/math><\/p>\n<p>  \u0421\u0438\u043b\u0443\u044d\u0442\u043e\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u0441\u0438\u043b\u0443\u044d\u0442\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u0438\u043b\u0443\u044d\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0432\u043e\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0440\u0435\u0434\u043d\u0435\u0433\u043e \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0414\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 \u043b\u0435\u0436\u0438\u0442 \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/7b7\/67e\/bf1\/7b767ebf15c29b116d9e6ca05734c433.svg\" alt=\"$[-1, 1]$\" data-tex=\"inline\"\/><\/math>. \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a -1, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043f\u043b\u043e\u0445\u0438\u043c (\u0440\u0430\u0437\u0440\u043e\u0437\u043d\u0435\u043d\u043d\u044b\u043c) \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f\u043c, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a \u043d\u0443\u043b\u044e, \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f \u0438 \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433 \u043d\u0430 \u0434\u0440\u0443\u0433\u0430, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043a 1, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 &quot;\u043f\u043b\u043e\u0442\u043d\u044b\u043c&quot; \u0447\u0435\u0442\u043a\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0438\u043b\u0443\u044d\u0442, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u0442\u043a\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b, \u0438 \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u044b\u0435, \u043f\u043b\u043e\u0442\u043d\u043e \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u043a\u0430 \u0442\u043e\u0447\u0435\u043a.<\/p>\n<p>  <\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0438\u043b\u0443\u044d\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/839\/452\/3d1\/8394523d1f4bab66a8544cd365388d87.svg\" alt=\"$k$\" data-tex=\"inline\"\/><\/math> (\u0435\u0441\u043b\u0438 \u043e\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e) \u2014 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0438\u043b\u0443\u044d\u0442\u0430. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u043c\u0435\u0442\u0440\u0438\u043a, \u0441\u0438\u043b\u0443\u044d\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0444\u043e\u0440\u043c\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u043f\u0443\u043a\u043b\u044b\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u0445, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0418 \u043d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u044d\u0442\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0446\u0438\u0444\u0440 MNIST:<\/p>\n<p>  <\/p>\n<pre><code class=\"python\">from sklearn import metrics from sklearn import datasets import pandas as pd from sklearn.cluster import KMeans, AgglomerativeClustering, AffinityPropagation, SpectralClustering  data = datasets.load_digits() X, y = data.data, data.target  algorithms = [] algorithms.append(KMeans(n_clusters=10, random_state=1)) algorithms.append(AffinityPropagation()) algorithms.append(SpectralClustering(n_clusters=10, random_state=1,                                      affinity='nearest_neighbors')) algorithms.append(AgglomerativeClustering(n_clusters=10))  data = [] for algo in algorithms:     algo.fit(X)     data.append(({         'ARI': metrics.adjusted_rand_score(y, algo.labels_),         'AMI': metrics.adjusted_mutual_info_score(y, algo.labels_),         'Homogenity': metrics.homogeneity_score(y, algo.labels_),         'Completeness': metrics.completeness_score(y, algo.labels_),         'V-measure': metrics.v_measure_score(y, algo.labels_),         'Silhouette': metrics.silhouette_score(X, algo.labels_)}))  results = pd.DataFrame(data=data, columns=['ARI', 'AMI', 'Homogenity',                                            'Completeness', 'V-measure',                                             'Silhouette'],                        index=['K-means', 'Affinity',                                'Spectral', 'Agglomerative'])  results<\/code><\/pre>\n<p>  <\/p>\n<table border=\"1\">\n<thead>\n<tr>\n<th><\/th>\n<th>ARI<\/th>\n<th>AMI<\/th>\n<th>Homogenity<\/th>\n<th>Completeness<\/th>\n<th>V-measure<\/th>\n<th>Silhouette<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<th>K-means<\/th>\n<td>0.662295<\/td>\n<td>0.732799<\/td>\n<td>0.735448<\/td>\n<td>0.742972<\/td>\n<td>0.739191<\/td>\n<td>0.182097<\/td>\n<\/tr>\n<tr>\n<th>Affinity<\/th>\n<td>0.175174<\/td>\n<td>0.451249<\/td>\n<td>0.958907<\/td>\n<td>0.486901<\/td>\n<td>0.645857<\/td>\n<td>0.115197<\/td>\n<\/tr>\n<tr>\n<th>Spectral<\/th>\n<td>0.752639<\/td>\n<td>0.827818<\/td>\n<td>0.829544<\/td>\n<td>0.876367<\/td>\n<td>0.852313<\/td>\n<td>0.182195<\/td>\n<\/tr>\n<tr>\n<th>Agglomerative<\/th>\n<td>0.794003<\/td>\n<td>0.856085<\/td>\n<td>0.857513<\/td>\n<td>0.879096<\/td>\n<td>0.868170<\/td>\n<td>0.178497<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>  <\/p>\n<h2 id=\"4-poleznye-istochniki\">4. \u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habrahabr.ru\/company\/io\/blog\/265089\/\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> &quot;\u041a\u0430\u043a \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u043b\u0430\u0442\u044c\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442&quot;<\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/users\/lexxo\/topics\/\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> &quot;\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (PCA) \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435&quot;<\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/321216\/\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> &quot;\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f: Affinity propagation&quot;<\/li>\n<li><a href=\"https:\/\/habrahabr.ru\/post\/322034\/\">\u0441\u0442\u0430\u0442\u044c\u044f<\/a> &quot;\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0447\u0430\u0441\u0442\u044c \u0432\u0442\u043e\u0440\u0430\u044f: DBSCAN&quot;<\/li>\n<li><a href=\"http:\/\/scikit-learn.org\/stable\/modules\/clustering.html\">\u043e\u0431\u0437\u043e\u0440<\/a> \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 \u043f\u0430\u043a\u0435\u0442\u0435 scikit-learn (\u0430\u043d\u0433\u043b.)<\/li>\n<li><a href=\"http:\/\/stats.stackexchange.com\/questions\/2691\/making-sense-of-principal-component-analysis-eigenvectors-eigenvalues\">Q&amp;A<\/a> \u0420\u0430\u0437\u0431\u043e\u0440 PCA \u0441 \u0438\u043d\u0442\u0443\u0438\u0446\u0438\u0435\u0439 \u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 (\u0430\u043d\u0433\u043b.)<\/li>\n<li><a href=\"https:\/\/github.com\/diefimov\/MTH594_MachineLearning\/blob\/master\/ipython\/Lecture10.ipynb\">\u0442\u0435\u0442\u0440\u0430\u0434\u043a\u0430<\/a> \u043f\u0440\u043e k-Means \u0438 EM-\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432 \u043a\u0443\u0440\u0441\u0435 \u0414\u043c\u0438\u0442\u0440\u0438\u044f \u0415\u0444\u0438\u043c\u043e\u0432\u0430 (\u0430\u043d\u0433\u043b.)<\/li>\n<li><a href=\"https:\/\/github.com\/esokolov\/ml-course-hse\/blob\/master\/2016-fall\/lecture-notes\/lecture12-unsupervised.pdf\">\u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442<\/a> &quot;\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f&quot; \u0432 \u043a\u0443\u0440\u0441\u0435 \u0415\u0432\u0433\u0435\u043d\u0438\u044f \u0421\u043e\u043a\u043e\u043b\u043e\u0432\u0430<\/li>\n<\/ul>\n<p>  <\/p>\n<p><em>\u0421\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 \u0441\u043e\u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u0435 \u0441 <a href=\"https:\/\/habrahabr.ru\/users\/yorko\/\" class=\"user_link\">yorko<\/a> (\u042e\u0440\u0438\u0435\u043c \u041a\u0430\u0448\u043d\u0438\u0446\u043a\u0438\u043c). \u041e \u0434\u043e\u043c\u0430\u0448\u043d\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0438 \u21167 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c \u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435.<\/em><\/p>\n<p> \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:\/\/habrahabr.ru\/post\/325654\/\"> https:\/\/habrahabr.ru\/post\/325654\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c! \u041f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u0441\u0435\u0434\u044c\u043c\u0443\u044e \u0442\u0435\u043c\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f!<\/p>\n<p>  <img decoding=\"async\" align=\"right\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/5be\/e8a\/297\/5bee8a297a98ce38da75f0a775f5eb3a.png\"\/>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435 \u043c\u044b \u043f\u043e\u0441\u0432\u044f\u0442\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0443\u0447\u0438\u0442\u0435\u043b\u044f (unsupervised learning), \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u0443 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 (PCA \u2014 principal component analysis) \u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0412\u044b \u0443\u0437\u043d\u0430\u0435\u0442\u0435, \u0437\u0430\u0447\u0435\u043c \u0441\u043d\u0438\u0436\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u0430\u043a \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u043a\u0430\u043a\u0438\u0435 \u0435\u0441\u0442\u044c \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u0445\u043e\u0436\u0438\u0445 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0439 \u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-284716","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284716","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=284716"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/284716\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=284716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=284716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=284716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}