{"id":464268,"date":"2025-06-24T03:00:11","date_gmt":"2025-06-24T03:00:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=464268"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=464268","title":{"rendered":"<span>\u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u043e ML\/DL, \u0447\u0430\u0441\u0442\u044c 2: \u0412\u043e\u043f\u0440\u043e\u0441 \u2192 \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442 \u2192 \u0420\u0430\u0437\u0431\u043e\u0440 \u2192 \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430. SVD\/PCA. Bias-variance. \u0414\u0435\u0440\u0435\u0432\u044c\u044f. \u0411\u0443\u0441\u0442\u0438\u043d\u0433<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e <strong>\u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c<\/strong> \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043f\u043b\u0430\u0441\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 ML. \u041f\u0440\u0438\u0447\u0438\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u0435 &#8212; \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044e, \u043d\u0430\u0447\u0430\u043b\u043e \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0430\u043b\u043e, \u043e\u0431\u044a\u0435\u043c\u0430 \u043c\u043d\u043e\u0433\u043e, \u0446\u0435\u043b\u0438 \u0430\u043c\u0431\u0438\u0446\u0438\u043e\u0437\u043d\u044b\u0435 &#8212; \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f <strong>\u043b\u0435\u0433\u043a\u043e<\/strong> \u0438 <strong>\u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c<\/strong>, \u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043d\u0435 \u043b\u0438\u0448\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b!<\/p>\n<p>\ud83d\udcbb \u041e\u0431\u0440\u0430\u0449\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0441\u0430\u043c\u044b\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c &#8212; \u044d\u0442\u043e \u0441\u0432\u043e\u0438\u043c\u0438 <strong>\u0440\u0443\u043a\u0430\u043c\u0438 \u043f\u043e\u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443<\/strong>! \u042d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435, \u043e\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 \u0441 \u043a\u043e\u0434\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0430\u043c\u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0441\u0432\u043e\u044e!<\/p>\n<p><em>\u0411\u0443\u0434\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0430\u0448\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0445 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c!<\/em><\/p>\n<p>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c. \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u044b\u0442\u0430\u0439\u0442\u0435 \u0441\u0435\u0431\u044f \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/918438\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 [1] \u0447\u0430\u0441\u0442\u0438!<\/a><\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/mr\/cb\/cz\/mrcbczu4hasamlmeh6-ftywwmve.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/mr\/cb\/cz\/mrcbczu4hasamlmeh6-ftywwmve.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/mr\/cb\/cz\/mrcbczu4hasamlmeh6-ftywwmve.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u043b\u043d\u044b\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044b &#8212; \u044d\u0442\u043e \u0432\u0437\u044f\u0442\u044c <a href=\"https:\/\/github.com\/girafe-ai\/ml-course\/blob\/23f_basic\/exam_program.md\" rel=\"noopener noreferrer nofollow\">\u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u044d\u043a\u0437\u0430\u043c\u0435\u043d<\/a> \u0438 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b &#8212; \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e. \u0410 \u0447\u0442\u043e \u0431\u044b \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043b\u043e\u0441\u044c \u043b\u0443\u0447\u0448\u0435 &#8212; \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u043a\u0443. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<blockquote>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0430\u043c\u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430! \u0421\u0442\u0430\u043b\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435-\u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c?<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0443 \u0432\u0430\u0436\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438!<\/p>\n<\/blockquote>\n<hr\/>\n<h3>11. \u0410\u043d\u0430\u043b\u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0421\u0432\u044f\u0437\u044c \u0441 SVD. \u0422\u0435\u043e\u0440\u0435\u043c\u0430 \u042d\u043a\u043a\u0430\u0440\u0442\u0430-\u042f\u043d\u0433\u0430. \u041a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c PCA \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>PCA (Principal Component Analysis \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442)<\/strong> \u2014 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u0420\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0430\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438 \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u043d\u0433\u0430 (\u043a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/rekomendacii-na-osnove-matrichnyh-razlozhenij\" rel=\"noopener noreferrer nofollow\">ALS<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u0415\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 MSE \u0438\u043b\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u043e \u0441 <strong>SVD<\/strong><\/p>\n<\/li>\n<li>\n<p>\u0415\u0449\u0435 \u043e\u0434\u043d\u0430 \u0438\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f &#8212; \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u044e\u0437\u0435\u0440\u0430 \u0438 \u0442\u043e\u0432\u0430\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/o6\/yj\/ya\/o6yjyajqfl0kvc1g2kur9uooknw.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/o6\/yj\/ya\/o6yjyajqfl0kvc1g2kur9uooknw.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/o6\/yj\/ya\/o6yjyajqfl0kvc1g2kur9uooknw.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<ul>\n<li>\n<p>\u0418\u0449\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u043e\u0441\u0438 (\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f), \u0432\u0434\u043e\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 <strong>\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e<\/strong><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0435\u0446\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0442\u0430\u043a\u0438\u0445 \u043e\u0441\u0435\u0439 (\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442), \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f <strong>\u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438<\/strong> (\u0432 \u0441\u043c\u044b\u0441\u043b\u0435 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438) &#8212; \u043f\u043e\u0447\u0435\u043c\u0443? \u0438\u0434\u0435\u043c \u043a SVD<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/re\/kb\/r9\/rekbr9wa4tlfws4sqkvkb45ljbg.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/re\/kb\/r9\/rekbr9wa4tlfws4sqkvkb45ljbg.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/re\/kb\/r9\/rekbr9wa4tlfws4sqkvkb45ljbg.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<ul>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <strong>SVD<\/strong> (Singular value decomposition \u0438\u043b\u0438 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435) &#8212; \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043d\u0430 <strong>\u0434\u0432\u0435 \u043e\u0440\u0442\u043e\u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 [\u043f\u043e\u0432\u043e\u0440\u043e\u0442]<\/strong> \u0438 <strong>\u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u0443\u044e [\u0440\u0430\u0441\u0442\u044f\u0436\u0435\u043d\u0438\u0435]<\/strong> (\u0441 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438=\u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c\/\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/s6\/lj\/47\/s6lj47isa-xzk0hs41cqh9r5yrs.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/s6\/lj\/47\/s6lj47isa-xzk0hs41cqh9r5yrs.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/s6\/lj\/47\/s6lj47isa-xzk0hs41cqh9r5yrs.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u043e\u043a\u0438 \u0443 \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f) <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438!<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/pw\/ho\/zb\/pwhozbc0dpvh__3qeriyniel8zg.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/pw\/ho\/zb\/pwhozbc0dpvh__3qeriyniel8zg.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/pw\/ho\/zb\/pwhozbc0dpvh__3qeriyniel8zg.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<ul>\n<li>\n<p>\u0422\u0435\u043e\u0440\u0435\u043c\u0430 \u042d\u043a\u043a\u0430\u0440\u0442\u0430-\u042f\u043d\u0433\u0430 &#8212; \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442, \u0442\u0430\u043a\u0430\u044f \u0430\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u0430\u043d\u0433\u0430 \u043f\u043e \u043d\u043e\u0440\u043c\u0435 \u0424\u0440\u043e\u0431\u0435\u043d\u0438\u0443\u0441\u0430 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0430\u044f!<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430 \u043e\u0434\u043d\u043e\u043c \u0434\u044b\u0445\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/youtu.be\/mlA-XxC9Ugg?si=8a1Edzx5RE6bPvki&amp;t=2923\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0442\u0443\u0442<\/a> \u0438\u043b\u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/matrichnaya-faktorizaciya\" rel=\"noopener noreferrer nofollow\">\u0445\u0435\u043d\u0434\u0431\u0443\u043a<\/a>. \u041e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 <a href=\"https:\/\/www.youtube.com\/watch?v=gXbThCXjZFM&amp;list=PLMrJAkhIeNNSVjnsviglFoY2nXildDCcv&amp;index=1\" rel=\"noopener noreferrer nofollow\">\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u0432\u0438\u0434\u0435\u043e\u0444\u043e\u0440\u043c\u0430\u0442<\/a> .<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0421\u0436\u0438\u043c\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 SVD \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u043a\u043e\u043b-\u0432\u043e\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SVD !<\/p>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_sample_image from skimage.color import rgb2gray from skimage.transform import resize  # --- \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 china = load_sample_image(\"china.jpg\")   # \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 gray = rgb2gray(china)                   # \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0432 \u0447\/\u0431 gray = resize(gray, (256, 256), anti_aliasing=True)  # \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0434\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430  # --- SVD U, S, VT = np.linalg.svd(gray, full_matrices=False)  # --- \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 k ks = [5, 20, 50, 100, 200] fig, axes = plt.subplots(1, len(ks) + 1, figsize=(15, 4))  # \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b axes[0].imshow(gray, cmap='gray') axes[0].set_title(\"\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\") axes[0].axis('off')  # \u041f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 k for i, k in enumerate(ks):     approx = U[:, :k] @ np.diag(S[:k]) @ VT[:k, :]     axes[i + 1].imshow(approx, cmap='gray')     axes[i + 1].set_title(f\"k = {k}\")     axes[i + 1].axis('off')  plt.suptitle(\"\u0421\u0436\u0430\u0442\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SVD\") plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/pv\/sg\/xa\/pvsgxavj2ysk1uvr-8jfxgctmeu.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/pv\/sg\/xa\/pvsgxavj2ysk1uvr-8jfxgctmeu.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/pv\/sg\/xa\/pvsgxavj2ysk1uvr-8jfxgctmeu.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<pre><code class=\"python\"># \u0420\u0430\u0441\u0447\u0451\u0442 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0439 \u0434\u043e\u043b\u0438 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 explained = np.cumsum(S) \/ np.sum(S)  # \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430: \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 + \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043b\u044f fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 5))  # --- 1. \u0421\u0430\u043c\u0438 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 (\u0432 \u043b\u043e\u0433 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0435) ax1.plot(S, marker='o') ax1.set_yscale(\"log\") ax1.set_title(\"\u0421\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\") ax1.set_xlabel(\"\u041d\u043e\u043c\u0435\u0440 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b\") ax1.set_ylabel(\"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (log)\") ax1.grid(True)  # --- 2. \u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 ax2.plot(explained, label='C\u0443\u043c\u043c\u0430\u0440\u043d\u0430\u044f \u0434\u043e\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438') ax2.axhline(0.9, color='red', linestyle='--', label='90% \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438') ax2.set_xlabel(\"\u0427\u0438\u0441\u043b\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\") ax2.set_ylabel(\"\u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043b\u044f\") ax2.set_title(\"\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u0443\u0442 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\") ax2.grid(True) ax2.legend()  plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/zm\/14\/p1\/zm14p1pdxfvr1roesstkcmr590k.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/zm\/14\/p1\/zm14p1pdxfvr1roesstkcmr590k.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/zm\/14\/p1\/zm14p1pdxfvr1roesstkcmr590k.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u0440\u043e\u0435\u0446\u0438\u0440\u0443\u0435\u043c \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0446\u0438\u0444\u0440) \u0432 2D \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PCA<\/summary>\n<div class=\"spoiler__content\">\n<p> \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0446\u0438\u0444\u0440 (digits) \u2014 \u0432 \u043d\u0451\u043c 64 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 (8\u00d78 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430), \u0438 \u0441\u043e\u0436\u043c\u0451\u043c \u0434\u043e 2 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a PCA \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b: <\/p>\n<pre><code class=\"python\">from sklearn.datasets import load_digits from sklearn.decomposition import PCA import matplotlib.pyplot as plt  # --- \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 digits = load_digits() X = digits.data       # 64 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 (8x8 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439) y = digits.target     # \u043c\u0435\u0442\u043a\u0438 (0-9)  # --- PCA \u0434\u043e 2 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 pca = PCA(n_components=2) X_pca = pca.fit_transform(X)  # --- \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(8, 6)) scatter = plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, cmap='tab10', s=15, alpha=0.8) plt.legend(*scatter.legend_elements(), title=\"\u0426\u0438\u0444\u0440\u044b\", loc=\"best\", bbox_to_anchor=(1.05, 1)) plt.title(\"PCA-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (64D \u2192 2D)\") plt.xlabel(\"1-\u044f \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\") plt.ylabel(\"2-\u044f \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\") plt.grid(True) plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/32\/oi\/6q\/32oi6qlfm_qaflaxy30fnab1ipw.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/32\/oi\/6q\/32oi6qlfm_qaflaxy30fnab1ipw.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/32\/oi\/6q\/32oi6qlfm_qaflaxy30fnab1ipw.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h3>12. \u042d\u0442\u0430\u043f\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0435\u0451 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 ML-\u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <strong>\u0442\u0440\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u044d\u0442\u0430\u043f\u0430<\/strong>:<\/p>\n<ol>\n<li>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 (train)<\/strong> \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f (validation)<\/strong> \u2014 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u043c \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u0422\u0435\u0441\u0442 (test)<\/strong> \u2014 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<\/li>\n<\/ol>\n<blockquote>\n<p>\u0411\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u0442\u0435\u0441\u0442 \u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u0440\u0443\u0442 \u043b\u0443\u0447\u0448\u0435\u0435 \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043d\u043e \u044d\u0442\u043e \u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<\/blockquote>\n<hr\/>\n<p><strong>\u041f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435<\/strong> \u2014 \u044d\u0442\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0433\u043e\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u043d\u043e \u043f\u043b\u043e\u0445\u043e \u043e\u0431\u043e\u0431\u0449\u0430\u0435\u0442 \u043d\u0430 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 train\/val\/test \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <strong>\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0444\u043e\u043b\u0434\u0430\u043c (k-fold cross-validation)<\/strong> &#8212; \u041e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0447\u0430\u0441\u0442\u0435\u0439, \u043d\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"k - 1\" alt=\"k - 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0e\/0e4\/0e4b332cc0e37403dff51019ff361775.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0e\/0e4\/0e4b332cc0e37403dff51019ff361775.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0e\/0e4\/0e4b332cc0e37403dff51019ff361775.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0447\u0438\u0442\u044c\u0441\u044f, \u043d\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0437\u0430\u043c\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e. \u041c\u0435\u0442\u0440\u0438\u043a\u0430 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<blockquote>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0434\u0445\u043e\u0434 \u0445\u043e\u0442\u044c \u0443\u0441\u0442\u043e\u0439\u0447\u0435\u0432\u0435\u0435 \u043a \u0448\u0443\u043c\u0443, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u044d\u0433\u0433\u0438\u043d\u0433 \u043d\u0430\u0434 \u044d\u0442\u0438\u043c\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041e\u0431\u044b\u0447\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 EDA (exploratory data analysis \u0438\u043b\u0438 \u0440\u0430\u0437\u0432\u0435\u0434\u043e\u0447\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437) \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442, \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 train\/val\/test \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438 \u0443\u0447\u0430\u0442 \u043e\u0434\u043d\u0443 \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<\/blockquote>\n<hr\/>\n<p><strong>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0430\u0442\u044c\u0441\u044f?<\/strong> (\u0435\u0441\u043b\u0438 \u043d\u0435\u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0447\u0435\u043a\u043f\u043e\u0438\u043d\u0442\u044b, \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e!)<\/p>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0430 \u043d\u0430 train \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043f\u0430\u0434\u0430\u0442\u044c, \u0430 \u043d\u0430 val \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u0442\u044c. (\u0415\u0441\u043b\u0438 \u043d\u0435\u0442\u0443 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432, \u0442\u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043d\u0430 train \u0441\u0438\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043d\u0430 val)<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f?<\/strong><\/p>\n<ul>\n<li>\n<p>Early stopping (\u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u043b\u0430\u0441\u044c k \u0448\u0430\u0433\u043e\u0432 &#8212; \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 &#8212;  <img decoding=\"async\" class=\"formula inline\" source=\"L_1\" alt=\"L_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2c\/2c6\/2c6f3b6c16df97a1b00e04ff17e4906e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2c\/2c6\/2c6f3b6c16df97a1b00e04ff17e4906e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2c\/2c6\/2c6f3b6c16df97a1b00e04ff17e4906e.svg 781w\" loading=\"lazy\" decode=\"async\"\/>\/<img decoding=\"async\" class=\"formula inline\" source=\"L_2\" alt=\"L_2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/07\/07c\/07cbd6c155424e110559a84df364be5a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/07\/07c\/07cbd6c155424e110559a84df364be5a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/07\/07c\/07cbd6c155424e110559a84df364be5a.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, Dropout\/BatchNorm, \u0430\u0443\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442\u0434<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0437\u043d\u0430\u0447\u0430\u0449\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 (\u0435\u0441\u043b\u0438 \u0438\u0445 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e, \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u043d\u0438\u0445 \u043e\u0442\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f, \u043c\u043e\u0436\u0435\u0442 \u0438 \u0441\u043e\u0439\u0434\u0435\u0442\u0441\u044f, \u043d\u043e \u0434\u041e\u043b\u044c\u0448\u0435!)<\/p>\n<\/li>\n<li>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0441\u044b\u043f\u0430\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u0411\u044d\u0433\u0433\u0438\u043d\u0433 (Bagging, \u043e\u0442 bootstrap aggregating) &#8212; \u0443\u0447\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u0431\u0443\u0442\u0441\u0440\u0435\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c =&gt; \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0438\u043c\u043f\u0442\u043e\u043c\u044b \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u043c\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c Double Descent) <\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/mk\/gu\/ef\/mkguef2-hdp5olyjuj_jf69aev0.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/mk\/gu\/ef\/mkguef2-hdp5olyjuj_jf69aev0.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/mk\/gu\/ef\/mkguef2-hdp5olyjuj_jf69aev0.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443 \u0432\u0430\u0441 Double Descent. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043b\u043e\u0441\u0441 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u0437\u043b\u0435\u0442\u0438\u0442, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u043d\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439!<\/p>\n<blockquote>\n<p>\u042f \u043d\u0435 \u0437\u043d\u0430\u044e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0443 \u043a\u043e\u0433\u043e \u0442\u0430\u043a\u043e\u0435 \u0431\u044b\u043b\u043e. \u041d\u043e \u043a\u0430\u043a \u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435.<\/p>\n<\/blockquote>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/6a\/ui\/_p\/6aui_p4wkqfvh2orda_taoochss.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/6a\/ui\/_p\/6aui_p4wkqfvh2orda_taoochss.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/6a\/ui\/_p\/6aui_p4wkqfvh2orda_taoochss.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e Double Descent \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/mlu-explain.github.io\/double-descent\/\" rel=\"noopener noreferrer nofollow\">1<\/a> \u0438 <a href=\"https:\/\/mlu-explain.github.io\/double-descent2\/\" rel=\"noopener noreferrer nofollow\">2<\/a>.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f: \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0437\u0430 \u043b\u043e\u0441\u0441\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c\u0438 <\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043f\u043e\u0445 \u0441 \u043b\u043e\u0441\u0441\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c\u0438, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<blockquote>\n<p>\u042f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u043d\u044c\u043e \u0432\u0437\u044f\u043b \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0442\u043e\u0447\u0435\u043a (=150), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b\/\u0440\u0430\u0437\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u043c \u043d\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/blockquote>\n<pre><code class=\"python\">import torch import torch.nn as nn import torch.optim as optim from sklearn.datasets import make_moons from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt import numpy as np  # --- 1. \u0414\u0430\u043d\u043d\u044b\u0435 X, y_true = make_moons(n_samples=150, noise=0.3, random_state=42) # y_random = np.random.permutation(y_true)  # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438!  # X_train, X_val, y_train, y_val = train_test_split(X, y_random, test_size=0.3, random_state=42) X_train, X_val, y_train, y_val = train_test_split(X, y_true, test_size=0.3, random_state=42)  X_train_t = torch.tensor(X_train, dtype=torch.float32) y_train_t = torch.tensor(y_train.reshape(-1, 1), dtype=torch.float32)  X_val_t = torch.tensor(X_val, dtype=torch.float32) y_val_t = torch.tensor(y_val.reshape(-1, 1), dtype=torch.float32)  # --- 2. \u041c\u043e\u0434\u0435\u043b\u044c # h_size = 256 h_size = 100 model = nn.Sequential(     nn.Linear(2, h_size),     nn.ReLU(),     nn.Linear(h_size, h_size),     nn.ReLU(),     nn.Linear(h_size, 1),     nn.Sigmoid() )  loss_fn = nn.BCELoss() optimizer = optim.Adam(model.parameters(), lr=0.01)  train_losses, val_losses = [], [] snapshots = [0, 10, 30, 99]  # \u044d\u043f\u043e\u0445\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e  grids = np.meshgrid(     np.linspace(X[:, 0].min() - 0.5, X[:, 0].max() + 0.5, 300),     np.linspace(X[:, 1].min() - 0.5, X[:, 1].max() + 0.5, 300) ) grid_points = np.c_[grids[0].ravel(), grids[1].ravel()] grid_tensor = torch.tensor(grid_points, dtype=torch.float32)  # --- 3. \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 snapshots_preds = []  for epoch in range(100):     model.train()     y_pred = model(X_train_t)     loss = loss_fn(y_pred, y_train_t)          optimizer.zero_grad()     loss.backward()     optimizer.step()      model.eval()     with torch.no_grad():         val_pred = model(X_val_t)         val_loss = loss_fn(val_pred, y_val_t)         if epoch in snapshots:             pred_grid = model(grid_tensor).reshape(300, 300)             snapshots_preds.append((epoch, pred_grid.numpy()))          train_losses.append(loss.item())     val_losses.append(val_loss.item())  # --- 4. \u0413\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u0442\u0435\u0440\u044c plt.figure(figsize=(8, 5)) plt.plot(train_losses, label='Train Loss') plt.plot(val_losses, label='Validation Loss') plt.axvline(np.argmin(val_losses), linestyle='--', color='gray', label='\u041b\u0443\u0447\u0448\u0430\u044f \u044d\u043f\u043e\u0445\u0430 (val)') plt.title(\"\u041f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435: \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0441\u0442\u0438\") plt.xlabel(\"\u042d\u043f\u043e\u0445\u0430\") plt.ylabel(\"Binary CrossEntropy\") plt.legend() plt.grid(True) plt.tight_layout() plt.show()  # --- 5. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 + \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f fig, axes = plt.subplots(1, len(snapshots_preds), figsize=(16, 4)) for ax, (epoch, Z) in zip(axes, snapshots_preds):     ax.contourf(grids[0], grids[1], Z, levels=20, cmap='coolwarm', alpha=0.7)     ax.scatter(*X_train.T, c=y_train, cmap='bwr', s=15, edgecolor='k', label='Train')     ax.scatter(*X_val.T, c=y_val, cmap='bwr', marker='x', s=15, label='Val')     ax.set_title(f\"\u042d\u043f\u043e\u0445\u0430 {epoch}\")     ax.axis('off') plt.suptitle(\"\u041a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0448\u0443\u043c: \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c\") plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/mk\/gu\/ef\/mkguef2-hdp5olyjuj_jf69aev0.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/mk\/gu\/ef\/mkguef2-hdp5olyjuj_jf69aev0.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/mk\/gu\/ef\/mkguef2-hdp5olyjuj_jf69aev0.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/bu\/zp\/2c\/buzp2cfb7sigb3kbv-qbmaid-yg.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/bu\/zp\/2c\/buzp2cfb7sigb3kbv-qbmaid-yg.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/bu\/zp\/2c\/buzp2cfb7sigb3kbv-qbmaid-yg.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0438\u043d\u043e\u043c\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"># \u041f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0441\u043b\u0435 \u0441\u0431\u0440\u043e\u0441\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f import numpy as np import matplotlib.pyplot as plt from sklearn.preprocessing import PolynomialFeatures from sklearn.linear_model import LinearRegression from sklearn.pipeline import make_pipeline from sklearn.metrics import mean_squared_error from sklearn.model_selection import train_test_split  # --- 1. \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 np.random.seed(42) X = np.linspace(-3, 3, 10).reshape(-1, 1)  # \u043c\u0430\u043b\u043e \u0442\u043e\u0447\u0435\u043a y = np.sin(X).ravel() + 0.3 * np.random.randn(*X.shape).ravel()  X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.3, random_state=42)  # --- 2. \u041e\u0431\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u043f\u043e\u043b\u0438\u043d\u043e\u043c\u0430 degrees = [1, 4, 15] preds = {} val_errors = {}  x_plot = np.linspace(-3, 3, 300).reshape(-1, 1)  plt.figure(figsize=(15, 4))  for i, deg in enumerate(degrees):     model = make_pipeline(PolynomialFeatures(degree=deg), LinearRegression())     model.fit(X_train, y_train)          y_plot = model.predict(x_plot)     y_val_pred = model.predict(X_val)     val_errors[deg] = mean_squared_error(y_val, y_val_pred)          plt.subplot(1, 3, i + 1)     plt.scatter(X_train, y_train, label='Train', color='blue')     plt.scatter(X_val, y_val, label='Val', color='red', alpha=0.5)     plt.plot(x_plot, y_plot, color='green', label=f\"Poly deg={deg}\")     plt.title(f\"deg={deg} | val MSE={val_errors[deg]:.2f}\")     plt.legend()     plt.grid(True)  plt.suptitle(\"\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e \u043f\u043e\u043b\u0438\u043d\u043e\u043c\u0430\") plt.tight_layout() plt.show()  val_errors # {1: 0.0623793189026051, 4: 0.16693688909602888, 15: 714985.2317858242} <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/bi\/45\/b2\/bi45b2w20uvuppaffbvpllmxr0i.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/bi\/45\/b2\/bi45b2w20uvuppaffbvpllmxr0i.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/bi\/45\/b2\/bi45b2w20uvuppaffbvpllmxr0i.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h3>13. \u0421\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438. \u041a\u0440\u043e\u0441\u0441-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f. \u0423\u0442\u0435\u0447\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/strong> \u2014 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043e\u043d\u044f\u0442\u044c, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u043d\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438:<\/p>\n<ul>\n<li>\n<p><strong>Hold-Out<\/strong> \u2014 \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0435\u043b\u0438\u043c \u043d\u0430 train\/val.<\/p>\n<\/li>\n<li>\n<p><strong>K-Fold<\/strong> \u2014 \u0443\u0447\u0438\u043c <img decoding=\"async\" class=\"formula inline\" source=\"k\" alt=\"k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8c\/8ce\/8ce4b16b22b58894aa86c421e8759df3.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0435\u043c \u043f\u043e \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0444\u043e\u043b\u0434\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>Stratified K-Fold<\/strong> \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>TimeSeriesSplit<\/strong> \u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0448\u043b\u043e\u0435, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0431\u0443\u0434\u0443\u0449\u0435\u0435.<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><strong>Data leakage (\u0443\u0442\u0435\u0447\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445)<\/strong> \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u0438\u0434\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u0430:<\/p>\n<ul>\n<li>\n<p>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043b\u0438 \u0432\u044b\u0431\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u043e train\/val split<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>target<\/code> \u0432 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u0445<\/p>\n<\/li>\n<li>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0443\u0442\u0435\u0447\u043a\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0441\u0432\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043c\u0435\u0442\u0440\u0438\u043a\u0443, \u0430 \u043d\u0430 \u043f\u0440\u043e\u0434\u043e\u0432\u044b\u0445 \u0441\u0438\u043b\u044c\u043d\u043e \u0445\u0443\u0436\u0435.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f val \u0443\u0442\u0435\u0447\u043a\u0438 \u0432 train. \u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0442\u0431\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 SelectKBest \u043d\u0430 train VS train + val.<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0423\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0441 \u043a\u0440\u043e\u0441\u0441\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0435\u0439 \u0443\u0442\u0435\u0447\u043a\u0430 \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0435\u0442\u0440\u0438\u043a\u0443!<\/p>\n<pre><code class=\"python\">import numpy as np from sklearn.datasets import make_classification from sklearn.model_selection import cross_val_score from sklearn.feature_selection import SelectKBest, f_classif from sklearn.ensemble import RandomForestClassifier from sklearn.pipeline import make_pipeline  # --- \u0414\u0430\u043d\u043d\u044b\u0435: \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0445 X, y = make_classification(     n_samples=1000, n_features=500, n_informative=30,     random_state=42, shuffle=False )  # --- \u26a0\ufe0f \u0423\u0442\u0435\u0447\u043a\u0430: \u043e\u0442\u0431\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0414\u041e cross-validation selector = SelectKBest(score_func=f_classif, k=50) X_leak = selector.fit_transform(X, y)  model = RandomForestClassifier(random_state=42) scores_leak = cross_val_score(model, X_leak, y, cv=5)  # --- \u2705 \u0427\u0435\u0441\u0442\u043d\u043e: \u043e\u0442\u0431\u043e\u0440 \u0444\u0438\u0447 \u0412\u041d\u0423\u0422\u0420\u0418 \u043a\u0440\u043e\u0441\u0441-\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 pipeline = make_pipeline(     SelectKBest(score_func=f_classif, k=50),     RandomForestClassifier(random_state=42) ) scores_clean = cross_val_score(pipeline, X, y, cv=5)  print(f\"\u26a0\ufe0f CV accuracy \u0441 \u0443\u0442\u0435\u0447\u043a\u043e\u0439:  {scores_leak.mean():.3f}\") print(f\"\u2705 CV accuracy \u0431\u0435\u0437 \u0443\u0442\u0435\u0447\u043a\u0438: {scores_clean.mean():.3f}\")  # \u26a0\ufe0f CV accuracy \u0441 \u0443\u0442\u0435\u0447\u043a\u043e\u0439:  0.787 # \u2705 CV accuracy \u0431\u0435\u0437 \u0443\u0442\u0435\u0447\u043a\u0438: 0.754 <\/code><\/pre>\n<\/div>\n<\/details>\n<h3>14. \u041a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f-\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 (Bias-variance trade-off).  Double Descent.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u042d\u0442\u043e \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 (\u0438 \u0441\u043f\u043e\u0441\u043e\u0431 \u0435\u0435 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c!) (\u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435) \u043d\u0430 \u0442\u0440\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b: <strong>bias<\/strong>, <strong>variance<\/strong>, <strong>noise<\/strong> (\u043d\u0430 \u043d\u0435\u0435 \u043d\u0435 \u0432\u043b\u0438\u044f\u0435\u043c). (\u0422\u0435\u043a\u0443\u0449\u0430\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0432\u0435\u0440\u043d\u0430 \u0434\u043b\u044f MSE, \u043d\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0438 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445!)<\/p>\n<p>\u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u043a \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0438 <strong>\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445<\/strong>: \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 <strong>bias<\/strong> \u043f\u0430\u0434\u0430\u0435\u0442, <strong>variance<\/strong> \u0440\u0430\u0441\u0442\u0435\u0442. \u0422\u043e\u0433\u0434\u0430 \u0441\u0443\u043c\u043c\u0430 \u0438\u0445 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 U-\u043e\u0431\u0440\u0430\u0437\u043d\u0430\u044f <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0435\u0441\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0443\u043c! (\u041f\u0440\u0438 <strong>Double Descent<\/strong> \u044d\u0442\u043e \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f!)<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/7i\/b0\/cu\/7ib0cu4vyhb4befp3mffjfml0ow.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/7i\/b0\/cu\/7ib0cu4vyhb4befp3mffjfml0ow.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/7i\/b0\/cu\/7ib0cu4vyhb4befp3mffjfml0ow.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u0440\u0430\u0439\u043d\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439 <strong>bias<\/strong> \u0438 <strong>variance<\/strong><\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/bz\/9r\/rr\/bz9rrrdqlskj0lexymd-iyeihwy.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/bz\/9r\/rr\/bz9rrrdqlskj0lexymd-iyeihwy.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/bz\/9r\/rr\/bz9rrrdqlskj0lexymd-iyeihwy.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<hr\/>\n<blockquote>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0438 \u043f\u043e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438<\/p>\n<\/blockquote>\n<p>\u041f\u0443\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"y(x, \\varepsilon) = f(x) + \\varepsilon\" alt=\"y(x, \\varepsilon) = f(x) + \\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/59\/59c\/59cce17e08530e14a4f9bda78179116a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/59\/59c\/59cce17e08530e14a4f9bda78179116a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/59\/59c\/59cce17e08530e14a4f9bda78179116a.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441 \u0448\u0443\u043c\u043e\u043c.<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\mathbb{E}[\\varepsilon] = 0,\\quad \\mathrm{Var}[\\varepsilon] = \\mathbb{E}[\\varepsilon^2] = \\sigma^2\" alt=\"\\mathbb{E}[\\varepsilon] = 0,\\quad \\mathrm{Var}[\\varepsilon] = \\mathbb{E}[\\varepsilon^2] = \\sigma^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e4d\/e4db7ef3c88302b7f84d20ab8686798f.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e4d\/e4db7ef3c88302b7f84d20ab8686798f.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e4d\/e4db7ef3c88302b7f84d20ab8686798f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"x\" alt=\"x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9d\/9dd\/9dd4e461268c8034f5c8564e155c67a6.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9d\/9dd\/9dd4e461268c8034f5c8564e155c67a6.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9d\/9dd\/9dd4e461268c8034f5c8564e155c67a6.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438. <img decoding=\"async\" class=\"formula inline\" source=\"X\" alt=\"X\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430<\/p>\n<\/li>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"a(x, X)\" alt=\"a(x, X)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/60\/601\/601344777ac7516f5331d8c000377489.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/60\/601\/601344777ac7516f5331d8c000377489.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/60\/601\/601344777ac7516f5331d8c000377489.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"X\" alt=\"X\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg 781w\" loading=\"lazy\" decode=\"async\"\/>,<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u043e\u0433\u0434\u0430 <strong>\u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430<\/strong> (MSE) \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438\u043c\u0435\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\mathbb{E}_x \\mathbb{E}_{X, \\varepsilon} \\left[ y(x, \\varepsilon) - a(x, X) \\right]^2= \\mathbb{E}_x \\left( \\underbrace{\\left( \\mathbb{E}_X[a(x, X)] - f(x) \\right)^2}_{\\text{\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 (bias)}^2}+ \\underbrace{\\text{Var}_X[a(x, X)]}_{\\text{\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f (variance)}}+ \\underbrace{\\sigma^2}_{\\text{\u0448\u0443\u043c}} \\right)\" alt=\"\\mathbb{E}_x \\mathbb{E}_{X, \\varepsilon} \\left[ y(x, \\varepsilon) - a(x, X) \\right]^2= \\mathbb{E}_x \\left( \\underbrace{\\left( \\mathbb{E}_X[a(x, X)] - f(x) \\right)^2}_{\\text{\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 (bias)}^2}+ \\underbrace{\\text{Var}_X[a(x, X)]}_{\\text{\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f (variance)}}+ \\underbrace{\\sigma^2}_{\\text{\u0448\u0443\u043c}} \\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/18\/18d\/18dd37012c339d49c643a44c0ea929b5.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/18\/18d\/18dd37012c339d49c643a44c0ea929b5.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/18\/18d\/18dd37012c339d49c643a44c0ea929b5.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<hr\/>\n<p>\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\text{bias}_X[a(x, X)] = \\mathbb{E}_X[a(x, X)] - f(x)\" alt=\"\\text{bias}_X[a(x, X)] = \\mathbb{E}_X[a(x, X)] - f(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/77\/772\/772365520801b0cd7923e7f9a8c07fcd.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/77\/772\/772365520801b0cd7923e7f9a8c07fcd.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/77\/772\/772365520801b0cd7923e7f9a8c07fcd.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<ul>\n<li>\n<p><strong>\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 (bias)<\/strong>  \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 \u0442\u043e\u0447\u043a\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"x\" alt=\"x\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9d\/9dd\/9dd4e461268c8034f5c8564e155c67a6.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9d\/9dd\/9dd4e461268c8034f5c8564e155c67a6.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9d\/9dd\/9dd4e461268c8034f5c8564e155c67a6.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0443\u0441\u0440\u0435\u0434\u043d\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u043c, \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"f\" alt=\"f\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8f\/8fa\/8fa14cdd754f91cc6554c9e71929cce7.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8f\/8fa\/8fa14cdd754f91cc6554c9e71929cce7.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8f\/8fa\/8fa14cdd754f91cc6554c9e71929cce7.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\text{Var}_X[a(x, X)] = \\mathbb{E}_X\\left[(a(x, X) - \\mathbb{E}_X[a(x, X)])^2\\right]\" alt=\"\\text{Var}_X[a(x, X)] = \\mathbb{E}_X\\left[(a(x, X) - \\mathbb{E}_X[a(x, X)])^2\\right]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/81\/81a\/81aae8d5623bf40d5be6ad8320424e06.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/81\/81a\/81aae8d5623bf40d5be6ad8320424e06.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/81\/81a\/81aae8d5623bf40d5be6ad8320424e06.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<li>\n<p><strong>\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f (variance)<\/strong>  \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"X\" alt=\"X\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/021\/02129bb861061d1a052c592e2dc6b383.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\sigma^2 = \\mathbb{E}_x \\mathbb{E}_\\varepsilon \\left[ y(x, \\varepsilon) - f(x) \\right]^2\" alt=\"\\sigma^2 = \\mathbb{E}_x \\mathbb{E}_\\varepsilon \\left[ y(x, \\varepsilon) - f(x) \\right]^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c8\/c87\/c87bae754c4145de8d37b9722ff7846a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c8\/c87\/c87bae754c4145de8d37b9722ff7846a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c8\/c87\/c87bae754c4145de8d37b9722ff7846a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<ul>\n<li>\n<p>\u043d\u0435\u0443\u0441\u0442\u0440\u0430\u043d\u0438\u043c\u044b\u0439 <strong>\u0448\u0443\u043c<\/strong> \u0432 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0441\u043b\u0430\u0436\u0434\u0430\u0435\u043c\u0441\u044f <a href=\"https:\/\/mlu-explain.github.io\/bias-variance\/\" rel=\"noopener noreferrer nofollow\">MLU-explAIn<\/a> \u0438 \u043f\u043e\u0442\u043e\u043c \u0438\u0434\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c \u0441 \u0432\u044b\u0432\u043e\u0434\u0430\u043c\u0438 \u0444\u043e\u0440\u043c\u0443\u043b <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/bias-variance-decomposition\" rel=\"noopener noreferrer nofollow\">\u0445\u0435\u043d\u0434\u0431\u0443\u043a<\/a><\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb Bias\u2013Variance \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435. \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 \u043e\u0434\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435. <\/summary>\n<div class=\"spoiler__content\">\n<p>\u041c\u044b \u043e\u0431\u0443\u0447\u0438\u043c \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 (\u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c) \u0441 \u0448\u0443\u043c\u043e\u043c \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435, \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u0438 \u0448\u0443\u043c \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0434\u0435\u0440\u0435\u0432\u0430. \u0410 \u0442\u0430\u043a\u0436\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c, \u043a\u0430\u043a \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0438\u0445 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import make_regression from sklearn.tree import DecisionTreeRegressor from sklearn.linear_model import LinearRegression from sklearn.model_selection import train_test_split from sklearn.utils import resample  # --- \u0414\u0430\u043d\u043d\u044b\u0435 X_all, y_all = make_regression(n_samples=1000, n_features=1, noise=15, random_state=42) X_train, X_val, y_train, y_val = train_test_split(X_all, y_all, test_size=0.3, random_state=42) X_clean, y_clean = make_regression(n_samples=300, n_features=1, noise=0, random_state=42) true_model = LinearRegression().fit(X_clean, y_clean)  X_test = np.linspace(X_all.min(), X_all.max(), 200).reshape(-1, 1) true_y = true_model.predict(X_test)  # --- Bias\u00b2, Variance, Noise depths = range(1, 20) n_models = 100 biases, variances, noises = [], [], [] models_by_depth = {d: [] for d in [1, 4, 10]}  for d in depths:     preds = []     for _ in range(n_models):         X_boot, y_boot = resample(X_train, y_train)         model = DecisionTreeRegressor(max_depth=d)         model.fit(X_boot, y_boot)         y_pred = model.predict(X_test)         preds.append(y_pred)         if d in models_by_depth and len(models_by_depth[d]) &lt; 50:             models_by_depth[d].append(y_pred)     preds = np.array(preds)     mean_preds = preds.mean(axis=0)     bias2 = ((mean_preds - true_y) ** 2).mean()     var = preds.var(axis=0).mean()     noise = np.var(y_val - model.predict(X_val))  # \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0451\u043d\u043d\u043e     biases.append(bias2)     variances.append(var)     noises.append(noise)  # --- \u0413\u0440\u0430\u0444\u0438\u043a \u043e\u0448\u0438\u0431\u043e\u043a plt.figure(figsize=(10, 6)) plt.plot(depths, biases, label='Bias\u00b2') plt.plot(depths, variances, label='Variance') plt.plot(depths, noises, label='Noise (\u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0451\u043d\u043d\u043e)') plt.plot(depths, np.array(biases) + np.array(variances) + np.array(noises),          label='Total Error', linestyle='--') plt.xlabel(\"\u0413\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u0430\") plt.ylabel(\"\u041e\u0448\u0438\u0431\u043a\u0430\") plt.title(\"Bias-Variance Trade-off\") plt.legend() plt.grid(True) plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/aj\/sr\/nc\/ajsrnce89tqhzniw9uqfqhwu_nu.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/aj\/sr\/nc\/ajsrnce89tqhzniw9uqfqhwu_nu.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/aj\/sr\/nc\/ajsrnce89tqhzniw9uqfqhwu_nu.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0441\u0430\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438: \u043d\u0430\u0440\u0438\u0441\u0443\u0435\u043c \u0432\u0441\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0433\u043b\u0443\u0431\u0438\u043d\u0430\u0445, \u0438\u0445 \u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 \u0438 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<pre><code class=\"python\"># --- \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 fig, axes = plt.subplots(1, 3, figsize=(18, 5), sharey=True) for ax, d in zip(axes, [1, 4, 10]):     all_preds = np.array(models_by_depth[d])     for y_pred in all_preds:         ax.plot(X_test.ravel(), y_pred, color='gray', alpha=0.2)     ax.plot(X_test.ravel(), all_preds.mean(axis=0), color='blue', linewidth=2, label='\u0423\u0441\u0440\u0435\u0434\u043d\u0451\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c')     ax.plot(X_test.ravel(), true_y, color='green', linestyle='--', label='f(x) (\u0438\u0441\u0442\u0438\u043d\u043d\u0430\u044f)')     ax.scatter(X_train, y_train, s=10, color='black', alpha=0.6, label='Train data')     ax.set_title(f\"\u0413\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u0430 = {d}\")     ax.set_xlabel(\"x\")     ax.legend()     ax.grid(True)  axes[0].set_ylabel(\"y\") plt.suptitle(\"\u0421\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432\") plt.tight_layout() plt.show()  <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/9f\/tj\/j9\/9ftjj9hsxz6qcaspgc3ojjcyayi.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/9f\/tj\/j9\/9ftjj9hsxz6qcaspgc3ojjcyayi.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/9f\/tj\/j9\/9ftjj9hsxz6qcaspgc3ojjcyayi.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u2014 \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0441\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0435. Train\/test \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u0430\u044f <img decoding=\"async\" class=\"formula inline\" source=\"f(x)\" alt=\"f(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/50\/50b\/50bbd36e1fd2333108437a2ca378be62.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/50\/50b\/50bbd36e1fd2333108437a2ca378be62.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/50\/50b\/50bbd36e1fd2333108437a2ca378be62.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<pre><code class=\"python\"># \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0444\u043e\u043d\u0435 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u043e\u0439 \u043f\u0440\u044f\u043c\u043e\u0439 plt.figure(figsize=(8, 5))  # \u041b\u0438\u043d\u0438\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 plt.plot(X_test, true_y, color='green', linestyle='--', label='f(x) (\u0438\u0441\u0442\u0438\u043d\u043d\u0430\u044f)')  # \u041e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0435 \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 plt.scatter(X_train, y_train, color='black', s=20, alpha=0.7, label='Train') plt.scatter(X_val, y_val, color='red', s=20, alpha=0.5, label='Test')  plt.xlabel(\"x\") plt.ylabel(\"y\") plt.title(\"\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445\") plt.grid(True) plt.legend() plt.tight_layout() plt.show()  <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/2v\/fv\/l7\/2vfvl7rsyjs73kzdhv784ftf3ay.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/2v\/fv\/l7\/2vfvl7rsyjs73kzdhv784ftf3ay.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/2v\/fv\/l7\/2vfvl7rsyjs73kzdhv784ftf3ay.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h3>15. \u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 (Decision tree).<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e, \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0443\u0437\u043b\u0435 \u043d\u0430 2 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u043f\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443 <img decoding=\"async\" class=\"formula inline\" source=\"x_j\" alt=\"x_j\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1f8\/1f89889020cdc84d9e1c35237cb62f65.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1f8\/1f89889020cdc84d9e1c35237cb62f65.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1f8\/1f89889020cdc84d9e1c35237cb62f65.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438 \u043f\u043e\u0440\u043e\u0433\u0443 <img decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e3\/e35\/e358efa489f58062f10dd7316b65649e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e3\/e35\/e358efa489f58062f10dd7316b65649e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e3\/e35\/e358efa489f58062f10dd7316b65649e.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0447\u0442\u043e\u0431\u044b <strong>\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c (impurity)<\/strong> (\u0447\u0435\u043c \u043d\u0438\u0436\u0435, \u0442\u0435\u043c \u043e\u0431\u044c\u0435\u043a\u0442\u044b \u0431\u043b\u0438\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c):<\/p>\n<p><strong>\u041f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0443\u0437\u043b\u0430:<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u0432\u0441\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"x_j\" alt=\"x_j\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1f8\/1f89889020cdc84d9e1c35237cb62f65.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1f8\/1f89889020cdc84d9e1c35237cb62f65.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1f\/1f8\/1f89889020cdc84d9e1c35237cb62f65.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u043e\u0440\u043e\u0433\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"t\" alt=\"t\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e3\/e35\/e358efa489f58062f10dd7316b65649e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e3\/e35\/e358efa489f58062f10dd7316b65649e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e3\/e35\/e358efa489f58062f10dd7316b65649e.svg 781w\" loading=\"lazy\" decode=\"async\"\/>. \u0412\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0441 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c \u043c\u0435\u043d\u044c\u0448\u0435 \u043f\u043e\u0440\u043e\u0433\u0430 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u043b\u0435\u0432\u044b\u0439 \u0443\u0437\u0435\u043b, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u043f\u0440\u0430\u0432\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442\u0441\u044f:<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\text{Impurity} = \\frac{n_\\text{left}}{n} \\cdot I(D_\\text{left}) + \\frac{n_\\text{right}}{n} \\cdot I(D_\\text{right})\" alt=\"\\text{Impurity} = \\frac{n_\\text{left}}{n} \\cdot I(D_\\text{left}) + \\frac{n_\\text{right}}{n} \\cdot I(D_\\text{right})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/27\/278\/27814fe5ddfd985ea1e0a1fd3332526a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/27\/278\/27814fe5ddfd985ea1e0a1fd3332526a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/27\/278\/27814fe5ddfd985ea1e0a1fd3332526a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0433\u0434\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"I(\\cdot)\" alt=\"I(\\cdot)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/027\/027d347fdc5625273039732242641b41.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/027\/027d347fdc5625273039732242641b41.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/02\/027\/027d347fdc5625273039732242641b41.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f impurity:<\/p>\n<ul>\n<li>\n<p>\u0414\u0436\u0438\u043d\u0438 \u0438\u043b\u0438 \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u044f (\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f)<\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\text{Gini}(p) = \\sum_{k=1}^{K} p_k (1 - p_k) = 1 - \\sum_{k=1}^{K} p_k^2\" alt=\"\\text{Gini}(p) = \\sum_{k=1}^{K} p_k (1 - p_k) = 1 - \\sum_{k=1}^{K} p_k^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/19\/195\/19599ccfc73a98ddbefa87fb786f6e4b.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/19\/195\/19599ccfc73a98ddbefa87fb786f6e4b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/19\/195\/19599ccfc73a98ddbefa87fb786f6e4b.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\text{Entropy}(p) = - \\sum_{k=1}^{K} p_k \\log_2 p_k\" alt=\"\\text{Entropy}(p) = - \\sum_{k=1}^{K} p_k \\log_2 p_k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/16d\/16d8b34cc52993b927568f80de8f181e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/16d\/16d8b34cc52993b927568f80de8f181e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/16d\/16d8b34cc52993b927568f80de8f181e.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f (\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f)<\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\text{MSE}(D) = \\frac{1}{n} \\sum_{i=1}^{n} (y_i - \\bar{y})^2\" alt=\"\\text{MSE}(D) = \\frac{1}{n} \\sum_{i=1}^{n} (y_i - \\bar{y})^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0f\/0f2\/0f2e1f89062db4fa6f0201d924c9fb4b.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0f\/0f2\/0f2e1f89062db4fa6f0201d924c9fb4b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0f\/0f2\/0f2e1f89062db4fa6f0201d924c9fb4b.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ol start=\"3\">\n<li>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u0441 <strong>\u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e<\/strong><\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u043f\u043e\u0442\u043e\u043c\u043a\u0435 <strong>\u0437\u0430\u043d\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f &#171;\u043e\u0442\u0432\u0435\u0442&#187; \u0443\u0437\u043b\u0430<\/strong>: <\/p>\n<ul>\n<li>\n<p>\u043c\u043e\u0434\u0430 (\u043a\u043b\u0430\u0441\u0441) \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"y\" alt=\"y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/41\/415\/415290769594460e2e485922904f345d.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/41\/415\/415290769594460e2e485922904f345d.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/41\/415\/415290769594460e2e485922904f345d.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0434\u043b\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u044b \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438:<\/p>\n<ul>\n<li>\n<p>\u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442\u0430 \u043c\u0430\u043a\u0441. \u0433\u043b\u0443\u0431\u0438\u043d\u0430<\/p>\n<\/li>\n<li>\n<p>\u043c\u0430\u043b\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (min_samples_split)<\/p>\n<\/li>\n<li>\n<p>impurity = 0<\/p>\n<\/li>\n<\/ul>\n<p>\u0412\u0430\u0436\u043d\u043e: \u0434\u0435\u0440\u0435\u0432\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f <strong>\u0436\u0430\u0434\u043d\u043e<\/strong>, \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435, \u043d\u0435 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u043f\u0442\u0438\u043c\u0443\u043c\u0430.<\/p>\n<p><strong>\u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430<\/strong> \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a: \u0431\u0435\u0440\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u0437\u043b\u0430 \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043e\u043b-\u0432\u043e \u0432\u0441\u0435\u0445 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439.<\/p>\n<hr\/>\n<p>\u0412\u043e\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0432\u0430\u0436\u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0443\u0437\u043b\u0430?<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0448\u0430\u0433\u0435 \u043d\u0435 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u0430?<\/p>\n<\/li>\n<li>\n<p>\u041a\u0430\u043a \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e\u0440\u043e\u0433\u0438?<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0427\u0438\u0442\u0430\u0435\u043c <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/reshayushchiye-derevya\" rel=\"noopener noreferrer nofollow\">\u0445\u0435\u043d\u0434\u0431\u0443\u043a<\/a> \u0438\u043b\u0438 <a href=\"https:\/\/mlu-explain.github.io\/decision-tree\/\" rel=\"noopener noreferrer nofollow\">\u0431\u043e\u043b\u0435\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e<\/a><\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0441 sklearn. <\/summary>\n<div class=\"spoiler__content\">\n<p>tldr:<\/p>\n<ul>\n<li>\n<p>\u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432\u044b\u0431\u0438\u0432\u0430\u0435\u043c \u0442\u0430\u043a\u043e\u0435 \u0436\u0435<\/p>\n<\/li>\n<li>\n<p>\u0410 \u0432\u043e\u0442, \u0442\u043e \u0447\u0442\u043e \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0442\u0430\u043a \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\"> import numpy as np import pandas as pd from sklearn.datasets import load_breast_cancer from sklearn.tree import DecisionTreeClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score import matplotlib.pyplot as plt  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 data = load_breast_cancer() X, y = data.data, data.target feature_names = data.feature_names X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)  # \u0421\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439 class Node:     def __init__(self, gini, samples, value, feature_index=None, threshold=None, left=None, right=None):         self.gini = gini         self.samples = samples         self.value = value         self.feature_index = feature_index         self.threshold = threshold         self.left = left         self.right = right  class MyDecisionTreeClassifier:     def __init__(self, max_depth=3, min_samples_split=2):         self.max_depth = max_depth         self.min_samples_split = min_samples_split         self.feature_importances_ = None         self.tree_ = None      def fit(self, X, y):         self.n_classes_ = len(set(y))         self.n_features_ = X.shape[1]         self.feature_importances_ = np.zeros(self.n_features_)         self.tree_ = self._grow_tree(X, y)          def _gini(self, y):         m = len(y)         return 1.0 - sum((np.sum(y == c) \/ m) ** 2 for c in np.unique(y))      def _best_split(self, X, y):         m, n = X.shape         if m &lt;= 1:             return None, None          best_gini = 1.0         best_idx, best_thr = None, None         parent_gini = self._gini(y)          for idx in range(n):             thresholds, classes = zip(*sorted(zip(X[:, idx], y)))             num_left = [0] * self.n_classes_             num_right = np.bincount(classes, minlength=self.n_classes_)             for i in range(1, m):                 c = classes[i - 1]                 num_left[c] += 1                 num_right[c] -= 1                 gini_left = 1.0 - sum((num_left[x] \/ i) ** 2 for x in range(self.n_classes_))                 gini_right = 1.0 - sum((num_right[x] \/ (m - i)) ** 2 for x in range(self.n_classes_))                 gini = (i * gini_left + (m - i) * gini_right) \/ m                  if thresholds[i] == thresholds[i - 1]:                     continue                  if gini &lt; best_gini:                     best_gini = gini                     best_idx = idx                     best_thr = (thresholds[i] + thresholds[i - 1]) \/ 2                     impurity_reduction = parent_gini - gini                     self.feature_importances_[idx] += impurity_reduction          return best_idx, best_thr      def _grow_tree(self, X, y, depth=0):         num_samples_per_class = [np.sum(y == i) for i in range(self.n_classes_)]         predicted_class = np.argmax(num_samples_per_class)         node = Node(             gini=self._gini(y),             samples=len(y),             value=num_samples_per_class         )          if depth &lt; self.max_depth and len(y) &gt;= self.min_samples_split and node.gini &gt; 0:             idx, thr = self._best_split(X, y)             if idx is not None:                 indices_left = X[:, idx] &lt;= thr                 X_left, y_left = X[indices_left], y[indices_left]                 X_right, y_right = X[~indices_left], y[~indices_left]                 node.feature_index = idx                 node.threshold = thr                 node.left = self._grow_tree(X_left, y_left, depth + 1)                 node.right = self._grow_tree(X_right, y_right, depth + 1)         return node      def _predict(self, inputs):         node = self.tree_         while node.left:             if inputs[node.feature_index] &lt;= node.threshold:                 node = node.left             else:                 node = node.right         return np.argmax(node.value)      def predict(self, X):         return np.array([self._predict(inputs) for inputs in X])  # \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 my_tree = MyDecisionTreeClassifier(max_depth=3) my_tree.fit(X_train, y_train) y_pred_my = my_tree.predict(X_test)  sk_tree = DecisionTreeClassifier(max_depth=3, random_state=42) sk_tree.fit(X_train, y_train) y_pred_sk = sk_tree.predict(X_test)  # \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 acc_my = accuracy_score(y_test, y_pred_my) acc_sk = accuracy_score(y_test, y_pred_sk) print(f\"{acc_my=} {acc_sk=}\") # acc_my=0.9590643274853801 acc_sk=0.9649122807017544   importances_df = pd.DataFrame({     \"Feature\": feature_names,     \"MyTree\": my_tree.feature_importances_ \/ np.sum(my_tree.feature_importances_),     \"Sklearn\": sk_tree.feature_importances_ }).sort_values(by=\"MyTree\", ascending=False)  importances_df  # FeatureMyTreeSklearn # 0mean radius0.6370330.000000 # 7mean concave points0.2603520.809978 # 2mean perimeter0.0319540.000000 # 1mean texture0.0302740.025169 # 6mean concavity0.0207490.000000 # 20worst radius0.0099490.043482 # 21worst texture0.0028680.066145 # 23worst area0.0019240.040310 # 22worst perimeter0.0018330.000000 # 3mean area0.0016940.000000 # 10radius error0.0013710.000000  <\/code><\/pre>\n<\/div>\n<\/details>\n<h3>16. \u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u044d\u043d\u0442\u0440\u043e\u043f\u0438\u0438, \u043d\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0414\u0436\u0438\u043d\u0438.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043c\u043e\u0442\u0440\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043f\u0443\u043d\u043a\u0442. \u0421\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 (\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438) \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0432\u0441\u0435\u0445 \u043e\u0431\u044c\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u0440\u043e\u0432\u043d\u0443, \u0430 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0432\u0441\u0435 \u0431\u044a\u0435\u043a\u0442\u044b \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/3k\/qv\/2x\/3kqv2xnptvtlbesz1fpm7rcvlgm.png\" alt=\"\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438\" title=\"\u0413\u0440\u0430\u0444\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/3k\/qv\/2x\/3kqv2xnptvtlbesz1fpm7rcvlgm.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/3k\/qv\/2x\/3kqv2xnptvtlbesz1fpm7rcvlgm.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0413\u0440\u0430\u0444\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 <\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt  # \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441 1) p = np.linspace(0, 1, 500)  # \u042d\u043d\u0442\u0440\u043e\u043f\u0438\u044f (Shannon entropy) entropy = -p * np.log2(p + 1e-9) - (1 - p) * np.log2(1 - p + 1e-9)  # \u0414\u0436\u0438\u043d\u0438 gini = 2 * p * (1 - p)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(8, 5)) plt.plot(p, entropy, label='Entropy', linewidth=2) plt.plot(p, gini, label='Gini Impurity', linewidth=2) plt.xlabel(\"p (\u0434\u043e\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430)\") plt.ylabel(\"Impurity\") plt.title(\"\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0435\u0432 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438\") plt.legend() plt.grid(True) plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/3k\/qv\/2x\/3kqv2xnptvtlbesz1fpm7rcvlgm.png\" alt=\"\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438\" title=\"\u0413\u0440\u0430\u0444\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/3k\/qv\/2x\/3kqv2xnptvtlbesz1fpm7rcvlgm.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/3k\/qv\/2x\/3kqv2xnptvtlbesz1fpm7rcvlgm.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0413\u0440\u0430\u0444\u0438\u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/figcaption><\/div>\n<\/figure>\n<\/div>\n<\/details>\n<h3>17. \u0410\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0432\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b. \u0411\u0443\u0442\u0441\u0442\u0440\u0430\u043f (bootstrap). \u0411\u044d\u0433\u0433\u0438\u043d\u0433 (bagging). \u0421\u0442\u0435\u043a\u0438\u043d\u0433 (stacking)<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>\u0410\u043d\u0441\u0430\u043c\u0431\u043b\u0438<\/strong> \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043e\u0434\u043d\u0443, \u0431\u043e\u043b\u0435\u0435 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u0443\u044e.<\/p>\n<p><strong>\u0411\u0443\u0442\u0441\u0442\u0440\u0430\u043f<\/strong>: \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0432\u044b\u0431\u043e\u0440\u043e\u043a \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u043c\u043f\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p><strong>\u0411\u044d\u0433\u0433\u0438\u043d\u0433 (bagging, bootstrap aggregation)<\/strong> &#8212; \u043e\u0431\u0443\u0447\u0430\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u0431\u0443\u0442\u0441\u0442\u0440\u0430\u043f-\u0432\u044b\u0431\u043e\u0440\u043a\u0430\u0445 \u0438 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u0443\u0435\u043c \u0438\u0445 \u043e\u0442\u0432\u0435\u0442\u044b (\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 \u0438\u043b\u0438 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043d\u0438\u0435).<\/p>\n<p>\u0422\u0435\u043e\u0440\u0438\u044f \u0432\u043e\u043a\u0440\u0443\u0433 <strong>Bias-variance trade-off<\/strong> \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u0447\u0442\u043e <strong>\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 (bias)<\/strong> \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f, a <strong>\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f (variance)<\/strong> \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u0441\u044f \u0432 <strong>k<\/strong> \u0440\u0430\u0437 (\u0415\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432). <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/ansambli-v-mashinnom-obuchenii\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0432\u043e\u0434 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/a>. <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0431\u0435\u0440\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u0435, \u0433\u043b\u0443\u0431\u043e\u043a\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 (\u0430 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0435\u0433\u0433\u0438\u043d\u0433\u0430!)<\/p>\n<p><strong>\u0421\u0442\u0435\u043a\u0438\u043d\u0433 (stacking)<\/strong>: 1. \u0423\u0447\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e (\u0440\u0430\u0437\u043d\u043e\u0439 \u043f\u0440\u0438\u0440\u043e\u0434\u044b) \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0444\u043e\u043b\u0434\u0430\u0445, \u0438 \u043f\u043e\u0442\u043e\u043c \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u043e\u043b\u0434\u0435 \u0443\u0447\u0438\u043c <strong>\u043c\u0435\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c<\/strong> .<\/p>\n<hr\/>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043b\u0435\u0441 (Random Forest) = <strong>\u0431\u044d\u0433\u0433\u0438\u043d\u0433<\/strong> + <strong>\u043c\u0435\u0442\u043e\u0434 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432<\/strong>(=\u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0437\u043b\u0435 \u0434\u0435\u0440\u0435\u0432\u0430 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0435 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432):<\/p>\n<p><strong>\u0418\u0437 \u043a\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c?<\/strong><\/p>\n<ul>\n<li>\n<p>\u041c\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0441\u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (=\u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u043e\u0442 \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f).<\/p>\n<\/li>\n<li>\n<p>\u041c\u0430\u043b\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/>  \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u043b\u0430\u0431\u044b\u0435 (=\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f).<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f \u2014 \u0431\u0440\u0430\u0442\u044c <strong>\u043a\u043e\u0440\u0435\u043d\u044c \u0438\u0437 \u0447\u0438\u0441\u043b\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432<\/strong> \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 <strong>\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432<\/strong> \u0434\u043b\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p><a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/ansambli-v-mashinnom-obuchenii\" rel=\"noopener noreferrer nofollow\">\u0425\u0435\u043d\u0434\u0431\u0443\u043a<\/a> + <a href=\"https:\/\/mlu-explain.github.io\/random-forest\/\" rel=\"noopener noreferrer nofollow\">\u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/a><\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0451\u0432\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"> # \u0418\u043c\u043f\u043e\u0440\u0442 \u0432\u0441\u0435\u0445 \u043d\u0443\u0436\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a from sklearn.ensemble import (     BaggingClassifier,     StackingClassifier,     RandomForestClassifier,     GradientBoostingClassifier ) from sklearn.tree import DecisionTreeClassifier from sklearn.linear_model import LogisticRegression from sklearn.svm import SVC from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score import matplotlib.pyplot as plt  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 X, y = load_breast_cancer(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)  # 1. \u041e\u0431\u044b\u0447\u043d\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e tree = DecisionTreeClassifier(random_state=42) tree.fit(X_train, y_train) y_pred_tree = tree.predict(X_test) acc_tree = accuracy_score(y_test, y_pred_tree)  # 2. \u0411\u044d\u0433\u0433\u0438\u043d\u0433 bag = BaggingClassifier(DecisionTreeClassifier(), n_estimators=100, random_state=42) bag.fit(X_train, y_train) y_pred_bag = bag.predict(X_test) acc_bag = accuracy_score(y_test, y_pred_bag)  # 3. \u0421\u0442\u0435\u043a\u0438\u043d\u0433: \u0434\u0435\u0440\u0435\u0432\u043e + SVM \u2192 \u043b\u043e\u0433\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f stack = StackingClassifier(     estimators=[         (\"dt\", DecisionTreeClassifier()),         (\"svm\", SVC(probability=True))     ],     final_estimator=LogisticRegression(),     cv=5 ) stack.fit(X_train, y_train) y_pred_stack = stack.predict(X_test) acc_stack = accuracy_score(y_test, y_pred_stack)  # 4. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043b\u0435\u0441 rf = RandomForestClassifier(n_estimators=100, random_state=42) rf.fit(X_train, y_train) y_pred_rf = rf.predict(X_test) acc_rf = accuracy_score(y_test, y_pred_rf)  # 5. \u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 boost = GradientBoostingClassifier(n_estimators=100, learning_rate=0.1, max_depth=3, random_state=42) boost.fit(X_train, y_train) y_pred_boost = boost.predict(X_test) acc_boost = accuracy_score(y_test, y_pred_boost)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 models = ['Decision Tree', 'Bagging', 'Stacking', 'Random Forest', 'Boosting'] accuracies = [acc_tree, acc_bag, acc_stack, acc_rf, acc_boost]  plt.figure(figsize=(10, 5)) plt.bar(models, accuracies, color=['skyblue', 'lightgreen', 'salmon', 'gold', 'orchid']) plt.ylim(0.9, 1.0) plt.ylabel(\"Accuracy\") plt.title(\"\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0432\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 Breast Cancer Dataset\") plt.grid(axis='y') plt.tight_layout() plt.show()  # \u0412\u044b\u0432\u043e\u0434 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 acc_tree, acc_bag, acc_stack, acc_rf, acc_boost # (0.9415204678362573, #  0.9590643274853801, #  0.9649122807017544, #  0.9707602339181286, #  0.9590643274853801)  <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/79\/4-\/hf\/794-hfxhbhlwdxda8lxedhcq-nc.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/79\/4-\/hf\/794-hfxhbhlwdxda8lxedhcq-nc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/79\/4-\/hf\/794-hfxhbhlwdxda8lxedhcq-nc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h3>18. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043b\u0435\u0441 (Random Forest), \u043c\u0435\u0442\u043e\u0434 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p> \u0421\u043c\u043e\u0442\u0440\u0438 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0431\u0438\u043b\u0435\u0442!  <\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u043e\u0438\u0441\u043a \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u0430 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432. \u041d\u0435\u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439. <\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u043e\u0432 <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0434\u0435\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0441\u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435 \u0440\u0430\u0441\u0442\u0435\u0442<br \/> .<\/p>\n<pre><code class=\"python\"> # \u0411\u0443\u0434\u0435\u043c \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e (variance) \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u0440\u0430\u0437\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 # \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f max_features  tree_variances = [] mean_accuracies = [] max_features_range = range(1, n_features + 1)  for mf in max_features_range:     rf = RandomForestClassifier(         n_estimators=100, max_features=mf, random_state=42, oob_score=False     )     rf.fit(X_train, y_train)          # \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432     all_preds = np.array([tree.predict(X_test) for tree in rf.estimators_])  # shape (n_estimators, n_samples)          # \u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 (majority vote)     majority_vote = np.round(np.mean(all_preds, axis=0)).astype(int)     acc = accuracy_score(y_test, majority_vote)     mean_accuracies.append(acc)          # \u041e\u0446\u0435\u043d\u043a\u0430 \"\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438\" (\u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f: \u0441\u0440\u0435\u0434\u043d\u044f\u044f \u0434\u043e\u043b\u044f \u043d\u0435\u0441\u043e\u0433\u043b\u0430\u0441\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c\u0438)     disagreement = np.mean(np.var(all_preds, axis=0))     tree_variances.append(disagreement)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f fig, ax1 = plt.subplots(figsize=(10, 5))  color = 'tab:blue' ax1.set_xlabel(\"max_features\") ax1.set_ylabel(\"Disagreement (Variance across trees)\", color=color) ax1.plot(max_features_range, tree_variances, color=color, label=\"Variance across trees\") ax1.tick_params(axis='y', labelcolor=color) ax1.grid(True)  ax2 = ax1.twinx() color = 'tab:green' ax2.set_ylabel(\"Accuracy\", color=color) ax2.plot(max_features_range, mean_accuracies, color=color, linestyle='--', label=\"Accuracy\") ax2.tick_params(axis='y', labelcolor=color)  plt.title(\"Variance across trees vs Accuracy (Random Forest)\") fig.tight_layout() plt.show()  <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/k2\/bg\/fm\/k2bgfmbr4wfikenrkumwgppb1w8.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/k2\/bg\/fm\/k2bgfmbr4wfikenrkumwgppb1w8.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/k2\/bg\/fm\/k2bgfmbr4wfikenrkumwgppb1w8.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h3>19. \u0411\u0443\u0441\u0442\u0438\u043d\u0433 \u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 (Gradient Boosting). \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u0430\u044f \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>\u0411\u0443\u0441\u0442\u0438\u043d\u0433<\/strong> \u2014 \u044d\u0442\u043e \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0435\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f <strong>\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e<\/strong>, \u043a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f <strong>\u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445<\/strong>.<\/p>\n<ul>\n<li>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0431\u044d\u0433\u0433\u0438\u043d\u0433\u0430 (\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438), \u0437\u0434\u0435\u0441\u044c \u0438\u0434\u0435\u0442 <strong>\u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0438\u0437 &#171;\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043e\u0440\u043e\u0432&#187;<\/strong>.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u2014 <strong>\u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u0430\u044f \u0441\u0443\u043c\u043c\u0430<\/strong> \u0432\u0441\u0435\u0445 \u0441\u043b\u0430\u0431\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 (Gradient Boosting)<\/strong> \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u0435\u0442 <strong>\u0430\u043d\u0442\u0438\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c<\/strong> (\u043d\u0430\u043f\u0440. MSE, \u043b\u043e\u0433\u043b\u043e\u0441\u0441) \u043f\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u044f.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<h4>\ud83d\udcd8 \u041e\u0431\u0449\u0430\u044f \u0438\u0434\u0435\u044f \u0431\u0443\u0441\u0442\u0438\u043d\u0433\u0430<\/h4>\n<blockquote>\n<p>\u041e\u0447\u0435\u043d\u044c \u043a\u0440\u0443\u0442\u043e, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/gradientnyj-busting\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<\/blockquote>\n<p>\u0418\u043c\u0435\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u043f\u043e\u0442\u0435\u0440\u044c <img decoding=\"async\" class=\"formula inline\" source=\"L(y, F(x))\" alt=\"L(y, F(x))\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a091ba93fd557ec5539ded474deafae9.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a091ba93fd557ec5539ded474deafae9.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a091ba93fd557ec5539ded474deafae9.svg 781w\" loading=\"lazy\" decode=\"async\"\/>.<br \/> \u0425\u043e\u0442\u0438\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0432 \u0432\u0438\u0434\u0435:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"F(x) = \\sum_{m=1}^{M} \\gamma_m h_m(x)\" alt=\"F(x) = \\sum_{m=1}^{M} \\gamma_m h_m(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f9\/f9a\/f9a7f568c6ce52b9c6be57a2512f6050.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f9\/f9a\/f9a7f568c6ce52b9c6be57a2512f6050.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f9\/f9a\/f9a7f568c6ce52b9c6be57a2512f6050.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u043d\u043e\u0432\u044b\u0439 \u0441\u043b\u0430\u0431\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c <img decoding=\"async\" class=\"formula inline\" source=\"h_m(x)\" alt=\"h_m(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/23\/23c\/23cee294c31cecb7985d655f5625a675.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/23\/23c\/23cee294c31cecb7985d655f5625a675.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/23\/23c\/23cee294c31cecb7985d655f5625a675.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 <strong>\u043e\u0441\u0442\u0430\u0442\u043a\u0430\u0445<\/strong> \u0438\u043b\u0438 <strong>\u0430\u043d\u0442\u0438\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0435<\/strong> \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<hr\/>\n<h4>\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 (Gradient Boosting)<\/h4>\n<p>\u041d\u0430 \u0448\u0430\u0433\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"m\" alt=\"m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6f\/6f8\/6f8f57715090da2632453988d9a1501b.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6f\/6f8\/6f8f57715090da2632453988d9a1501b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6f\/6f8\/6f8f57715090da2632453988d9a1501b.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0441\u0442\u0440\u043e\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c <img decoding=\"async\" class=\"formula inline\" source=\"h_m\" alt=\"h_m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/10\/104\/10448234aa48987392431d0083a29736.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/10\/104\/10448234aa48987392431d0083a29736.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/10\/104\/10448234aa48987392431d0083a29736.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u043f\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0438\u0440\u0443\u0435\u0442 <strong>\u0430\u043d\u0442\u0438\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c<\/strong> \u043f\u043e \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"r_i^{(m)} = - \\left. \\frac{\\partial L(y_i, F(x_i))}{\\partial F(x_i)} \\right|_{F = F_{m-1}}\" alt=\"r_i^{(m)} = - \\left. \\frac{\\partial L(y_i, F(x_i))}{\\partial F(x_i)} \\right|_{F = F_{m-1}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/03\/036\/036d5bc0e17fb29bd61b860da99d1f37.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/03\/036\/036d5bc0e17fb29bd61b860da99d1f37.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/03\/036\/036d5bc0e17fb29bd61b860da99d1f37.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<ul>\n<li>\n<p>\u043e\u0431\u0443\u0447\u0430\u0435\u043c <img decoding=\"async\" class=\"formula inline\" source=\"h_m\" alt=\"h_m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/10\/104\/10448234aa48987392431d0083a29736.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/10\/104\/10448234aa48987392431d0083a29736.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/10\/104\/10448234aa48987392431d0083a29736.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043d\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"(x_i, r_i^{(m)})\" alt=\"(x_i, r_i^{(m)})\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/80\/80b\/80b25689a147fbc745329b3e86815797.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/80\/80b\/80b25689a147fbc745329b3e86815797.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/80\/80b\/80b25689a147fbc745329b3e86815797.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0448\u0430\u0433 <img decoding=\"async\" class=\"formula inline\" source=\"\\gamma_m\" alt=\"\\gamma_m\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/45\/450\/45045ddc39f748208d12990482e55a21.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/45\/450\/45045ddc39f748208d12990482e55a21.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/45\/450\/45045ddc39f748208d12990482e55a21.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p>\u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u043c:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"F_m(x) = F_{m-1}(x) + \\gamma_m h_m(x)\" alt=\"F_m(x) = F_{m-1}(x) + \\gamma_m h_m(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1c\/1c3\/1c3d15f790ceae464474d2579bbc89f0.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1c\/1c3\/1c3d15f790ceae464474d2579bbc89f0.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1c\/1c3\/1c3d15f790ceae464474d2579bbc89f0.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<\/ul>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043e\u0432:<\/h4>\n<ul>\n<li>\n<p><strong>MSE (\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f):<\/strong><\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\frac{\\partial}{\\partial F(x)} \\frac{1}{2}(y - F(x))^2 = F(x) - y\\Rightarrow r_i = y_i - F(x_i)\" alt=\"\\frac{\\partial}{\\partial F(x)} \\frac{1}{2}(y - F(x))^2 = F(x) - y\\Rightarrow r_i = y_i - F(x_i)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/22\/22c\/22c0f0ac35ea0f1eced1c0744866f45f.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/22\/22c\/22c0f0ac35ea0f1eced1c0744866f45f.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/22\/22c\/22c0f0ac35ea0f1eced1c0744866f45f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0441\u0442\u0430\u0442\u043a\u0438! \u0421\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0441\u0442\u0438\u043d\u0433\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>Log-loss (\u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f):<\/strong><\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"L(y, F) = \\log(1 + e^{-yF}) \\Rightarrow r_i = \\frac{-y_i}{1 + e^{y_i F(x_i)}}\" alt=\"L(y, F) = \\log(1 + e^{-yF}) \\Rightarrow r_i = \\frac{-y_i}{1 + e^{y_i F(x_i)}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/57\/57c\/57c78975c2c103630a5453ba3bbb4cb5.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/57\/57c\/57c78975c2c103630a5453ba3bbb4cb5.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/57\/57c\/57c78975c2c103630a5453ba3bbb4cb5.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<\/ul>\n<h4>\u041f\u043e\u0447\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/h4>\n<ul>\n<li>\n<p>\u0420\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0443 <strong>\u043d\u0435 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0430 \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c<\/strong>!<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0442\u0435\u0440\u044c \u2014 \u043a\u0430\u043a <strong>\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435<\/strong> (\u0432 <img decoding=\"async\" class=\"formula inline\" source=\"n\" alt=\"n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b8\/7b8b965ad4bca0e41ab51de7b31363a1.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b8\/7b8b965ad4bca0e41ab51de7b31363a1.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b8\/7b8b965ad4bca0e41ab51de7b31363a1.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435, <img decoding=\"async\" class=\"formula inline\" source=\"n\" alt=\"n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b8\/7b8b965ad4bca0e41ab51de7b31363a1.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b8\/7b8b965ad4bca0e41ab51de7b31363a1.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7b\/7b8\/7b8b965ad4bca0e41ab51de7b31363a1.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430). \u041a\u0430\u0436\u0434\u044b\u0439 \u0448\u0430\u0433 &#8212; \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0430\u043d\u0442\u0438\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u043a \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\Rightarrow\" alt=\"\\Rightarrow\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/05\/055\/055889aaee38b7c53f994c5e42a40994.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043b\u043e\u0441\u0441\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f <strong>MSE<\/strong> \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438 \u0442\u043e\u0436\u0435! (\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u0438 \u0430\u043d\u0442\u0438\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u0440\u0430\u0432\u043d\u044b)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/fj\/ib\/hk\/fjibhk79wxnc2nscvcyjnvrdcjo.png\" alt=\"\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438\" title=\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u0442\u0438\u043d\u044b\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/fj\/ib\/hk\/fjibhk79wxnc2nscvcyjnvrdcjo.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/fj\/ib\/hk\/fjibhk79wxnc2nscvcyjnvrdcjo.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0438 \u0438\u0441\u0442\u0438\u043d\u044b<\/figcaption><\/div>\n<\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/2x\/aw\/-f\/2xaw-f0ys-asy6cz4ifbolrvc3i.png\" alt=\"\u041a\u0440\u0438\u0442\u0435\u0440\u0438\u0438\" title=\"\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/2x\/aw\/-f\/2xaw-f0ys-asy6cz4ifbolrvc3i.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/2x\/aw\/-f\/2xaw-f0ys-asy6cz4ifbolrvc3i.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<div><figcaption>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c<\/figcaption><\/div>\n<\/figure>\n<blockquote>\n<p>\u041e\u0431\u0440\u0430\u0449\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0442\u043e\u0442 \u0438 \u0442\u043e\u0442 \u043e\u0431\u0430 \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043f\u043e \u043d\u0430\u0438\u0441\u043a\u043e\u0440\u0435\u0439\u0448\u0435\u043c\u0443 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e.<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u0410 \u043a\u0430\u043a \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438? \u0411\u0435\u0440\u0443\u0442\u0441\u044f &#171;\u043f\u0440\u043e\u0441\u0442\u044b\u0435&#187; \u043c\u043e\u0434\u0435\u043b\u0438 (\u0441 \u043d\u0438\u0437\u043a\u043e\u0439 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0435\u0439), \u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435<\/p>\n<\/blockquote>\n<hr\/>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0435 \u0432 \u043f\u0440\u043e\u0434\u0435. <strong>XGBoost<\/strong>, <strong>LightGBM<\/strong> \u0438 <strong>CatBoost<\/strong>.<br \/> \u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0432\u0430\u0436\u043d\u044b\u0435 \u0444\u0438\u0448\u043a\u0438 \u0438 \u043e\u0442\u043b\u0438\u0447\u0438\u044f.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0432\u043e\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433. \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 GradientBoostingRegressor \u0438 RandomForestRegressor.<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043a\u043e\u0434, \u0441 \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043a\u0430\u043a \u0438\u0437 sklearn.<\/p>\n<\/li>\n<li>\n<p>\u0414\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0438\u0433\u0440\u0430\u043b\u043e \u0431\u0443\u0441\u0442\u0438\u043d\u0433\u0443.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\"># \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434: \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0431\u0443\u0441\u0442\u0438\u043d\u0433\u0430 \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430  import numpy as np import matplotlib.pyplot as plt from sklearn.tree import DecisionTreeRegressor from sklearn.metrics import mean_squared_error from sklearn.model_selection import train_test_split from sklearn.ensemble import GradientBoostingRegressor, RandomForestRegressor  # 1. \u0421\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 np.random.seed(42) X = np.linspace(0, 10, 500).reshape(-1, 1) y_true = np.sin(X).ravel() y = y_true + np.random.normal(0, 0.3, size=X.shape[0]) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)  # 2. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 class MyGradientBoostingRegressor:     def __init__(self, n_estimators=100, learning_rate=0.1, max_depth=3):         self.n_estimators = n_estimators         self.learning_rate = learning_rate         self.max_depth = max_depth         self.models = []         self.gammas = []      def fit(self, X, y):         self.models = []         self.gammas = []         self.init_val = np.mean(y)         F = np.full_like(y, fill_value=self.init_val, dtype=np.float64)          for m in range(self.n_estimators):             residuals = y - F             tree = DecisionTreeRegressor(max_depth=self.max_depth)             tree.fit(X, residuals)             prediction = tree.predict(X)             gamma = 1.0             F += self.learning_rate * gamma * prediction             self.models.append(tree)             self.gammas.append(gamma)      def predict(self, X):         F = np.full(X.shape[0], self.init_val)         for gamma, tree in zip(self.gammas, self.models):             F += self.learning_rate * gamma * tree.predict(X)         return F  # 3. \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 # \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0431\u0443\u0441\u0442\u0438\u043d\u0433 my_gb = MyGradientBoostingRegressor(n_estimators=100, learning_rate=0.1, max_depth=3) my_gb.fit(X_train, y_train) y_pred_my = my_gb.predict(X_test) mse_my = mean_squared_error(y_test, y_pred_my)  # sklearn GB (\u043e\u0431\u044b\u0447\u043d\u044b\u0439) sklearn_gb = GradientBoostingRegressor(n_estimators=100, learning_rate=0.1, max_depth=3, random_state=42) sklearn_gb.fit(X_train, y_train) y_pred_sklearn = sklearn_gb.predict(X_test) mse_sklearn = mean_squared_error(y_test, y_pred_sklearn)  # sklearn GB (\u043d\u0438\u0437\u043a\u0438\u0439 learning_rate) sklearn_gb_slow = GradientBoostingRegressor(n_estimators=300, learning_rate=0.03, max_depth=3, random_state=42) sklearn_gb_slow.fit(X_train, y_train) y_pred_slow = sklearn_gb_slow.predict(X_test) mse_slow = mean_squared_error(y_test, y_pred_slow)  # \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043b\u0435\u0441 rf = RandomForestRegressor(n_estimators=100, max_depth=6, random_state=42) rf.fit(X_train, y_train) y_pred_rf = rf.predict(X_test) mse_rf = mean_squared_error(y_test, y_pred_rf)  # 4. \u0421\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0434\u043b\u044f \u0433\u043b\u0430\u0434\u043a\u0438\u0445 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 sorted_idx = np.argsort(X_test.ravel()) X_plot = X_test[sorted_idx] y_true_plot = np.sin(X_plot).ravel() y_test_plot = y_test[sorted_idx] y_pred_my_plot = y_pred_my[sorted_idx] y_pred_sklearn_plot = y_pred_sklearn[sorted_idx] y_pred_slow_plot = y_pred_slow[sorted_idx] y_pred_rf_plot = y_pred_rf[sorted_idx]  # 5. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(12, 6)) plt.plot(X_plot, y_true_plot, label=\"True function sin(x)\", color='green', linestyle='--') plt.plot(X_plot, y_pred_my_plot, label=f\"My GB (MSE={mse_my:.4f})\", color='red') plt.plot(X_plot, y_pred_sklearn_plot, label=f\"sklearn GB (0.1) (MSE={mse_sklearn:.4f})\", color='blue') plt.plot(X_plot, y_pred_slow_plot, label=f\"sklearn GB (0.03) (MSE={mse_slow:.4f})\", color='orange') plt.plot(X_plot, y_pred_rf_plot, label=f\"Random Forest (MSE={mse_rf:.4f})\", color='purple') plt.scatter(X_plot, y_test_plot, label=\"Test data\", s=10, alpha=0.3) plt.legend() plt.title(\"\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0431\u0443\u0441\u0442\u0438\u043d\u0433\u0430 (\u0440\u0443\u0447\u043d\u043e\u0439 \u0438 sklearn) \u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430\") plt.grid(True) plt.tight_layout() plt.show()  <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/b_\/-i\/1p\/b_-i1py5fs9mmcmbhyef-wifkue.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/b_\/-i\/1p\/b_-i1py5fs9mmcmbhyef-wifkue.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/b_\/-i\/1p\/b_-i1py5fs9mmcmbhyef-wifkue.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h3>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h3>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/lf\/cu\/ci\/lfcucinx9two8eljpeoqup5e3vy.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/lf\/cu\/ci\/lfcucinx9two8eljpeoqup5e3vy.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/lf\/cu\/ci\/lfcucinx9two8eljpeoqup5e3vy.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0412\u0434\u0443\u043c\u0447\u0438\u0432\u043e \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432 \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u0445, \u043d\u043e \u043a\u043e\u0440\u043e\u0442\u043a\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0443\u0442\u044c.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u0430\u043f &#8212; \u0443\u043c\u0435\u0442\u044c, \u043f\u043e\u043d\u0438\u043c\u0430\u044f \u0431\u0430\u0437\u0443, \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u043a\u0430\u0432\u0435\u0440\u0437\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0438\u0445 \u0434\u043b\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0438!<\/p>\n<h3>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h3>\n<ul>\n<li>\n<p>\u0421\u0430\u043c <a href=\"https:\/\/github.com\/girafe-ai\/ml-course\/blob\/23f_basic\/exam_program.md\" rel=\"noopener noreferrer nofollow\">\u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432<\/a> \u0432\u0437\u044f\u043b \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u044d\u043a\u0437\u0430\u043c\u0435\u043d\u043e\u0432<br \/> <a href=\"https:\/\/github.com\/girafe-ai\" rel=\"noopener noreferrer nofollow\">girafe.ai<\/a> ~ <a href=\"https:\/\/www.youtube.com\/@DeepLearningSchool\" rel=\"noopener noreferrer nofollow\">Deep Learning School<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/education.yandex.ru\/handbook\/ml\" rel=\"noopener noreferrer nofollow\">\u0425\u0435\u043d\u0434\u0431\u0443\u043a\u0438 \u042f\u043d\u0434\u0435\u043a\u0441<\/a> &#8212; \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435. \u041c\u0435\u0441\u0442\u0430\u043c\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/proproprogs.ru\/ml\/ml-chto-takoe-mashinnoe-obuchenie-obuchayushchaya-vyborka-i-priznakovoe-prostranstvo\" rel=\"noopener noreferrer nofollow\">SelfEdu<\/a> &#8212; \u043c\u0435\u0433\u0430\u043a\u0440\u0443\u0442\u043e\u0439. \u0422\u0430\u043a\u0436\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u044f\u043b\u0441\u044f (\u0438 \u044f \u0442\u043e\u0436\u0435!) <a href=\"https:\/\/www.youtube.com\/channel\/UCdfMlHaF7spha_q8iM_LZHg\" rel=\"noopener noreferrer nofollow\">\u0421\u0435\u0440\u0433\u0435\u0435\u043c \u041d\u0438\u043a\u043e\u043b\u0435\u043d\u043a\u043e<\/a>.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/mlu-explain.github.io\/\" rel=\"noopener noreferrer nofollow\">MLU-EXPLAIN<\/a> &#8212; \u043d\u0430 \u0434\u043e\u0441\u0443\u0433\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043b\u0438\u043f\u043d\u0443\u0442\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438 \u043b\u0435\u0433\u043a\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 <a href=\"https:\/\/www.deeplearningbook.org\/\" rel=\"noopener noreferrer nofollow\">\u0443\u0447\u0435\u0431\u043d\u0438\u043a<\/a>.<\/p>\n<\/li>\n<li>\n<p>\u0417\u0430\u0431\u044b\u043b \u043e\u0434\u043d\u043e \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0432\u0430\u0436\u043d\u044b\u0445 &#8212; <a href=\"https:\/\/chatgpt.com\/\" rel=\"noopener noreferrer nofollow\">LLM<\/a> \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043d\u0430\u0431\u0440\u043e\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0433\u0438\u043f\u043e\u0442\u0435\u0437\u0443<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p><em>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u2014 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0432\u0432\u043e\u0434\u0430 \u0432 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435, \u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u0440\u0430\u0437\u0431\u043e\u0440\u043e\u043c \u0432\u0430\u0436\u043d\u0435\u0439\u0448\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440. \u041f\u043e\u043a\u0430 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u0438 \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438 \u043d\u0430\u0445\u043e\u0434\u043a\u0430\u043c\u0438!<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/921190\/\"> https:\/\/habr.com\/ru\/articles\/921190\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0423 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043c\u043e\u043c\u0435\u043d\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e <strong>\u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u0432\u0435\u0436\u0438\u0442\u044c<\/strong> \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0439 \u043f\u043b\u0430\u0441\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 ML. \u041f\u0440\u0438\u0447\u0438\u043d\u044b \u0440\u0430\u0437\u043d\u044b\u0435 &#8212; \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044e, \u043d\u0430\u0447\u0430\u043b\u043e \u043f\u0440\u0435\u043f\u043e\u0434\u0430\u0432\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u0435.<\/p>\n<p>\u0412\u0440\u0435\u043c\u0435\u043d\u0438 \u043c\u0430\u043b\u043e, \u043e\u0431\u044a\u0435\u043c\u0430 \u043c\u043d\u043e\u0433\u043e, \u0446\u0435\u043b\u0438 \u0430\u043c\u0431\u0438\u0446\u0438\u043e\u0437\u043d\u044b\u0435 &#8212; \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f <strong>\u043b\u0435\u0433\u043a\u043e<\/strong> \u0438 <strong>\u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c<\/strong>, \u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043d\u0435 \u043b\u0438\u0448\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b!<\/p>\n<p>\ud83d\udcbb \u041e\u0431\u0440\u0430\u0449\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0441\u0430\u043c\u044b\u0439 \u0434\u0435\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c &#8212; \u044d\u0442\u043e \u0441\u0432\u043e\u0438\u043c\u0438 <strong>\u0440\u0443\u043a\u0430\u043c\u0438 \u043f\u043e\u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443<\/strong>! \u042d\u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0432\u0430\u0436\u043d\u043e\u0435, \u043e\u043d\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 \u0441 \u043a\u043e\u0434\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0430\u043c\u0438 \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u043a\u0443 \u0438 \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0441\u0432\u043e\u044e!<\/p>\n<p><em>\u0411\u0443\u0434\u0435\u0442 \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432\u0430\u0448\u0438 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0445 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c!<\/em><\/p>\n<p>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c. \u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u044b\u0442\u0430\u0439\u0442\u0435 \u0441\u0435\u0431\u044f \u0432 <a href=\"https:\/\/habr.com\/ru\/articles\/918438\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 [1] \u0447\u0430\u0441\u0442\u0438!<\/a><\/p>\n<figure class=\"\"><\/figure>\n<p>\u042f \u0441\u0447\u0438\u0442\u0430\u044e \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u043b\u043d\u044b\u0439 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044b &#8212; \u044d\u0442\u043e \u0432\u0437\u044f\u0442\u044c <a href=\"https:\/\/github.com\/girafe-ai\/ml-course\/blob\/23f_basic\/exam_program.md\" rel=\"noopener noreferrer nofollow\">\u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u044d\u043a\u0437\u0430\u043c\u0435\u043d<\/a> \u0438 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c \u043d\u0430 \u0432\u0441\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b &#8212; \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e. \u0410 \u0447\u0442\u043e \u0431\u044b \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043b\u043e\u0441\u044c \u043b\u0443\u0447\u0448\u0435 &#8212; \u0440\u0435\u0448\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u043a\u0443. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<blockquote>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u0441\u0430\u043c\u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430! \u0421\u0442\u0430\u043b\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435-\u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0442\u044c?<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u043f\u043e\u0433\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0443 \u0432\u0430\u0436\u043d\u044b\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b. \u0414\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u0441\u0432\u043e\u0438\u043c\u0438!<\/p>\n<\/blockquote>\n<hr\/>\n<h3>11. \u0410\u043d\u0430\u043b\u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0421\u0432\u044f\u0437\u044c \u0441 SVD. \u0422\u0435\u043e\u0440\u0435\u043c\u0430 \u042d\u043a\u043a\u0430\u0440\u0442\u0430-\u042f\u043d\u0433\u0430. \u041a\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c PCA \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p><strong>PCA (Principal Component Analysis \u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442)<\/strong> \u2014 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043d\u0438\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u0420\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0430\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u043c\u0430\u0442\u0440\u0438\u0446\u0430\u043c\u0438 \u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u043d\u0433\u0430 (\u043a\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/rekomendacii-na-osnove-matrichnyh-razlozhenij\" rel=\"noopener noreferrer nofollow\">ALS<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u0415\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c \u043a\u0430\u043a \u0437\u0430\u0434\u0430\u0447\u0443 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 MSE \u0438\u043b\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u043d\u043e \u0441 <strong>SVD<\/strong><\/p>\n<\/li>\n<li>\n<p>\u0415\u0449\u0435 \u043e\u0434\u043d\u0430 \u0438\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f &#8212; \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u043b\u0430\u0442\u0435\u043d\u0442\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u044e\u0437\u0435\u0440\u0430 \u0438 \u0442\u043e\u0432\u0430\u0440\u0430<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<ul>\n<li>\n<p>\u0418\u0449\u0435\u0442 \u0442\u0430\u043a\u0438\u0435 \u043e\u0441\u0438 (\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f), \u0432\u0434\u043e\u043b\u044c \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 <strong>\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e<\/strong><\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u043e\u0435\u0446\u0438\u0440\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0435  \u0442\u0430\u043a\u0438\u0445 \u043e\u0441\u0435\u0439 (\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442), \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f <strong>\u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438<\/strong> (\u0432 \u0441\u043c\u044b\u0441\u043b\u0435 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438) &#8212; \u043f\u043e\u0447\u0435\u043c\u0443? \u0438\u0434\u0435\u043c \u043a SVD<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<ul>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 <strong>SVD<\/strong> (Singular value decomposition \u0438\u043b\u0438 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435) &#8212; \u0440\u0430\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043d\u0430 <strong>\u0434\u0432\u0435 \u043e\u0440\u0442\u043e\u043d\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 [\u043f\u043e\u0432\u043e\u0440\u043e\u0442]<\/strong> \u0438 <strong>\u0434\u0438\u0430\u0433\u043e\u043d\u0430\u043b\u044c\u043d\u0443\u044e [\u0440\u0430\u0441\u0442\u044f\u0436\u0435\u043d\u0438\u0435]<\/strong> (\u0441 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438=\u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c\/\u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430)<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u043e\u043a\u0438 \u0443 \u0440\u0430\u0437\u0436\u0430\u0442\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0432\u0435\u043d\u043d\u043e, \u0447\u0442\u043e \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f)  \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u044b\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438!<\/p>\n<\/li>\n<\/ul>\n<figure class=\"\"><\/figure>\n<ul>\n<li>\n<p>\u0422\u0435\u043e\u0440\u0435\u043c\u0430 \u042d\u043a\u043a\u0430\u0440\u0442\u0430-\u042f\u043d\u0433\u0430 &#8212; \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442, \u0442\u0430\u043a\u0430\u044f \u0430\u043f\u0440\u043e\u043a\u0441\u0438\u043c\u0430\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u0430\u043d\u0433\u0430 \u043f\u043e \u043d\u043e\u0440\u043c\u0435 \u0424\u0440\u043e\u0431\u0435\u043d\u0438\u0443\u0441\u0430 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0430\u044f!<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430 \u043e\u0434\u043d\u043e\u043c \u0434\u044b\u0445\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e <a href=\"https:\/\/youtu.be\/mlA-XxC9Ugg?si=8a1Edzx5RE6bPvki&amp;t=2923\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0441\u043b\u0443\u0448\u0430\u0442\u044c \u0442\u0443\u0442<\/a> \u0438\u043b\u0438 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/matrichnaya-faktorizaciya\" rel=\"noopener noreferrer nofollow\">\u0445\u0435\u043d\u0434\u0431\u0443\u043a<\/a>. \u041e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 <a href=\"https:\/\/www.youtube.com\/watch?v=gXbThCXjZFM&amp;list=PLMrJAkhIeNNSVjnsviglFoY2nXildDCcv&amp;index=1\" rel=\"noopener noreferrer nofollow\">\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438\u0439 \u0432\u0438\u0434\u0435\u043e\u0444\u043e\u0440\u043c\u0430\u0442<\/a> .<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0421\u0436\u0438\u043c\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 SVD \u0438 \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u0443\u0447\u0438\u043c\u0441\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 \u043c\u0435\u043d\u044c\u0448\u0438\u043c \u043a\u043e\u043b-\u0432\u043e\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SVD !<\/p>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_sample_image from skimage.color import rgb2gray from skimage.transform import resize  # --- \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443 china = load_sample_image(\"china.jpg\")   # \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 gray = rgb2gray(china)                   # \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0432 \u0447\/\u0431 gray = resize(gray, (256, 256), anti_aliasing=True)  # \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0434\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0430  # --- SVD U, S, VT = np.linalg.svd(gray, full_matrices=False)  # --- \u0412\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 k ks = [5, 20, 50, 100, 200] fig, axes = plt.subplots(1, len(ks) + 1, figsize=(15, 4))  # \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b axes[0].imshow(gray, cmap='gray') axes[0].set_title(\"\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\") axes[0].axis('off')  # \u041f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 k for i, k in enumerate(ks):     approx = U[:, :k] @ np.diag(S[:k]) @ VT[:k, :]     axes[i + 1].imshow(approx, cmap='gray')     axes[i + 1].set_title(f\"k = {k}\")     axes[i + 1].axis('off')  plt.suptitle(\"\u0421\u0436\u0430\u0442\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SVD\") plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><\/figure>\n<pre><code class=\"python\"># \u0420\u0430\u0441\u0447\u0451\u0442 \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u043e\u0439 \u0434\u043e\u043b\u0438 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 explained = np.cumsum(S) \/ np.sum(S)  # \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430: \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 + \u043d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043b\u044f fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(14, 5))  # --- 1. \u0421\u0430\u043c\u0438 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 (\u0432 \u043b\u043e\u0433 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0435) ax1.plot(S, marker='o') ax1.set_yscale(\"log\") ax1.set_title(\"\u0421\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\") ax1.set_xlabel(\"\u041d\u043e\u043c\u0435\u0440 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b\") ax1.set_ylabel(\"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 (log)\") ax1.grid(True)  # --- 2. \u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 ax2.plot(explained, label='C\u0443\u043c\u043c\u0430\u0440\u043d\u0430\u044f \u0434\u043e\u043b\u044f \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438') ax2.axhline(0.9, color='red', linestyle='--', label='90% \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438') ax2.set_xlabel(\"\u0427\u0438\u0441\u043b\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\") ax2.set_ylabel(\"\u041d\u0430\u043a\u043e\u043f\u043b\u0435\u043d\u043d\u0430\u044f \u0434\u043e\u043b\u044f\") ax2.set_title(\"\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u0443\u0442 \u0441\u0438\u043d\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\") ax2.grid(True) ax2.legend()  plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u0440\u043e\u0435\u0446\u0438\u0440\u0443\u0435\u043c \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0446\u0438\u0444\u0440) \u0432 2D \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e PCA<\/summary>\n<div class=\"spoiler__content\">\n<p> \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0446\u0438\u0444\u0440 (digits) \u2014 \u0432 \u043d\u0451\u043c 64 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 (8\u00d78 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430), \u0438 \u0441\u043e\u0436\u043c\u0451\u043c \u0434\u043e 2 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a PCA \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b: <\/p>\n<pre><code class=\"python\">from sklearn.datasets import load_digits from sklearn.decomposition import PCA import matplotlib.pyplot as plt  # --- \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 digits = load_digits() X = digits.data       # 64 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 (8x8 \u043f\u0438\u043a\u0441\u0435\u043b\u0435\u0439) y = digits.target     # \u043c\u0435\u0442\u043a\u0438 (0-9)  # --- PCA \u0434\u043e 2 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 pca = PCA(n_components=2) X_pca = pca.fit_transform(X)  # --- \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(8, 6)) scatter = plt.scatter(X_pca[:, 0], X_pca[:, 1], c=y, cmap='tab10', s=15, alpha=0.8) plt.legend(*scatter.legend_elements(), title=\"\u0426\u0438\u0444\u0440\u044b\", loc=\"best\", bbox_to_anchor=(1.05, 1)) plt.title(\"PCA-\u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (64D \u2192 2D)\") plt.xlabel(\"1-\u044f \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\") plt.ylabel(\"2-\u044f \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\") plt.grid(True) plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><\/figure>\n<\/div>\n<\/details>\n<h3>12. \u042d\u0442\u0430\u043f\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u0435\u0451 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f.<\/h3>\n<details class=\"spoiler\">\n<summary>\ud83d\udccc \u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0442\u0432\u0435\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 ML-\u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 <strong>\u0442\u0440\u0438 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u044d\u0442\u0430\u043f\u0430<\/strong>:<\/p>\n<ol>\n<li>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 (train)<\/strong> \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f (validation)<\/strong> \u2014 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u043c \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p><strong>\u0422\u0435\u0441\u0442 (test)<\/strong> \u2014 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430, \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437.<\/p>\n<\/li>\n<\/ol>\n<blockquote>\n<p>\u0411\u044b\u0432\u0430\u044e\u0442, \u0447\u0442\u043e \u0442\u0435\u0441\u0442 \u043e\u043f\u0443\u0441\u043a\u0430\u044e\u0442 \u0438 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0435\u0440\u0443\u0442 \u043b\u0443\u0447\u0448\u0435\u0435 \u0441 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438, \u043d\u043e \u044d\u0442\u043e \u0432\u0435\u0434\u0435\u0442 \u043a \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<\/blockquote>\n<hr\/>\n<p><strong>\u041f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435<\/strong> \u2014 \u044d\u0442\u043e \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0433\u043e\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u043d\u043e \u043f\u043b\u043e\u0445\u043e \u043e\u0431\u043e\u0431\u0449\u0430\u0435\u0442 \u043d\u0430 \u043d\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u0432\u0438\u0441\u0435\u0442\u044c \u043e\u0442 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 train\/val\/test \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 <strong>\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0444\u043e\u043b\u0434\u0430\u043c (k-fold cross-validation)<\/strong> &#8212; \u041e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f  \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0414\u0430\u0442\u0430\u0441\u0435\u0442 \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0430  \u0447\u0430\u0441\u0442\u0435\u0439, \u043d\u0430  \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0447\u0438\u0442\u044c\u0441\u044f, \u043d\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0437\u0430\u043c\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e. \u041c\u0435\u0442\u0440\u0438\u043a\u0430 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<blockquote>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0434\u0445\u043e\u0434 \u0445\u043e\u0442\u044c \u0443\u0441\u0442\u043e\u0439\u0447\u0435\u0432\u0435\u0435 \u043a \u0448\u0443\u043c\u0443, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0431\u044d\u0433\u0433\u0438\u043d\u0433 \u043d\u0430\u0434 \u044d\u0442\u0438\u043c\u0438  \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041e\u0431\u044b\u0447\u043d\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 EDA (exploratory data analysis \u0438\u043b\u0438 \u0440\u0430\u0437\u0432\u0435\u0434\u043e\u0447\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437) \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0442, \u0447\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 train\/val\/test \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0438 \u0443\u0447\u0430\u0442 \u043e\u0434\u043d\u0443 \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<\/blockquote>\n<hr\/>\n<p><strong>\u041a\u0430\u043a \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0430\u0442\u044c\u0441\u044f?<\/strong> (\u0435\u0441\u043b\u0438 \u043d\u0435\u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0447\u0435\u043a\u043f\u043e\u0438\u043d\u0442\u044b, \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u044c\u044e!)<\/p>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u0440\u0438\u043a\u0430 \u043d\u0430 train \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u043f\u0430\u0434\u0430\u0442\u044c, \u0430 \u043d\u0430 val \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u0442\u044c. (\u0415\u0441\u043b\u0438 \u043d\u0435\u0442\u0443 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432, \u0442\u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043d\u0430 train \u0441\u0438\u043b\u044c\u043d\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043d\u0430 val)<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f?<\/strong><\/p>\n<ul>\n<li>\n<p>Early stopping (\u0435\u0441\u043b\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u043b\u0430\u0441\u044c k \u0448\u0430\u0433\u043e\u0432 &#8212; \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f)<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0438 &#8212;  \/, Dropout\/BatchNorm, \u0430\u0443\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0442\u0434<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435\u0437\u043d\u0430\u0447\u0430\u0449\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 (\u0435\u0441\u043b\u0438 \u0438\u0445 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e, \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 \u043d\u0438\u0445 \u043e\u0442\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f, \u043c\u043e\u0436\u0435\u0442 \u0438 \u0441\u043e\u0439\u0434\u0435\u0442\u0441\u044f, \u043d\u043e \u0434\u041e\u043b\u044c\u0448\u0435!)<\/p>\n<\/li>\n<li>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0441\u044b\u043f\u0430\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u0411\u044d\u0433\u0433\u0438\u043d\u0433 (Bagging, \u043e\u0442 bootstrap aggregating) &#8212; \u0443\u0447\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0430 \u0431\u0443\u0442\u0441\u0440\u0435\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c =&gt; \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e \u043e\u0442\u0432\u0435\u0442\u0430<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0438\u043c\u043f\u0442\u043e\u043c\u044b \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u043c\u043e\u0436\u043d\u043e \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u043c\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u043c Double Descent) <\/p>\n<figure class=\"\"><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0440\u0430\u043d\u044c\u0448\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443 \u0432\u0430\u0441 Double Descent. \u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043b\u043e\u0441\u0441 \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u0437\u043b\u0435\u0442\u0438\u0442, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u043d\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u043c\u0435\u043d\u044c\u0448\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439!<\/p>\n<blockquote>\n<p>\u042f \u043d\u0435 \u0437\u043d\u0430\u044e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0443 \u043a\u043e\u0433\u043e \u0442\u0430\u043a\u043e\u0435 \u0431\u044b\u043b\u043e. \u041d\u043e \u043a\u0430\u043a \u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435.<\/p>\n<\/blockquote>\n<figure class=\"\"><\/figure>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e Double Descent \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/mlu-explain.github.io\/double-descent\/\" rel=\"noopener noreferrer nofollow\">1<\/a> \u0438 <a href=\"https:\/\/mlu-explain.github.io\/double-descent2\/\" rel=\"noopener noreferrer nofollow\">2<\/a>.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f: \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c \u0437\u0430 \u043b\u043e\u0441\u0441\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c\u0438 <\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u043f\u043e\u0445 \u0441 \u043b\u043e\u0441\u0441\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c\u0438, \u0435\u0441\u043b\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043a\u0440\u044b\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<blockquote>\n<p>\u042f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u043d\u044c\u043e \u0432\u0437\u044f\u043b \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0442\u043e\u0447\u0435\u043a (=150), \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b\/\u0440\u0430\u0437\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u0438 \u043f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u043c \u043d\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/blockquote>\n<pre><code class=\"python\">import torch import torch.nn as nn import torch.optim as optim from sklearn.datasets import make_moons from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt import numpy as np  # --- 1. \u0414\u0430\u043d\u043d\u044b\u0435 X, y_true = make_moons(n_samples=150, noise=0.3, random_state=42) # y_random = np.random.permutation(y_true)  # \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043c\u0435\u0442\u043a\u0438!  # X_train, X_val, y_train, y_val = train_test_split(X, y_random, test_size=0.3, random_state=42) X_train, X_val, y_train, y_val = train_test_split(X, y_true, test_size=0.3, random_state=42)  X_train_t = torch.tensor(X_train, dtype=torch.float32) y_train_t = torch.tensor(y_train.reshape(-1, 1), dtype=torch.float32)  X_val_t = torch.tensor(X_val, dtype=torch.float32) y_val_t = torch.tensor(y_val.reshape(-1, 1), dtype=torch.float32)  # --- 2. \u041c\u043e\u0434\u0435\u043b\u044c # h_size = 256 h_size = 100 model = nn.Sequential(     nn.Linear(2, h_size),     nn.ReLU(),     nn.Linear(h_size, h_size),     nn.ReLU(),     nn.Linear(h_size, 1),     nn.Sigmoid() )  loss_fn = nn.BCELoss() optimizer = optim.Adam(model.parameters(), lr=0.01)  train_losses, val_losses = [], [] snapshots = [0, 10, 30, 99]  # \u044d\u043f\u043e\u0445\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e  grids = np.meshgrid(     np.linspace(X[:, 0].min() - 0.5, X[:, 0].max() + 0.5, 300),     np.linspace(X[:, 1].min() - 0.5, X[:, 1].max() + 0.5, 300) ) grid_points = np.c_[grids[0].ravel(), grids[1].ravel()] grid_tensor = torch.tensor(grid_points, dtype=torch.float32)  # --- 3. \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 snapshots_preds = []  for epoch in range(100):     model.train()     y_pred = model(X_train_t)     loss = loss_fn(y_pred, y_train_t)          optimizer.zero_grad()     loss.backward()     optimizer.step()      model.eval()     with torch.no_grad():         val_pred = model(X_val_t)         val_loss = loss_fn(val_pred, y_val_t)         if epoch in snapshots:             pred_grid = model(grid_tensor).reshape(300, 300)             snapshots_preds.append((epoch, pred_grid.numpy()))          train_losses.append(loss.item())     val_losses.append(val_loss.item())  # --- 4. \u0413\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u0442\u0435\u0440\u044c plt.figure(figsize=(8, 5)) plt.plot(train_losses, label='Train Loss') plt.plot(val_losses, label='Validation Loss') plt.axvline(np.argmin(val_losses), linestyle='--', color='gray', label='\u041b\u0443\u0447\u0448\u0430\u044f<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-464268","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464268","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=464268"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464268\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}