{"id":463413,"date":"2025-06-15T03:00:08","date_gmt":"2025-06-15T03:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=463413"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=463413","title":{"rendered":"<span>\u0424\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043f\u043e ML\/DL, \u0447\u0430\u0441\u0442\u044c 1: \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. \u041b\u0438\u043d\u0435\u0439\u043a\u0438. \u0411\u0430\u0439\u0435\u0441. \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<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>\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.<\/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<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/sg\/80\/wc\/sg80wc891lrdbsliixpdgygh7nc.png\" width=\"800\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/sg\/80\/wc\/sg80wc891lrdbsliixpdgygh7nc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/sg\/80\/wc\/sg80wc891lrdbsliixpdgygh7nc.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 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043b\u043e\u0441\u044c \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<h3>\ud83d\udcda \u0413\u043b\u0430\u0432\u0430 1: \u041c\u043e\u0434\u0435\u043b\u0438, \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438 \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0411\u0430\u0439\u0435\u0441\u0430<\/h3>\n<h4>0. \u0417\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c. \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f, \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/h4>\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<ul>\n<li>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c<\/strong> \u2014 \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0441\u043d\u0430\u0431\u0436\u0451\u043d \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <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\"\/>, \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"f(x) \\approx y\" alt=\"f(x) \\approx y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/da\/da6\/da6364930d3a426e809b3154268dac2b.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/da\/da6\/da6364930d3a426e809b3154268dac2b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/da\/da6\/da6364930d3a426e809b3154268dac2b.svg 781w\" loading=\"lazy\" decode=\"async\"\/>.<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/strong>: \u0435\u0441\u043b\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"y \\in \\mathbb{R}\" alt=\"y \\in \\mathbb{R}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/82\/825\/8259e4a90e110709ea1e2f5ac3bf330b.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/82\/825\/8259e4a90e110709ea1e2f5ac3bf330b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/82\/825\/8259e4a90e110709ea1e2f5ac3bf330b.svg 781w\" loading=\"lazy\" decode=\"async\"\/> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0446\u0435\u043d\u0430, \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430).<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>: \u0435\u0441\u043b\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"y \\in \\{1, \\dots, K\\}\" alt=\"y \\in \\{1, \\dots, K\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/00\/00a\/00a6ab4a5ee83e2d4f7c2bd9a4b271d8.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/00\/00a\/00a6ab4a5ee83e2d4f7c2bd9a4b271d8.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/00\/00a\/00a6ab4a5ee83e2d4f7c2bd9a4b271d8.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0438\u043b\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0438\u0430\u0433\u043d\u043e\u0437, \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\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<h3>\u041e\u0431\u0449\u0430\u044f \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0412 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0438\u0437 \u043f\u0430\u0440<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"(x_i, y_i), \\quad i = 1, \\dots, n,\" alt=\"(x_i, y_i), \\quad i = 1, \\dots, n,\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/95\/95a\/95ab3d73c8526e2c5629f272cb6c7f14.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/95\/95a\/95ab3d73c8526e2c5629f272cb6c7f14.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/95\/95a\/95ab3d73c8526e2c5629f272cb6c7f14.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0433\u0434\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"x_i \\in \\mathbb{R}^d\" alt=\"x_i \\in \\mathbb{R}^d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8d\/8df\/8dff37afcc500954756c2b306e34e6c3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8d\/8df\/8dff37afcc500954756c2b306e34e6c3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8d\/8df\/8dff37afcc500954756c2b306e34e6c3.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432, <img decoding=\"async\" class=\"formula inline\" source=\"y_i\" alt=\"y_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8d\/8d6\/8d62e469fb30ed435a668eb5c035b1f6.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8d\/8d6\/8d62e469fb30ed435a668eb5c035b1f6.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8d\/8d6\/8d62e469fb30ed435a668eb5c035b1f6.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f. \u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c <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\"\/>, \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f.<\/p>\n<hr\/>\n<h3>\u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/h3>\n<p>\u0415\u0441\u043b\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"y_i \\in \\mathbb{R}\" alt=\"y_i \\in \\mathbb{R}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/35\/355\/355bc7b5aa3d744fe7315364bd990167.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/35\/355\/355bc7b5aa3d744fe7315364bd990167.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/35\/355\/355bc7b5aa3d744fe7315364bd990167.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438\u043b\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\mathbb{R}^k\" alt=\"\\mathbb{R}^k\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/55\/55d\/55d122a3bc618523c39dce5705ad6136.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/55\/55d\/55d122a3bc618523c39dce5705ad6136.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/55\/55d\/55d122a3bc618523c39dce5705ad6136.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439<\/strong>.<br \/> \u041c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c:<\/p>\n<ul>\n<li>\n<p>Mean Squared Error (MSE)<\/p>\n<\/li>\n<li>\n<p>Mean Absolute Error (MAE)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0446\u0435\u043d\u044b \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u041e\u0446\u0435\u043d\u043a\u0430 \u0441\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0442\u043e\u0432\u0430\u0440<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0415\u0441\u043b\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"y_i \\in \\{1, \\dots, K\\}\" alt=\"y_i \\in \\{1, \\dots, K\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1de\/1def7dbc99d98a16e523f2cff54b1546.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1de\/1def7dbc99d98a16e523f2cff54b1546.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1de\/1def7dbc99d98a16e523f2cff54b1546.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0437\u0430\u0434\u0430\u0447\u0430 <strong>\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/strong>.<br \/> \u0412 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 <strong>\u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;\u0434\u0430\/\u043d\u0435\u0442&#187;).<br \/> \u041f\u0440\u0438 <\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"K &gt; 2\" alt=\"K &gt; 2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0b\/0bc\/0bc9ec16650fae00a84652a0862811ac.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0b\/0bc\/0bc9ec16650fae00a84652a0862811ac.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0b\/0bc\/0bc9ec16650fae00a84652a0862811ac.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 <strong>\u043c\u043d\u043e\u0433\u043e\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u0430\u044f<\/strong>. \u0422\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 <strong>multi-label \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u043a. <\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0432\u044b\u0434\u0430\u0435\u0442 \u043b\u0438\u0431\u043e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c (soft), \u043b\u0438\u0431\u043e \u0441\u0440\u0430\u0437\u0443 \u043c\u0435\u0442\u043a\u0443 (hard). \u0427\u0430\u0441\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0442 logloss \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 surrogate-\u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0446\u0438\u0444\u0440 (0\u20139)<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f e-mail \u043a\u0430\u043a &#171;\u0441\u043f\u0430\u043c \/ \u043d\u0435 \u0441\u043f\u0430\u043c&#187;<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0417\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0447\u0443\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u043c, \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0438\u0438 (\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439  \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439) \u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439)<\/p>\n<pre><code class=\"python\">from sklearn.linear_model import LinearRegression, LogisticRegression from sklearn.datasets import make_regression, make_classification  # --- \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- X_reg, y_reg = make_regression(n_samples=100, n_features=2, noise=0.1, random_state=43) # [100, 2], [100] reg = LinearRegression().fit(X_reg, y_reg)  # --- \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f --- X_clf, y_clf = make_classification(n_samples=100, n_features=2, n_classes=2, n_redundant=0, random_state=43) # [100, 2], [100] clf = LogisticRegression().fit(X_clf, y_clf) <\/code><\/pre>\n<pre><code class=\"python\">  # --- \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 --- import matplotlib.pyplot as plt import numpy as np  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0438\u0433\u0443\u0440\u0443 \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0434\u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438 fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 5))  # --- \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0442\u043a\u0443 \u0442\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u043b\u0438\u043d\u0438\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 x_grid = np.linspace(X_reg[:, 0].min(), X_reg[:, 0].max(), 100).reshape(-1, 1) # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a (\u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435) # \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u043c\u043e\u0436\u0435\u043c =&gt; \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u0443\u0441\u0440\u0435\u0434\u043d\u0438\u043c!  # \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043b\u043e\u0445\u043e! \u043d\u043e \u0434\u043b\u044f \u0438\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 - \u043e\u043a! x_grid_full = np.column_stack([x_grid, np.full_like(x_grid, X_reg[:, 1].mean())]) y_pred = reg.predict(x_grid_full)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 ax1.scatter(X_reg[:, 0], y_reg, alpha=0.5, label='\u0414\u0430\u043d\u043d\u044b\u0435') ax1.plot(x_grid, y_pred, 'r-', label='\u041b\u0438\u043d\u0438\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438') ax1.set_title('\u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f') ax1.set_xlabel('\u041f\u0440\u0438\u0437\u043d\u0430\u043a 1') ax1.set_ylabel('\u0426\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f') ax1.legend()  # --- \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f --- # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0442\u043a\u0443 \u0442\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 x_min, x_max = X_clf[:, 0].min() - 0.5, X_clf[:, 0].max() + 0.5 y_min, y_max = X_clf[:, 1].min() - 0.5, X_clf[:, 1].max() + 0.5 xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02),                      np.arange(y_min, y_max, 0.02))  # \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a \u0441\u0435\u0442\u043a\u0438 Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) Z = Z.reshape(xx.shape)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 ax2.contourf(xx, yy, Z, alpha=0.3, cmap='viridis') ax2.contour(xx, yy, Z, [0.5], colors='red', linewidths=2)  scatter = ax2.scatter(X_clf[:, 0], X_clf[:, 1], c=y_clf, cmap='viridis', alpha=0.5) ax2.set_title('\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f') ax2.set_xlabel('\u041f\u0440\u0438\u0437\u043d\u0430\u043a 1') ax2.set_ylabel('\u041f\u0440\u0438\u0437\u043d\u0430\u043a 2') ax2.legend(*scatter.legend_elements(), title=\"\u041a\u043b\u0430\u0441\u0441\u044b\")  plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/l-\/rk\/jb\/l-rkjbjdhmpgbg8mqw51vn4_zx4.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/l-\/rk\/jb\/l-rkjbjdhmpgbg8mqw51vn4_zx4.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/l-\/rk\/jb\/l-rkjbjdhmpgbg8mqw51vn4_zx4.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h4>1. \u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438: accuracy, balanced accuracy, precision, recall, f1-score, ROC-AUC, \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h4>\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\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (<img decoding=\"async\" class=\"formula inline\" source=\"y \\in {0, 1}\" alt=\"y \\in {0, 1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e4f\/e4fa9ffd435daf72e3138e8009cc9914.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e4f\/e4fa9ffd435daf72e3138e8009cc9914.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e\/e4\/e4f\/e4fa9ffd435daf72e3138e8009cc9914.svg 781w\" loading=\"lazy\" decode=\"async\"\/>) \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e \u043d\u0438\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ym\/op\/la\/ymoplahkjrjy9zbbnqh74avxkgo.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ym\/op\/la\/ymoplahkjrjy9zbbnqh74avxkgo.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ym\/op\/la\/ymoplahkjrjy9zbbnqh74avxkgo.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041c\u0435\u0442\u0440\u0438\u043a\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0424\u043e\u0440\u043c\u0443\u043b\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0421\u043c\u044b\u0441\u043b<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Accuracy<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>Accuracy = (TP + TN) \/ (TP + TN + FP + FN)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u0449\u0430\u044f \u0434\u043e\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Balanced Accuracy<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>0.5 * (TPR + TNR) = 0.5 * (TP \/ (TP + FN) + TN \/ (TN + FP))<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0441\u0440\u0435\u0434\u043d\u0451\u043d\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u043f\u0440\u0438 \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Precision<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>TP \/ (TP + FP)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043b\u044f \u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Recall<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>TP \/ (TP + FN)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043b\u044f \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">F1(b)-score<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>2 * P * R \/ (P + R) = 2 \/ (1\/P + 1\/R) = [b=1] = (b^2 + 1) \/ (b^2 r^-1 + r^-1)  <\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0411\u0430\u043b\u0430\u043d\u0441 \u043c\u0435\u0436\u0434\u0443 precision \u0438 recall<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">AUC<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440 \u0441\u0440\u0435\u0434\u0438 (Negative, Positive)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e\u0434 ROC-\u043a\u0440\u0438\u0432\u043e\u0439 (TPR (y) vs FPR (x) \u043f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u0430\u0445)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/-p\/th\/tx\/-pthtx5b7dqdq1kfnbxab0fmymi.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/-p\/th\/tx\/-pthtx5b7dqdq1kfnbxab0fmymi.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/-p\/th\/tx\/-pthtx5b7dqdq1kfnbxab0fmymi.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041b\u0435\u0433\u0447\u0435 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043a\u0430\u043a TPR = recall \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 FPR = 1 &#8212; recall \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 !<\/p>\n<p>\u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 &#8212; \u044d\u0442\u043e \u0434\u043e\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440 \u0441\u0440\u0435\u0434\u0438 (Negative, Positive)<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ld\/5j\/u-\/ld5ju-0yxdvvddim7twzbpr-nis.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ld\/5j\/u-\/ld5ju-0yxdvvddim7twzbpr-nis.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ld\/5j\/u-\/ld5ju-0yxdvvddim7twzbpr-nis.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<ul>\n<li>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u043b\u043e\u0445\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 &#8212; AUC=0.5 \u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0432\u0435\u0440\u0441\u043d\u0443\u0442\u044c!<\/p>\n<\/li>\n<li>\n<p>\u041b\u0443\u0447\u0448\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 AUC=1<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u0414\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 &#8212; \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 one-vs-rest \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a. \u0414\u0430\u043b\u0435\u0435 \u043b\u0438\u0431\u043e \u043c\u0438\u043a\u0440\u043e-\u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u043c (\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043c\u0435\u0442\u0440\u043a\u0443) \u0438\u043b\u0438 \u043c\u0430\u043a\u0440\u043e-\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 (\u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u043c)<\/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>\u041e\u0447\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/metriki-klassifikacii-i-regressii\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>!<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0430\u043a \u0436\u0435 \u043d\u0430:<\/p>\n<ul>\n<li>\n<p>Recall@k, Precision@k<\/p>\n<\/li>\n<li>\n<p>Average Precision<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 &#8212; \u0442\u0430\u043c \u0438 \u0440\u0430\u0437\u0433\u0443\u043b\u044f\u0435\u043c\u0441\u044f (\u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043a\u0430\u043f\u0430\u0442\u044c\u0441\u044f)!<\/p>\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 AUC ROC<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"> from sklearn.datasets import make_classification from sklearn.linear_model import LogisticRegression from sklearn.dummy import DummyClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import roc_curve, roc_auc_score import matplotlib.pyplot as plt  # --- 1. \u0421\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \"\u0433\u0440\u044f\u0437\u043d\u044b\u0435\" \u0434\u0430\u043d\u043d\u044b\u0435 --- X, y = make_classification(     n_samples=1000,     n_features=20,     n_informative=5,     n_redundant=4,     n_classes=2,     weights=[0.75, 0.25],  # \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u0432     flip_y=0.1,            # 10% \u043c\u0435\u0442\u043e\u043a \u0448\u0443\u043c\u043d\u044b\u0435     class_sep=0.8,         # \u043a\u043b\u0430\u0441\u0441\u044b \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f     random_state=42 )  # --- 2. \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 train\/test --- X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=42)  # --- 3. \u041b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- model = LogisticRegression(max_iter=1000).fit(X_tr, y_tr) y_prob = model.predict_proba(X_te)[:, 1] fpr_model, tpr_model, _ = roc_curve(y_te, y_prob) auc_model = roc_auc_score(y_te, y_prob)  # --- 4. Dummy-\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 (\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f stratified) --- dummy = DummyClassifier(strategy='stratified', random_state=42).fit(X_tr, y_tr) y_dummy_prob = dummy.predict_proba(X_te)[:, 1] fpr_dummy, tpr_dummy, _ = roc_curve(y_te, y_dummy_prob) auc_dummy = roc_auc_score(y_te, y_dummy_prob)  # --- 5. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ROC-\u043a\u0440\u0438\u0432\u044b\u0445 --- plt.figure(figsize=(8, 6)) plt.plot(fpr_model, tpr_model, label=f\"Logistic Regression (AUC = {auc_model:.2f})\") plt.plot(fpr_dummy, tpr_dummy, linestyle='--', label=f\"Dummy Stratified (AUC = {auc_dummy:.2f})\") plt.plot([0, 1], [0, 1], 'k:', label=\"Random Guess (AUC = 0.50)\")  plt.xlabel(\"False Positive Rate (FPR)\") plt.ylabel(\"True Positive Rate (TPR)\") plt.title(\"ROC-\u043a\u0440\u0438\u0432\u0430\u044f: \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f vs \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\") 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\/x2\/mz\/fb\/x2mzfblet_xeei8fize344lki4w.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/x2\/mz\/fb\/x2mzfblet_xeei8fize344lki4w.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/x2\/mz\/fb\/x2mzfblet_xeei8fize344lki4w.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h4>2. \u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438: MSE, MAE, R\u00b2<\/h4>\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<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041c\u0435\u0442\u0440\u0438\u043a\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0424\u043e\u0440\u043c\u0443\u043b\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0421\u043c\u044b\u0441\u043b<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MSE<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>mean((y_true - y_pred) ** 2)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430. \u041d\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0438\u043b\u044c\u043d\u0435\u0435.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MAE<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>mean(abs(y_true - y_pred))<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430. \u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">R\u00b2 score<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>1 - MSE_model \/ MSE_const<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0443\u0447\u0448\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f(=\u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 MSE) . \u041e\u0442 0 \u0434\u043e 1 (\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c &lt; 0 \u043f\u0440\u0438 \u043f\u043b\u043e\u0445\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438).<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/od\/ab\/tf\/odabtfuydodxhboo2geeg3lb5nw.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/od\/ab\/tf\/odabtfuydodxhboo2geeg3lb5nw.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/od\/ab\/tf\/odabtfuydodxhboo2geeg3lb5nw.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><strong>MSE (Mean Squared Error)<\/strong><br \/> \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c. \u041e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0443 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c.<br \/> <code>MSE = mean((y - \u0177) ** 2)<\/code><\/p>\n<p><strong>MAE (Mean Absolute Error)<\/strong><br \/> \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c\u0438 \u0438 \u0438\u0441\u0442\u0438\u043d\u043e\u0439. \u041c\u0435\u043d\u0435\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0430 \u043a \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c(=\u0440\u043e\u0431\u0430\u0441\u0442\u043d\u0435\u0435), \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f (\u0432 \u0442\u0435\u0445 \u0436\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445, \u0447\u0442\u043e \u0438 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f).<br \/> <code>MAE = mean(|y - \u0177|)<\/code><\/p>\n<p><strong>Huber Loss<\/strong> \u2014 \u0433\u0438\u0431\u0440\u0438\u0434 \u043c\u0435\u0436\u0434\u0443 MSE \u0438 MAE: \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u0442\u0440\u0430\u0444, \u0434\u0430\u043b\u044c\u0448\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439.<\/p>\n<p><strong>R\u00b2 (\u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0446\u0438\u0438)<\/strong><br \/> \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c.<br \/> <code>R\u00b2 = 1 - (MSE_model \/ MSE_const)<\/code><br \/> \u0413\u0434\u0435 <code>MSE_const<\/code> \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430\u0438\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u043d\u0435\u0435.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043e\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score from sklearn.datasets import make_regression from sklearn.linear_model import LinearRegression, HuberRegressor from sklearn.model_selection import train_test_split  # \u0414\u0430\u043d\u043d\u044b\u0435 X, y = make_regression(n_samples=500, noise=15, random_state=42) X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=42)  # --- \u041b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- model_lr = LinearRegression().fit(X_tr, y_tr) y_pred_lr = model_lr.predict(X_te)  print(\"=== Linear Regression ===\") print(\"MSE:\", mean_squared_error(y_te, y_pred_lr)) print(\"MAE:\", mean_absolute_error(y_te, y_pred_lr)) print(\"R\u00b2:\", r2_score(y_te, y_pred_lr))  # --- Huber-\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- model_huber = HuberRegressor().fit(X_tr, y_tr) y_pred_huber = model_huber.predict(X_te)  print(\"\\n=== Huber Regressor ===\") print(\"MSE:\", mean_squared_error(y_te, y_pred_huber)) print(\"MAE:\", mean_absolute_error(y_te, y_pred_huber)) print(\"R\u00b2:\", r2_score(y_te, y_pred_huber)) <\/code><\/pre>\n<pre><code>=== Linear Regression === MSE: 334.45719591398216 MAE: 14.30958669001259 R\u00b2: 0.988668164971938  === Huber Regressor === MSE: 367.2515287731075 MAE: 15.169297076822216 R\u00b2: 0.9875570512797974 <\/code><\/pre>\n<p>\u042d\u0442\u0438 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 &#8212; \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043b\u043e\u0441\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0442\u0430\u043a \u0438 \u0431\u0438\u0437\u043d\u0435\u0441\u0441 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438! \u041a\u0430\u043a\u043e\u0439 \u043b\u043e\u0441\u0441 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0430\u044f \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u0431\u0438\u0437\u043d\u0435\u0441 \u043c\u0435\u0442\u0440\u0438\u043a\u0430!<\/p>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt  # \u041e\u0448\u0438\u0431\u043a\u0438 (residuals) errors = np.linspace(-2, 2, 400)  # MSE: \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u0435 \u043f\u043e\u0442\u0435\u0440\u0438 mse_loss = errors ** 2  # MAE: \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u044b\u0435 \u043f\u043e\u0442\u0435\u0440\u0438 mae_loss = np.abs(errors)  # Huber loss delta = 1.0 huber_loss = np.where(     np.abs(errors) &lt;= delta,     0.5 * errors ** 2,     delta * (np.abs(errors) - 0.5 * delta) )  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(8, 6)) plt.plot(errors, mse_loss, label='MSE Loss', color='red') plt.plot(errors, mae_loss, label='MAE Loss', color='blue') plt.plot(errors, huber_loss, label='Huber Loss (\u03b4 = 1.0)', color='green') plt.xlabel(\"\u041e\u0448\u0438\u0431\u043a\u0430 (residual)\") plt.ylabel(\"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c\") plt.title(\"\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 MSE, MAE \u0438 Huber Loss\") 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\/od\/ab\/tf\/odabtfuydodxhboo2geeg3lb5nw.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/od\/ab\/tf\/odabtfuydodxhboo2geeg3lb5nw.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/od\/ab\/tf\/odabtfuydodxhboo2geeg3lb5nw.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h4>3. \u041e\u0446\u0435\u043d\u043a\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u044f (MLE), \u0441\u0432\u044f\u0437\u044c \u0441 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439 \u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439<\/h4>\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>MLE (Maximum Likelihood Estimation)<\/strong> \u2014 \u043c\u0435\u0442\u043e\u0434 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<blockquote>\n<p>\u0426\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f (\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0434\u0435\u043b\u0438) \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u043b\u0443\u0430\u0439\u043d\u044b\u0435 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b.<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u0424\u0438\u043a\u0441\u0438\u0440\u0443\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0435) \u0438 \u0438\u0449\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 (=&gt; \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u0435\u043c\u043f\u043b\u0430 \u0438 \u043f\u0440\u0438 \u0432\u044b\u0432\u043e\u0434\u043a \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0441\u0435\u043c\u043f\u043b\u043e\u0432)!<\/p>\n<\/blockquote>\n<ul>\n<li>\n<p>\u0412 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 (\u043f\u0440\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u0448\u0443\u043c\u0435) MLE \u21d4 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f MSE<\/p>\n<\/li>\n<li>\n<p>\u0412 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 MLE \u21d4 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u043e\u0433\u043b\u043e\u0441\u0441\u0430<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/strong> \u0432\u043d\u043e\u0441\u0438\u0442 \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f (MAP) \u043d\u0430 \u0432\u0435\u0441\u0430. \u041f\u0440\u0438 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <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\"\/> \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044e, \u043f\u0440\u0438 \u043b\u0430\u043f\u043b\u0430\u0441\u0441\u0435 <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\"\/>.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udd2c \u0424\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0432\u043e\u0434\u044b<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0414\u0435\u0442\u0430\u043b\u044c\u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/girafe-ai\/ml-course\/blob\/23f_basic\/week0_02_linear_reg\/week02_extra_data_preprocessing_example_full.ipynb\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043d\u0446\u0435 \u0442\u0435\u0442\u0440\u0430\u0434\u043a\u0435<\/a>.<\/p>\n<h3>\u270d MLE \u0438 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/h3>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>y\u1d62<\/code> \u0438\u043c\u0435\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0441 \u0446\u0435\u043d\u0442\u0440\u043e\u043c \u0432 <code>x\u1d62\u1d40w<\/code> \u0438 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0435\u0439 <code>\u03c3\u00b2<\/code>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"y_i \\sim \\mathcal{N}(x_i^\\top w, \\sigma^2)\" alt=\"y_i \\sim \\mathcal{N}(x_i^\\top w, \\sigma^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ad\/add\/adde6362509a0fe548f0f2d71372cc33.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ad\/add\/adde6362509a0fe548f0f2d71372cc33.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ad\/add\/adde6362509a0fe548f0f2d71372cc33.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0422\u043e\u0433\u0434\u0430 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u0432\u0441\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"p(y | X, \\theta) = \\prod_i \\mathcal{N}(y_i | x_i^\\top w, \\sigma^2)\" alt=\"p(y | X, \\theta) = \\prod_i \\mathcal{N}(y_i | x_i^\\top w, \\sigma^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/38\/38c\/38c525d0fe809e6c26d03d7cc88047be.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/38\/38c\/38c525d0fe809e6c26d03d7cc88047be.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/38\/38c\/38c525d0fe809e6c26d03d7cc88047be.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0411\u0435\u0440\u0451\u043c \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log p(y | X, \\theta) = \\sum_i \\log \\left( \\frac{1}{\\sqrt{2\\pi} \\sigma} \\exp\\left( -\\frac{(y_i - x_i^\\top w)^2}{2\\sigma^2} \\right) \\right)\" alt=\"\\log p(y | X, \\theta) = \\sum_i \\log \\left( \\frac{1}{\\sqrt{2\\pi} \\sigma} \\exp\\left( -\\frac{(y_i - x_i^\\top w)^2}{2\\sigma^2} \\right) \\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/52\/52d\/52d78e042f4511598349fd1a31c09480.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/52\/52d\/52d78e042f4511598349fd1a31c09480.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/52\/52d\/52d78e042f4511598349fd1a31c09480.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0420\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0443\u043c\u043c\u0443:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"= \\sum_i \\left( -\\frac{1}{2} \\log(2\\pi) - \\log \\sigma - \\frac{(y_i - x_i^\\top w)^2}{2\\sigma^2} \\right)\" alt=\"= \\sum_i \\left( -\\frac{1}{2} \\log(2\\pi) - \\log \\sigma - \\frac{(y_i - x_i^\\top w)^2}{2\\sigma^2} \\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3b\/3b9\/3b9e27568ecd81166d02c6382982c242.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3b\/3b9\/3b9e27568ecd81166d02c6382982c242.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3b\/3b9\/3b9e27568ecd81166d02c6382982c242.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u2192 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0430 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u044f \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u0430 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\sum_i (y_i - x_i^\\top w)^2\" alt=\"\\sum_i (y_i - x_i^\\top w)^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/81\/812\/81213ac0f049da1fd9155612bb79e1cc.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/81\/812\/81213ac0f049da1fd9155612bb79e1cc.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/81\/812\/81213ac0f049da1fd9155612bb79e1cc.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<hr\/>\n<h3>\u2705 \u0412\u044b\u0432\u043e\u0434:<\/h3>\n<p>\u041c\u0435\u0442\u043e\u0434 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u044f (MLE) \u0434\u043b\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 <strong>\u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c MSE<\/strong> \u2014 \u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0439 \u043e\u0448\u0438\u0431\u043a\u0435.<\/p>\n<blockquote>\n<p>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Ridge(=<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\"\/>)) \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u0432\u0435\u0441\u0430 \u2014 \u044d\u0442\u043e \u0443\u0436\u0435 <strong>MAP<\/strong>, \u043d\u0435 MLE.<\/p>\n<\/blockquote>\n<hr\/>\n<h3>\u270d MLE \u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/h3>\n<p>\u0412 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>y\u1d62 \u2208 {0, 1}<\/code> &#8212; \u0434\u043b\u044f \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u043d\u0438\u0435 \u0411\u0435\u0440\u043d\u0443\u043b\u0438.<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"P(y_i = 1 | x_i, w) = \\sigma(x_i^\\top w) = \\frac{1}{1 + e^{-x_i^\\top w}}\" alt=\"P(y_i = 1 | x_i, w) = \\sigma(x_i^\\top w) = \\frac{1}{1 + e^{-x_i^\\top w}}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5b0\/5b09033482aed73416b288177a3613d3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5b0\/5b09033482aed73416b288177a3613d3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5b\/5b0\/5b09033482aed73416b288177a3613d3.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u0435 \u0432\u0441\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"L(w) = \\prod_i \\left[ \\sigma(x_i^\\top w) \\right]^{y_i} \\cdot \\left[ 1 - \\sigma(x_i^\\top w) \\right]^{1 - y_i}\" alt=\"L(w) = \\prod_i \\left[ \\sigma(x_i^\\top w) \\right]^{y_i} \\cdot \\left[ 1 - \\sigma(x_i^\\top w) \\right]^{1 - y_i}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/df\/dfb\/dfb7701357660b9a98db40eb4ec5d940.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/df\/dfb\/dfb7701357660b9a98db40eb4ec5d940.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/df\/dfb\/dfb7701357660b9a98db40eb4ec5d940.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041b\u043e\u0433\u0430\u0440\u0438\u0444\u043c \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u044f:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log L(w) = \\sum_i \\left[ y_i \\log \\sigma(x_i^\\top w) + (1 - y_i) \\log (1 - \\sigma(x_i^\\top w)) \\right]\" alt=\"\\log L(w) = \\sum_i \\left[ y_i \\log \\sigma(x_i^\\top w) + (1 - y_i) \\log (1 - \\sigma(x_i^\\top w)) \\right]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/b3\/b37\/b37cbc00d51a8e0a8e0a910f77d0bef1.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/b3\/b37\/b37cbc00d51a8e0a8e0a910f77d0bef1.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/b3\/b37\/b37cbc00d51a8e0a8e0a910f77d0bef1.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<hr\/>\n<h3>\u2705 \u0412\u044b\u0432\u043e\u0434:<\/h3>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0430 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u044f \u21d4 <strong>\u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f log-loss (\u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c)<\/strong><\/p>\n<hr\/>\n<h3>\u270d \u0427\u0442\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439: MAP (Maximum A Posteriori)<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>L2-\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u21d4 \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0435 <code>w \u223c \ud835\udca9(0, \u03bb\u207b\u00b9I)<\/code><\/p>\n<\/li>\n<li>\n<p>L1-\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u21d4 \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0435 <code>w \u223c Laplace(0, b)<\/code><\/p>\n<\/li>\n<\/ul>\n<p>MAP-\u043e\u0446\u0435\u043d\u043a\u0430:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log P(w | X, y) \u221d \\log L(w) + \\log P(w)\" alt=\"\\log P(w | X, y) \u221d \\log L(w) + \\log P(w)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/22\/227\/2278007a3463b8caaaad404964733b14.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/22\/227\/2278007a3463b8caaaad404964733b14.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/22\/227\/2278007a3463b8caaaad404964733b14.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u2192 \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c <strong>MLE + \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/strong>:<\/p>\n<ul>\n<li>\n<p><code>MLE<\/code> \u21d4 \u043b\u043e\u0433\u043b\u043e\u0441\u0441<\/p>\n<\/li>\n<li>\n<p><code>MAP<\/code> \u21d4 \u043b\u043e\u0433\u043b\u043e\u0441\u0441 + \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0411\u0430\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u044b\u0432\u043e\u0434 \u0434\u0432\u0443\u0445 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439<\/summary>\n<div class=\"spoiler__content\">\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430<\/h3>\n<p>\u041f\u0443\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <img decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0438:<\/p>\n<ul>\n<li>\n<p><strong>Prior<\/strong>: <img decoding=\"async\" class=\"formula inline\" source=\"w \\sim \\mathcal{N}(\\mu_0, \\sigma_0^2)\" alt=\"w \\sim \\mathcal{N}(\\mu_0, \\sigma_0^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a02\/a02a56633fa23725c1880ef212319d72.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a02\/a02a56633fa23725c1880ef212319d72.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a02\/a02a56633fa23725c1880ef212319d72.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p><strong>Likelihood<\/strong>: <img decoding=\"async\" class=\"formula inline\" source=\"y \\sim \\mathcal{N}(\\mu_1, \\sigma_1^2)\" alt=\"y \\sim \\mathcal{N}(\\mu_1, \\sigma_1^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4c\/4c7\/4c79215310501b9fe4f062480835b796.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4c\/4c7\/4c79215310501b9fe4f062480835b796.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4c\/4c7\/4c79215310501b9fe4f062480835b796.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0435 \u0441 <img decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0439\u0442\u0438 <strong>posterior<\/strong> <img decoding=\"async\" class=\"formula inline\" source=\"P(w \\mid y)\" alt=\"P(w \\mid y)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/14a\/14a7db2c678ef347d03199580151f9da.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/14a\/14a7db2c678ef347d03199580151f9da.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/14a\/14a7db2c678ef347d03199580151f9da.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>\ud83d\udcd0 \u0428\u0430\u0433 1: \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0411\u0430\u0439\u0435\u0441\u0430<\/h3>\n<p>\u041f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044e:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"P(w | y) \\propto P(y | w) \\cdot P(w)\" alt=\"P(w | y) \\propto P(y | w) \\cdot P(w)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/ba\/bae\/baed4fe7fbb5a5d0b20d1ce40de39760.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/ba\/bae\/baed4fe7fbb5a5d0b20d1ce40de39760.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/ba\/bae\/baed4fe7fbb5a5d0b20d1ce40de39760.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0435 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log P(w | y) = \\log P(y | w) + \\log P(w) + \\text{const}\" alt=\"\\log P(w | y) = \\log P(y | w) + \\log P(w) + \\text{const}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/63\/631\/63156003dcb04bd5130a2385bed675f7.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/63\/631\/63156003dcb04bd5130a2385bed675f7.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/63\/631\/63156003dcb04bd5130a2385bed675f7.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>\ud83e\uddee \u0428\u0430\u0433 2: \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/h3>\n<ol>\n<li>\n<p>Prior:<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log P(w) = -\\frac{1}{2\\sigma_0^2} (w - \\mu_0)^2 + \\text{const}\" alt=\"\\log P(w) = -\\frac{1}{2\\sigma_0^2} (w - \\mu_0)^2 + \\text{const}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a6\/a6b\/a6bc01ebcf142ccb8ca54e9c9a242417.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a6\/a6b\/a6bc01ebcf142ccb8ca54e9c9a242417.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a6\/a6b\/a6bc01ebcf142ccb8ca54e9c9a242417.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<ol start=\"2\">\n<li>\n<p>Likelihood (\u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 <img decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0444\u0438\u043a\u0441\u0438\u0440\u0443\u044f <img decoding=\"async\" class=\"formula inline\" source=\"y = \\mu_1\" alt=\"y = \\mu_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/09\/096\/096b291b542ef9ffd328e1348dc5897d.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/09\/096\/096b291b542ef9ffd328e1348dc5897d.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/09\/096\/096b291b542ef9ffd328e1348dc5897d.svg 781w\" loading=\"lazy\" decode=\"async\"\/>):<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log P(y | w) = -\\frac{1}{2\\sigma_1^2} (w - \\mu_1)^2 + \\text{const}\" alt=\"\\log P(y | w) = -\\frac{1}{2\\sigma_1^2} (w - \\mu_1)^2 + \\text{const}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/18\/18f\/18faf3eaea3688f351dbca9d5edcadf0.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/18\/18f\/18faf3eaea3688f351dbca9d5edcadf0.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/18\/18f\/18faf3eaea3688f351dbca9d5edcadf0.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>\ud83d\udcc9 \u0428\u0430\u0433 3: \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u044b<\/h3>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log P(w | y) = -\\frac{1}{2\\sigma_0^2} (w - \\mu_0)^2 - \\frac{1}{2\\sigma_1^2} (w - \\mu_1)^2 + \\text{const}\" alt=\"\\log P(w | y) = -\\frac{1}{2\\sigma_0^2} (w - \\mu_0)^2 - \\frac{1}{2\\sigma_1^2} (w - \\mu_1)^2 + \\text{const}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6a\/6a2\/6a2e248f81c168d3bfe5980b093232bd.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6a\/6a2\/6a2e248f81c168d3bfe5980b093232bd.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6a\/6a2\/6a2e248f81c168d3bfe5980b093232bd.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u042d\u0442\u043e \u2014 <strong>\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e <img decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/strong>, \u0442\u043e \u0435\u0441\u0442\u044c \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0441\u0430\u043c <strong>posterior \u2014 \u0442\u043e\u0436\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439<\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"P(w | y) = \\mathcal{N}(\\mu_{\\text{post}}, \\sigma_{\\text{post}}^2)\" alt=\"P(w | y) = \\mathcal{N}(\\mu_{\\text{post}}, \\sigma_{\\text{post}}^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/65\/655\/655987f3dcb6f941b3af694f9a2d63a4.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/65\/655\/655987f3dcb6f941b3af694f9a2d63a4.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/65\/655\/655987f3dcb6f941b3af694f9a2d63a4.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>\u2705 \u0412\u044b\u0432\u043e\u0434: \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/h3>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\sigma_{\\text{post}}^2 = \\left( \\frac{1}{\\sigma_0^2} + \\frac{1}{\\sigma_1^2} \\right)^{-1}\" alt=\"\\sigma_{\\text{post}}^2 = \\left( \\frac{1}{\\sigma_0^2} + \\frac{1}{\\sigma_1^2} \\right)^{-1}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6c\/6c0\/6c0d7abded76967fb695f4e9e2875f96.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6c\/6c0\/6c0d7abded76967fb695f4e9e2875f96.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/6\/6c\/6c0\/6c0d7abded76967fb695f4e9e2875f96.svg 781w\" loading=\"lazy\" decode=\"async\"\/><img decoding=\"async\" class=\"formula\" source=\"\\mu_{\\text{post}} = \\sigma_{\\text{post}}^2 \\left( \\frac{\\mu_0}{\\sigma_0^2} + \\frac{\\mu_1}{\\sigma_1^2} \\right)\" alt=\"\\mu_{\\text{post}} = \\sigma_{\\text{post}}^2 \\left( \\frac{\\mu_0}{\\sigma_0^2} + \\frac{\\mu_1}{\\sigma_1^2} \\right)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/30\/30e\/30e0a084995f6a776c3a04963e23a0cb.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/30\/30e\/30e0a084995f6a776c3a04963e23a0cb.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/30\/30e\/30e0a084995f6a776c3a04963e23a0cb.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<hr\/>\n<h3>\u041e\u0442\u0440\u0438\u0441\u0443\u0435\u043c!<\/h3>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt from scipy.stats import norm  # \u041e\u0441\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 w w = np.linspace(-5, 5, 500)  # \u0417\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b mu0, sigma0 = 0, 1     # prior: N(0, 1) mu1, sigma1 = 2, 1     # likelihood: N(2, 1)  # \u0420\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f prior = norm.pdf(w, loc=mu0, scale=sigma0) likelihood = norm.pdf(w, loc=mu1, scale=sigma1)  # \u041f\u043e\u0441\u0442\u0435\u0440\u0438\u043e\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u2014 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 sigma_post_sq = 1 \/ (1\/sigma0**2 + 1\/sigma1**2) mu_post = sigma_post_sq * (mu0\/sigma0**2 + mu1\/sigma1**2) posterior = norm.pdf(w, loc=mu_post, scale=np.sqrt(sigma_post_sq))  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(10, 6)) plt.plot(w, prior, label=f\"Prior N({mu0}, {sigma0**2})\", color='green') plt.plot(w, likelihood, label=f\"Likelihood N({mu1}, {sigma1**2})\", color='blue') plt.plot(w, posterior, label=f\"Posterior N({mu_post:.2f}, {sigma_post_sq:.2f})\", color='red')  plt.axvline(mu0, color='green', linestyle=':') plt.axvline(mu1, color='blue', linestyle=':') plt.axvline(mu_post, color='red', linestyle='--', label=f\"MAP = {mu_post:.2f}\")  plt.title(\"\u0411\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u0432\u044b\u0432\u043e\u0434: Posterior = Prior \u00d7 Likelihood\") plt.xlabel(\"w\") plt.ylabel(\"\u041f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c\") 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\/-x\/tr\/ag\/-xtraghhvtbnp8vgezj0pave35c.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/-x\/tr\/ag\/-xtraghhvtbnp8vgezj0pave35c.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/-x\/tr\/ag\/-xtraghhvtbnp8vgezj0pave35c.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<blockquote>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0434\u0430\u0436\u0435 \u0434\u043b\u044f \u0434\u0432\u0443\u0445 \u043c\u043d\u043e\u0433\u043c\u0435\u0440\u043d\u044b\u0445 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044f\u043c\u0438 &#8212; \u0432\u0435\u0440\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435, \u0438\u0445 \u0430\u043f\u043e\u0441\u0442\u0435\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u0436\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0435!<\/p>\n<\/blockquote>\n<\/div>\n<\/details>\n<h4>4. \u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/h4>\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>\u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0441\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b \u043f\u0440\u0438 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"P(y | x_1, ..., x_d) \u221d P(y) \\cdot \\prod_{i=1}^d P(x_i | y)\" alt=\"P(y | x_1, ..., x_d) \u221d P(y) \\cdot \\prod_{i=1}^d P(x_i | y)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fd\/fd3\/fd3acfcf101ac57ff9657e2220306cdb.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fd\/fd3\/fd3acfcf101ac57ff9657e2220306cdb.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fd\/fd3\/fd3acfcf101ac57ff9657e2220306cdb.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435: \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u043c <code>P(y)<\/code> \u0438 <code>P(x\u1d62 | y)<\/code> \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443.<br \/> \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e, \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432 \u043a \u043c\u0430\u043b\u044b\u043c \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u043c, \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\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<p>\u0412 \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u0435:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log P(y | x) \u221d \\log P(y) + \\sum_i \\log P(x_i | y)\" alt=\"\\log P(y | x) \u221d \\log P(y) + \\sum_i \\log P(x_i | y)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/769\/769e63814d987e407dd3f0637de2a36a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/769\/769e63814d987e407dd3f0637de2a36a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/769\/769e63814d987e407dd3f0637de2a36a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><strong>\u0413\u0430\u0443\u0441\u0441\u043e\u0432\u0441\u043a\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435<\/strong> \u2014 <code>GaussianNB<\/code><\/p>\n<\/li>\n<li>\n<p><strong>\u042f\u0434\u0435\u0440\u043d\u0443\u044e \u043e\u0446\u0435\u043d\u043a\u0443 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 (KDE)<\/strong> \u2014 \u0441\u0433\u043b\u0430\u0436\u0435\u043d\u043d\u044b\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p><strong>\u042d\u043a\u0441\u043f\u043e\u043d\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435, \u041b\u0430\u043f\u043b\u0430\u0441\u043e\u0432\u0441\u043a\u043e\u0435 \u0438 \u0434\u0440.<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430: \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u0434 \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u0411\u0430\u0435\u0439\u0441 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (KDE)<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u043e\u043b\u043d\u0430\u044f <a href=\"https:\/\/github.com\/girafe-ai\/ml-course\/blob\/23f_basic\/week0_01_naive_bayes\/week0_01_01_naive_bayes__completed.ipynb\" rel=\"noopener noreferrer nofollow\">\u0442\u0435\u0442\u0440\u0430\u0434\u043a\u0430 \u0442\u0443\u0442<\/a>.<\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 4 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438, \u0430 \u0441 \u0434\u0432\u0443\u043c\u044f!<\/p>\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split from sklearn.neighbors import KernelDensity from sklearn.metrics import accuracy_score from sklearn.naive_bayes import GaussianNB from scipy.special import logsumexp  # --- 1. \u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 iris = load_iris() X = iris.data[:, [2, 3]]  # \u0434\u0432\u0430 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430: \u0434\u043b\u0438\u043d\u0430 \u0438 \u0448\u0438\u0440\u0438\u043d\u0430 \u043b\u0435\u043f\u0435\u0441\u0442\u043a\u0430 y = iris.target feature_names = np.array(iris.feature_names)[[2, 3]] class_names = iris.target_names  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42) <\/code><\/pre>\n<pre><code class=\"python\"># --- 2. \u041e\u0431\u0451\u0440\u0442\u043a\u0430 KDE class KDEWrapper:     def __init__(self, data):         self.kde = KernelDensity(kernel='gaussian', bandwidth=0.2).fit(data[:, None])      def logpdf(self, x):         return self.kde.score_samples(x[:, None])       #  --- 3. NaiveBayes \u0438\u0437 \u0442\u0435\u0442\u0440\u0430\u0434\u043a\u0438 class NaiveBayes:     def fit(self, X, y, sample_weight=None, distributions=None):         self.unique_labels = np.unique(y)         if distributions is None:             distributions = [KDEWrapper] * X.shape[1]         assert len(distributions) == X.shape[1]         self.conditional_feature_distributions = {}         for label in self.unique_labels:             dists = []             for i in range(X.shape[1]):                 dists.append(distributions[i](X[y == label, i]))             self.conditional_feature_distributions[label] = dists         self.prior_label_distibution = {l: np.mean(y == l) for l in self.unique_labels}      def predict_log_proba(self, X):         log_proba = np.zeros((X.shape[0], len(self.unique_labels)))         for i, label in enumerate(self.unique_labels):             for j in range(X.shape[1]):                 log_proba[:, i] += self.conditional_feature_distributions[label][j].logpdf(X[:, j])             log_proba[:, i] += np.log(self.prior_label_distibution[label])         log_proba -= logsumexp(log_proba, axis=1)[:, None]         return log_proba      def predict(self, X):         return self.unique_labels[np.argmax(self.predict_log_proba(X), axis=1)] <\/code><\/pre>\n<pre><code class=\"python\"># --- 4. \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 model_kde = NaiveBayes() model_kde.fit(X_train, y_train, distributions=[KDEWrapper, KDEWrapper]) y_pred_kde = model_kde.predict(X_test)  model_gnb = GaussianNB() model_gnb.fit(X_train, y_train) y_pred_gnb = model_gnb.predict(X_test)  print(\"KDE NB Accuracy:\", accuracy_score(y_test, y_pred_kde)) print(\"GaussianNB Accuracy:\", accuracy_score(y_test, y_pred_gnb))  # KDE NB Accuracy: 1.0 # GaussianNB Accuracy: 1.0 <\/code><\/pre>\n<pre><code class=\"python\"># --- 5. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f KDE-\u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0435\u0439 def plot_kde_and_gaussian_densities(X_data, y_data):     fig, axes = plt.subplots(1, 2, figsize=(12, 4))          # \u041e\u0431\u0443\u0447\u0438\u043c GaussianNB \u2014 \u043e\u043d \u0441\u0430\u043c \u043e\u0446\u0435\u043d\u0438\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b     gnb = GaussianNB()     gnb.fit(X_data, y_data)      for i in range(X_data.shape[1]):         ax = axes[i]         for label in np.unique(y_data):             x_vals = X_data[y_data == label, i]             grid = np.linspace(x_vals.min() * 0.9, x_vals.max() * 1.1, 500)              # --- KDE             kde = KernelDensity(kernel='gaussian', bandwidth=0.2).fit(x_vals[:, None])             ax.plot(grid, np.exp(kde.score_samples(grid[:, None])), label=f'{class_names[label]} (KDE)', linestyle='-')              # --- Gauss via GaussianNB             mu = gnb.theta_[label, i]             sigma = np.sqrt(gnb.var_[label, i])             ax.plot(grid, norm.pdf(grid, mu, sigma), label=f'{class_names[label]} (Gauss)', linestyle='--')           ax.set_title(f'\u041f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u044f {feature_names[i]}')         ax.set_xlabel('\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430')         ax.set_ylabel('\u041f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u044c')         ax.legend()         ax.grid()      plt.tight_layout()     plt.show()  # --- 6. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0433\u0440\u0430\u043d\u0438\u0446 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 def plot_decision_boundary(X_data, y_data, model, title):     x_min, x_max = X[:, 0].min() - 0.5, X[:, 0].max() + 0.5     y_min, y_max = X[:, 1].min() - 0.5, X[:, 1].max() + 0.5     xx, yy = np.meshgrid(np.linspace(x_min, x_max, 300),                          np.linspace(y_min, y_max, 300))     grid = np.c_[xx.ravel(), yy.ravel()]     Z = model.predict(grid).reshape(xx.shape)      plt.figure(figsize=(8, 6))     plt.contourf(xx, yy, Z, alpha=0.3, cmap='Accent')     plt.contour(xx, yy, Z, levels=np.arange(0, 4), colors='k', linewidths=0.5)     for label in np.unique(y_train):         plt.scatter(X_data[y_data == label, 0], X_data[y_data == label, 1],label=class_names[label], s=40)     plt.xlabel(feature_names[0])     plt.ylabel(feature_names[1])     plt.title(title)     plt.legend()     plt.grid(True)     plt.tight_layout()     plt.show()  # train plot_kde_and_gaussian_densities(X_train, y_train) plot_decision_boundary(X_train, y_train, model_kde, \"\u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u0411\u0430\u0439\u0435\u0441 \u0441 KDE\") plot_decision_boundary(X_train, y_train, model_gnb, \"GaussianNB (\u0413\u0430\u0443\u0441\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u0411\u0430\u0439\u0435\u0441)\") # test plot_kde_and_gaussian_densities(X_test, y_test) plot_decision_boundary(X_test, y_test, model_kde, \"\u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u0411\u0430\u0439\u0435\u0441 \u0441 KDE\") plot_decision_boundary(X_test, y_test, model_gnb, \"GaussianNB (\u0413\u0430\u0443\u0441\u0441\u043e\u0432\u0441\u043a\u0438\u0439 \u041d\u0430\u0438\u0432\u043d\u044b\u0439 \u0411\u0430\u0439\u0435\u0441)\") <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/no\/y7\/rj\/noy7rjpv0aqz7yndqbpnuqv_glc.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/no\/y7\/rj\/noy7rjpv0aqz7yndqbpnuqv_glc.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/no\/y7\/rj\/noy7rjpv0aqz7yndqbpnuqv_glc.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/bq\/ft\/4m\/bqft4mkkjaknivd-tuutsnoyxyk.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/bq\/ft\/4m\/bqft4mkkjaknivd-tuutsnoyxyk.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/bq\/ft\/4m\/bqft4mkkjaknivd-tuutsnoyxyk.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/m0\/ah\/rm\/m0ahrm1osk28jaymbzkciijnlw0.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/m0\/ah\/rm\/m0ahrm1osk28jaymbzkciijnlw0.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/m0\/ah\/rm\/m0ahrm1osk28jaymbzkciijnlw0.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/8p\/zd\/zv\/8pzdzvxqx7ix5y1tssouvhh_9xy.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/8p\/zd\/zv\/8pzdzvxqx7ix5y1tssouvhh_9xy.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/8p\/zd\/zv\/8pzdzvxqx7ix5y1tssouvhh_9xy.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/gh\/ba\/mg\/ghbamgqyamlb-ehyxgblzjjxqxk.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/gh\/ba\/mg\/ghbamgqyamlb-ehyxgblzjjxqxk.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/gh\/ba\/mg\/ghbamgqyamlb-ehyxgblzjjxqxk.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/bj\/ey\/be\/bjeybevarucatufitsjix-jy77k.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/bj\/ey\/be\/bjeybevarucatufitsjix-jy77k.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/bj\/ey\/be\/bjeybevarucatufitsjix-jy77k.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h4>5. \u041c\u0435\u0442\u043e\u0434 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439<\/h4>\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>\u041c\u0435\u0442\u043e\u0434 k \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u0441\u043e\u0441\u0435\u0434\u0435\u0439 (k-NN)<\/strong> \u2014 \u044d\u0442\u043e \u043b\u0435\u043d\u0438\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u044f\u0432\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0438 \u0438\u0449\u0435\u0442 <code>k<\/code> \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>\u0433\u043e\u043b\u043e\u0441\u0443\u0435\u0442 \u0437\u0430 \u043a\u043b\u0430\u0441\u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 (\u0438\u043b\u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u0442 \u2014 \u0432 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438).<\/p>\n<\/li>\n<\/ul>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u043c\u0435\u0442\u0440\u0438\u043a\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e\u0439), \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0443 \u0438 \u0448\u0443\u043c\u0443.<\/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>\u041f\u0440\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438:<\/p>\n<pre><code>\u0177(x) = argmax_c \u2211 I(y\u1d62 = c) \u0434\u043b\u044f x\u1d62 \u2208 N_k(x) <\/code><\/pre>\n<p>\u041f\u043b\u044e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f,<\/p>\n<\/li>\n<li>\n<p>\u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0438\u043d\u0443\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f (\u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0451),<\/p>\n<\/li>\n<li>\n<p>\u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0438 \u0448\u0443\u043c\u0443,<\/p>\n<\/li>\n<li>\n<p>\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<p>\u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p><code>k<\/code> \u2014 \u0447\u0438\u0441\u043b\u043e \u0441\u043e\u0441\u0435\u0434\u0435\u0439 (\u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438),<\/p>\n<\/li>\n<li>\n<p><code>metric<\/code> \u2014 \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044f (\u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u043e, \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u0435 \u0438 \u0442.\u0434.)<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439 KNN \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u044b\u043c \u043d\u0430 MNIST<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import numpy as np from sklearn.datasets import load_digits from sklearn.model_selection import train_test_split from sklearn.preprocessing import StandardScaler from sklearn.neighbors import KNeighborsClassifier from sklearn.metrics import accuracy_score from scipy.stats import mode  # --- 1. \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 digits = load_digits() X = digits.data y = digits.target  # \u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 X = StandardScaler().fit_transform(X)  # \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=42)  # --- 2. \u0421\u0432\u043e\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f k-NN (\u0435\u0432\u043a\u043b\u0438\u0434\u043e\u0432\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430) class MyKNN:     def __init__(self, n_neighbors=5):         self.k = n_neighbors      def fit(self, X, y):         self.X_train = X         self.y_train = y      def predict(self, X):         predictions = []         for x in X:             dists = np.linalg.norm(self.X_train - x, axis=1)             nearest = np.argsort(dists)[:self.k]             labels = self.y_train[nearest]             pred = mode(labels, keepdims=False).mode              predictions.append(pred)         return np.array(predictions)  # --- 3. \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 # sklearn sk_knn = KNeighborsClassifier(n_neighbors=5) sk_knn.fit(X_tr, y_tr) y_pred_sk = sk_knn.predict(X_te) acc_sk = accuracy_score(y_te, y_pred_sk)  # \u043d\u0430\u0448 my_knn = MyKNN(n_neighbors=5) my_knn.fit(X_tr, y_tr) y_pred_my = my_knn.predict(X_te) acc_my = accuracy_score(y_te, y_pred_my)  assert np.isclose(acc_sk, acc_my, rtol=1e-6), '\u0422\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0441\u043e\u0432\u043f\u0434\u0430\u044e\u0442!' print(f\"{acc_sk=} {acc_my=}\") # acc_sk=0.9777777777777777 acc_my=0.9777777777777777 <\/code><\/pre>\n<\/div>\n<\/details>\n<h3>\ud83d\udcca \u0413\u043b\u0430\u0432\u0430 2: \u041f\u043e\u0447\u0435\u043c\u0443 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u044f\u043c\u0430\u044f<\/h3>\n<h4>6. \u041b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f. \u0424\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c MSE. \u0410\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0422\u0435\u043e\u0440\u0435\u043c\u0430 \u0413\u0430\u0443\u0441\u0441\u0430-\u041c\u0430\u0440\u043a\u043e\u0432\u0430. \u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438.<\/h4>\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>\u041b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 MSE:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"L(w) = \\|Xw - y\\|^2\" alt=\"L(w) = \\|Xw - y\\|^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/06\/068\/068e4261b2fb3e013dfb549c1f01482a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/06\/068\/068e4261b2fb3e013dfb549c1f01482a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/06\/068\/068e4261b2fb3e013dfb549c1f01482a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<ul>\n<li>\n<p>\u0410\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438: <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{w} = (X^\\top X)^{-1} X^\\top y\" alt=\"\\hat{w} = (X^\\top X)^{-1} X^\\top y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a3\/a31\/a31c5071a916b50be22e580c96237fe0.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a3\/a31\/a31c5071a916b50be22e580c96237fe0.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a3\/a31\/a31c5071a916b50be22e580c96237fe0.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p>\u0422\u0435\u043e\u0440\u0435\u043c\u0430 \u0413\u0430\u0443\u0441\u0441\u0430-\u041c\u0430\u0440\u043a\u043e\u0432\u0430: \u044d\u0442\u043e <strong>\u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0430\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u043d\u0435\u0441\u043c\u0435\u0449\u0451\u043d\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430<\/strong> \u043f\u0440\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445 (BLUE)<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f <strong>\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a<\/strong><\/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<h3>\ud83d\udccc \u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"X \\in \\mathbb{R}^{n \\times d}\" alt=\"X \\in \\mathbb{R}^{n \\times d}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1d7\/1d7d6f0110b728b638b5c9da6f35c217.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1d7\/1d7d6f0110b728b638b5c9da6f35c217.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1d7\/1d7d6f0110b728b638b5c9da6f35c217.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432;<\/p>\n<\/li>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"y \\in \\mathbb{R}^n\" alt=\"y \\in \\mathbb{R}^n\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f6\/f61\/f616f7f7e7e8f1f896bb4f3221b62c62.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f6\/f61\/f616f7f7e7e8f1f896bb4f3221b62c62.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f6\/f61\/f616f7f7e7e8f1f896bb4f3221b62c62.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f;<\/p>\n<\/li>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"w \\in \\mathbb{R}^d\" alt=\"w \\in \\mathbb{R}^d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/27\/27d\/27d2dc20f76850919573d2bf88ad13a4.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/27\/27d\/27d2dc20f76850919573d2bf88ad13a4.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/27\/27d\/27d2dc20f76850919573d2bf88ad13a4.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0426\u0435\u043b\u044c: \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c <strong>\u0441\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443<\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"L(w) = \\|Xw - y\\|^2 = (Xw - y)^\\top (Xw - y)\" alt=\"L(w) = \\|Xw - y\\|^2 = (Xw - y)^\\top (Xw - y)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5d\/a5d031143ab7e7229a2d8cd1e5e53c32.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5d\/a5d031143ab7e7229a2d8cd1e5e53c32.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5d\/a5d031143ab7e7229a2d8cd1e5e53c32.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>\ud83d\udccc \u0412\u044b\u0432\u043e\u0434 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0412\u044b\u043f\u0438\u0448\u0435\u043c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442 \u043f\u043e <img decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 781w\" loading=\"lazy\" decode=\"async\"\/>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\nabla_w L(w) = 2 X^\\top (Xw - y)\" alt=\"\\nabla_w L(w) = 2 X^\\top (Xw - y)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/95\/953\/95362876296038703b4049f01689a968.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/95\/953\/95362876296038703b4049f01689a968.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/95\/953\/95362876296038703b4049f01689a968.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041f\u0440\u0438\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043a \u043d\u0443\u043b\u044e:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"X^\\top (Xw - y) = 0\" alt=\"X^\\top (Xw - y) = 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/91\/918\/918fcfebb2235756e4a7ebb329b06a8a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/91\/918\/918fcfebb2235756e4a7ebb329b06a8a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/91\/918\/918fcfebb2235756e4a7ebb329b06a8a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0420\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043a\u043e\u0431\u043a\u0438:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"X^\\top X w = X^\\top y\" alt=\"X^\\top X w = X^\\top y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5d\/5d4\/5d45540dd004ecd9b2619745ecd9466c.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5d\/5d4\/5d45540dd004ecd9b2619745ecd9466c.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5d\/5d4\/5d45540dd004ecd9b2619745ecd9466c.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044f, \u0447\u0442\u043e <img decoding=\"async\" class=\"formula inline\" source=\"X^\\top X\" alt=\"X^\\top X\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c6\/c63\/c631353afeb2cbc96b7f9edf5c64ec76.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c6\/c63\/c631353afeb2cbc96b7f9edf5c64ec76.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c6\/c63\/c631353afeb2cbc96b7f9edf5c64ec76.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0430:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\hat{w} = (X^\\top X)^{-1} X^\\top y\" alt=\"\\hat{w} = (X^\\top X)^{-1} X^\\top y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a3\/a31\/a31c5071a916b50be22e580c96237fe0.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a3\/a31\/a31c5071a916b50be22e580c96237fe0.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a3\/a31\/a31c5071a916b50be22e580c96237fe0.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<h3>\ud83d\udccc \u0422\u0435\u043e\u0440\u0435\u043c\u0430 \u0413\u0430\u0443\u0441\u0441\u0430-\u041c\u0430\u0440\u043a\u043e\u0432\u0430 (\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430)<\/h3>\n<p>\u0415\u0441\u043b\u0438:<\/p>\n<ol>\n<li>\n<p>\u043c\u043e\u0434\u0435\u043b\u044c \u043b\u0438\u043d\u0435\u0439\u043d\u0430 \u043f\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c: <img decoding=\"async\" class=\"formula inline\" source=\"y = Xw + \\varepsilon\" alt=\"y = Xw + \\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/296\/2964ae7053f53e6fbd4f9d5aafde1e5c.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/296\/2964ae7053f53e6fbd4f9d5aafde1e5c.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/29\/296\/2964ae7053f53e6fbd4f9d5aafde1e5c.svg 781w\" loading=\"lazy\" decode=\"async\"\/>;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0448\u0438\u0431\u043a\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"\\varepsilon\" alt=\"\\varepsilon\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f8\/f8b\/f8b1c5a729a09649c275fca88976d8dd.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f8\/f8b\/f8b1c5a729a09649c275fca88976d8dd.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f8\/f8b\/f8b1c5a729a09649c275fca88976d8dd.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438\u043c\u0435\u044e\u0442 \u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435;<\/p>\n<\/li>\n<li>\n<p>\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u0443\u044e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e <img decoding=\"async\" class=\"formula inline\" source=\"\\text{Var}(\\varepsilon) = \\sigma^2 I\" alt=\"\\text{Var}(\\varepsilon) = \\sigma^2 I\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f7\/f71\/f714b1ec0dc2807df9398088b09ff3f6.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f7\/f71\/f714b1ec0dc2807df9398088b09ff3f6.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f7\/f71\/f714b1ec0dc2807df9398088b09ff3f6.svg 781w\" loading=\"lazy\" decode=\"async\"\/>;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439;<\/p>\n<\/li>\n<\/ol>\n<p>\u2192 \u0442\u043e\u0433\u0434\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{w}\" alt=\"\\hat{w}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg 781w\" loading=\"lazy\" decode=\"async\"\/> (\u0438\u0437 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f) \u2014 <strong>\u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0430\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u043d\u0435\u0441\u043c\u0435\u0449\u0451\u043d\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430 (BLUE)<\/strong>.<\/p>\n<p>\u0422\u0435\u0440\u043c\u0438\u043d <strong>BLUE<\/strong> (Best Linear Unbiased Estimator) \u2014 \u044d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435:<\/p>\n<ol>\n<li>\n<p><strong>Linear (\u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f):<\/strong><br \/> \u041e\u0446\u0435\u043d\u043a\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{w}\" alt=\"\\hat{w}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u044d\u0442\u043e <strong>\u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442 <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\"\/><\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\hat{w} = A y\" alt=\"\\hat{w} = A y\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/834\/834894ab4aeecd65987c86fb0f7c4730.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/834\/834894ab4aeecd65987c86fb0f7c4730.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/83\/834\/834894ab4aeecd65987c86fb0f7c4730.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0433\u0434\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"A = (X^\\top X)^{-1} X^\\top\" alt=\"A = (X^\\top X)^{-1} X^\\top\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/87\/87a\/87ae646111fb3693cd8e3ef17538940e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/87\/87a\/87ae646111fb3693cd8e3ef17538940e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/87\/87a\/87ae646111fb3693cd8e3ef17538940e.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p><strong>Unbiased (\u043d\u0435\u0441\u043c\u0435\u0449\u0451\u043d\u043d\u0430\u044f):<\/strong><br \/> \u0421\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0446\u0435\u043d\u043a\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\mathbb{E}[\\hat{w}] = w\" alt=\"\\mathbb{E}[\\hat{w}] = w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ae\/ae4\/ae4d5c0623aa6c218cc2a1d61c60d29d.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ae\/ae4\/ae4d5c0623aa6c218cc2a1d61c60d29d.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ae\/ae4\/ae4d5c0623aa6c218cc2a1d61c60d29d.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<li>\n<p><strong>Best (\u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0430\u044f):<\/strong><br \/> \u0418\u0437 \u0432\u0441\u0435\u0445 <strong>\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u0438 \u043d\u0435\u0441\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u0445<\/strong> \u043e\u0446\u0435\u043d\u043e\u043a, <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{w}\" alt=\"\\hat{w}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a48\/a4811ce3271ae4eafe259cec9d36d546.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438\u043c\u0435\u0435\u0442 <strong>\u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0443\u044e \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e<\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\text{Var}(\\hat{w}) \\text{ \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u043d\u0435\u0441\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u0445 \u043e\u0446\u0435\u043d\u043e\u043a}\" alt=\"\\text{Var}(\\hat{w}) \\text{ \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u043d\u0435\u0441\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u0445 \u043e\u0446\u0435\u043d\u043e\u043a}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8b\/8b0\/8b01c4209e68ca2088860275dd05f8f6.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8b\/8b0\/8b01c4209e68ca2088860275dd05f8f6.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/8b\/8b0\/8b01c4209e68ca2088860275dd05f8f6.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<\/ol>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0410\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0438 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u0432\u0435\u0441\u043e\u0432 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 + \u0433\u0440\u0430\u0444\u0438\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt from sklearn.datasets import make_regression from sklearn.metrics import mean_squared_error  # --- \u0414\u0430\u043d\u043d\u044b\u0435 X_raw, y = make_regression(n_samples=300, n_features=1, noise=15, random_state=42) X = np.hstack([X_raw, np.ones((X_raw.shape[0], 1))])  # \u0434\u043e\u0431\u0430\u0432\u0438\u043c bias  # --- \u0410\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 w_analytic = np.linalg.inv(X.T @ X) @ X.T @ y y_pred_analytic = X @ w_analytic  # --- \u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a w = np.zeros(X.shape[1]) lr = 0.01 losses = []  for _ in range(1000):     grad = 2 * X.T @ (X @ w - y) \/ len(y)     w -= lr * grad     losses.append(mean_squared_error(y, X @ w))  y_pred_gd = X @ w  # --- \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 print(\"MSE (\u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430):\", mean_squared_error(y, y_pred_analytic)) print(\"MSE (\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442):\", mean_squared_error(y, y_pred_gd))  # --- \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(10, 5))  # 1. \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f plt.subplot(1, 2, 1) plt.scatter(X_raw, y, s=20, alpha=0.6, label='\u0414\u0430\u043d\u043d\u044b\u0435') plt.plot(X_raw, y_pred_analytic, label='\u0410\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435', color='green') plt.plot(X_raw, y_pred_gd, label='\u0413\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u044b\u0439 \u0441\u043f\u0443\u0441\u043a', color='red', linestyle='--') plt.title(\"\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439\") plt.xlabel(\"X\") plt.ylabel(\"y\") plt.legend() plt.grid()  # 2. \u041f\u043e\u0442\u0435\u0440\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 plt.subplot(1, 2, 2) plt.plot(losses, label=\"MSE (\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442)\") plt.title(\"\u0421\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430\") plt.xlabel(\"\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u0438\") plt.ylabel(\"MSE\") plt.grid() plt.tight_layout() plt.show() # MSE (\u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0430): 230.84267462302407 # MSE (\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442): 230.84267462302407 <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/np\/_l\/zn\/np_lzndevu1uekzsd-4lkclz8k4.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/np\/_l\/zn\/np_lzndevu1uekzsd-4lkclz8k4.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/np\/_l\/zn\/np_lzndevu1uekzsd-4lkclz8k4.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h4>7. \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0432 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u044f\u0445: L_1 ,L_2 \u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f.<\/h4>\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>\u0420\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u2014 \u044d\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043a\u0430 \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u043e\u0441\u0442 \u0432\u0435\u0441\u043e\u0432 \u0438 \u0431\u043e\u0440\u0435\u0442\u0441\u044f \u0441 \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c.<\/p>\n<ul>\n<li>\n<p><strong>L2-\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f (Ridge):<\/strong><\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\text{Loss}(w) = \\text{MSE}(w) + \\lambda \\|w\\|_2^2\" alt=\"\\text{Loss}(w) = \\text{MSE}(w) + \\lambda \\|w\\|_2^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/ca\/ca9\/ca96d22acb3535bbf36f7e01fbe8f7fd.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/ca\/ca9\/ca96d22acb3535bbf36f7e01fbe8f7fd.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/ca\/ca9\/ca96d22acb3535bbf36f7e01fbe8f7fd.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<li>\n<p><strong>L1-\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f (Lasso):<\/strong><\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\text{Loss}(w) = \\text{MSE}(w) + \\lambda \\|w\\|_1\" alt=\"\\text{Loss}(w) = \\text{MSE}(w) + \\lambda \\|w\\|_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fa\/fa3\/fa363692aeac796062c44ae0ec84e172.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fa\/fa3\/fa363692aeac796062c44ae0ec84e172.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/fa\/fa3\/fa363692aeac796062c44ae0ec84e172.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<li>\n<p>L2 \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u0435\u0442 \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0432\u0435\u0441\u0430<\/p>\n<\/li>\n<li>\n<p>L1 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0440\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u043c (\u043e\u0431\u043d\u0443\u043b\u044f\u0435\u0442 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\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><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\"\/> &#8212; Ridge, <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\"\/> &#8212; Lasso, Elastic Net &#8212; \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f.<\/p>\n<h3>\ud83d\udccc \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u043d\u0430\u044f \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0442\u043e\u0440\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e <strong>\u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044e \u0430\u043f\u0440\u0438\u043e\u0440\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f<\/strong> \u043d\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 3 \u0432\u043e\u043f\u0440\u043e\u0441\u0435 \u043e MLE):<\/p>\n<ul>\n<li>\n<p><strong>L2 = Gaussian prior:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"P(w) \\sim \\mathcal{N}(0, \\sigma^2 I)\\Rightarrow \\text{MAP} \\propto \\log L(w) - \\lambda \\|w\\|_2^2\" alt=\"P(w) \\sim \\mathcal{N}(0, \\sigma^2 I)\\Rightarrow \\text{MAP} \\propto \\log L(w) - \\lambda \\|w\\|_2^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3a\/3a4\/3a46c1a6d2da811286d040cf6f3511d0.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3a\/3a4\/3a46c1a6d2da811286d040cf6f3511d0.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3a\/3a4\/3a46c1a6d2da811286d040cf6f3511d0.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<li>\n<p><strong>L1 = Laplace prior:<\/strong><\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"P(w) \\sim \\text{Laplace}(0, b)\\Rightarrow \\text{MAP} \\propto \\log L(w) - \\lambda \\|w\\|_1\" alt=\"P(w) \\sim \\text{Laplace}(0, b)\\Rightarrow \\text{MAP} \\propto \\log L(w) - \\lambda \\|w\\|_1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9c7\/9c7f25d021f36dbd3ed3ca1645d3152a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9c7\/9c7f25d021f36dbd3ed3ca1645d3152a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9c7\/9c7f25d021f36dbd3ed3ca1645d3152a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<\/ul>\n<p>\u2192 \u0422\u043e \u0435\u0441\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f = <strong>\u0431\u0430\u0439\u0435\u0441\u043e\u0432\u0441\u043a\u0430\u044f MAP-\u043e\u0446\u0435\u043d\u043a\u0430<\/strong>, \u0435\u0441\u043b\u0438 \u043c\u044b \u0437\u043d\u0430\u0435\u043c prior \u043d\u0430 \u0432\u0435\u0441\u0430.<\/p>\n<hr\/>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u043f\u0440\u0438  \u0437\u0430\u043d\u0443\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0435\u0441\u0430?<\/h3>\n<p>\u041e\u0447\u0435\u043d\u044c \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0438 \u0432\u0430\u0436\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441! \u0418\u0437\u043e\u0431\u0440\u0430\u0437\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0438 \u043f\u043e\u0442\u0435\u0440\u044c \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u043b\u043e\u0441\u0441\u0430!<\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043b\u043e\u0436\u0438\u043c \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u0435. \u041f\u0443\u0441\u0442\u044c <img decoding=\"async\" class=\"formula inline\" source=\"t^*\" alt=\"t^*\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ae\/ae2\/ae25b720797349452f3f62982e4575a6.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ae\/ae2\/ae25b720797349452f3f62982e4575a6.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/ae\/ae2\/ae25b720797349452f3f62982e4575a6.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043e\u043f\u0438\u0442\u0438\u043c\u0443\u043c \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0438 \u043e\u043d \u043d\u0435 \u043d\u0430 \u043e\u0441\u044f\u0445 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442. \u0418\u0437-\u0437\u0430 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0441\u0442\u0438 \u0434\u0432\u0443\u0445 \u0444\u0438\u0433\u0443\u0440, \u043d\u0430\u0439\u0434\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0438, \u0430 \u043f\u043e \u043d\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0443\u0436\u0435 \u043f\u043e\u0434\u043d\u044f\u0442\u044c\u0441\u044f \u0432\u0432\u0435\u0440\u0445, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0432 \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u043e <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\"\/> \u0438 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c MSE ! \u0412\u0442\u043e\u0440\u043e\u0439 <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/linear-models\" rel=\"noopener noreferrer nofollow\">\u0437\u0430\u0443\u043c\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442<\/a> .<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/n3\/s1\/zd\/n3s1zdjbh-h-2f_4iaatoxihckg.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/n3\/s1\/zd\/n3s1zdjbh-h-2f_4iaatoxihckg.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/n3\/s1\/zd\/n3s1zdjbh-h-2f_4iaatoxihckg.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 2-\u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430: \u0434\u0432\u0435 \u0444\u0438\u0433\u0443\u0440\u044b \u0432\u044b\u043f\u0443\u043a\u043b\u044b\u0435 \u0438 \u0438\u043c\u0435\u044e\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043a\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e (\u043f\u043e\u043c\u0438\u043c\u043e <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\"\/> \u0432 \u0442\u043e\u0447\u043a\u0430\u0445 \u043d\u0430 \u043e\u0441\u044f\u0445!), \u0442\u043e\u0433\u0434\u0430 \u0432 \u0442\u043e\u0447\u043a\u0435 \u043a\u0430\u0441\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e \u043f\u0440\u044f\u043c\u0443\u044e!<\/p>\n<p>\u0410 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u0441\u0438 \u0443 \u044d\u043b\u0438\u043f\u0441\u0430 \u0443 MSE \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c\u0443 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e, \u0430 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 (\u043d\u0430 \u043e\u0434\u043d\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0435=) \u0440\u0430\u0432\u043d\u0430 \u043d\u0443\u043b\u044e!<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ku\/je\/mh\/kujemhp6yrlrxcf7anrnomkhyoo.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ku\/je\/mh\/kujemhp6yrlrxcf7anrnomkhyoo.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ku\/je\/mh\/kujemhp6yrlrxcf7anrnomkhyoo.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 L1 \u0438 L2<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041e\u0431\u0443\u0447\u0438\u043c \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u044c\u043a\u0438 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0440\u0435\u0433\u0443\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 8 \u0438\u0437 10 \u0448\u0443\u043c\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438. \u0412 \u0438\u0434\u0435\u0430\u043b\u0438 \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f(\u0438\u043c\u0435\u0442\u044c \u0432\u0435\u0441 \u043d\u043e\u043b\u044c) \u043e\u0442 \u0432\u0441\u0435\u0445 \u043d\u0435\u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432!<\/p>\n<pre><code class=\"python\"># \u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435: 2 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 + 8 \u0448\u0443\u043c\u043e\u0432\u044b\u0445  from sklearn.linear_model import Ridge, Lasso from sklearn.metrics import mean_squared_error import numpy as np import matplotlib.pyplot as plt  # --- \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b n_samples = 100 n_features = 10 n_informative = 2  # \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 \"\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435\"  # --- \u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 np.random.seed(42) X = np.random.randn(n_samples, n_features) true_coefs = np.zeros(n_features) true_coefs[:n_informative] = [3, -2]  # \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 2 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430 \u0437\u043d\u0430\u0447\u0438\u043c\u044b  # \u0426\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0441 \u0448\u0443\u043c\u043e\u043c y = X @ true_coefs + np.random.normal(0, 1.0, size=n_samples)  # --- \u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 ridge = Ridge(alpha=1.0) lasso = Lasso(alpha=0.1)  ridge.fit(X, y) lasso.fit(X, y)  # --- \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0432\u0435\u0441\u043e\u0432 x_idx = np.arange(n_features) plt.figure(figsize=(10, 4)) plt.stem(x_idx, true_coefs, linefmt=\"gray\", markerfmt=\"go\", basefmt=\" \", label=\"True\") plt.stem(x_idx, ridge.coef_, linefmt=\"b-\", markerfmt=\"bo\", basefmt=\" \", label=\"Ridge\") plt.stem(x_idx, lasso.coef_, linefmt=\"r-\", markerfmt=\"ro\", basefmt=\" \", label=\"Lasso\") plt.xticks(ticks=x_idx) plt.title(\"L1 vs L2: 2 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0448\u0443\u043c\") plt.xlabel(\"\u0418\u043d\u0434\u0435\u043a\u0441 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\") plt.ylabel(\"\u0412\u0435\u0441\") plt.legend() plt.tight_layout() plt.show()  # --- \u041f\u043e\u0434\u0441\u0447\u0451\u0442 \u0437\u0430\u043d\u0443\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u0435\u0441\u043e\u0432 ridge_zeros = np.sum(np.abs(ridge.coef_) &lt; 1e-4) lasso_zeros = np.sum(np.abs(lasso.coef_) &lt; 1e-4) print(f\"{ridge_zeros=}, f{lasso_zeros=}\") # ridge_zeros=np.int64(0), flasso_zeros=np.int64(5) <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/63\/xj\/z_\/63xjz_rqarrjlkl79nsmpp2_mzi.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/63\/xj\/z_\/63xjz_rqarrjlkl79nsmpp2_mzi.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/63\/xj\/z_\/63xjz_rqarrjlkl79nsmpp2_mzi.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h4>8. \u041b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f. \u042d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 MLE \u0438 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u043e\u0442\u0435\u0440\u044c.<\/h4>\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>\u041b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/strong> \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0430\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"y = 1\" alt=\"y = 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5a\/5a6\/5a6fb152b0e79d61bb16fd58014ba123.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5a\/5a6\/5a6fb152b0e79d61bb16fd58014ba123.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5a\/5a6\/5a6fb152b0e79d61bb16fd58014ba123.svg 781w\" loading=\"lazy\" decode=\"async\"\/>:<\/p>\n<pre><code>P(y = 1 | x) = \\sigma(x^\\top w), \\quad \\sigma(z) = \\frac{1}{1 + e^{-z}} <\/code><\/pre>\n<p>MLE: \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0430 \u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u044f \u21d4  \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f log-loss (\u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438) = cross-entropy-loss (\u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043b\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438)<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\log L(w) = \\sum_i y_i \\log p_i + (1 - y_i) \\log(1 - p_i)\" alt=\"\\log L(w) = \\sum_i y_i \\log p_i + (1 - y_i) \\log(1 - p_i)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9cf\/9cf77e19d150acb79d792ad2a7f263b5.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9cf\/9cf77e19d150acb79d792ad2a7f263b5.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9c\/9cf\/9cf77e19d150acb79d792ad2a7f263b5.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0438\u043b\u0438<\/p>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"\\mathcal{L}(W) = - \\sum_{i=1}^{n} \\sum_{k=1}^{K} p_{i, k} \\cdot \\log \\hat{p}_{i,k}\" alt=\"\\mathcal{L}(W) = - \\sum_{i=1}^{n} \\sum_{k=1}^{K} p_{i, k} \\cdot \\log \\hat{p}_{i,k}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f9\/f9d\/f9db5cb8e273da2a0fa449bfab0b189f.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f9\/f9d\/f9db5cb8e273da2a0fa449bfab0b189f.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f9\/f9d\/f9db5cb8e273da2a0fa449bfab0b189f.svg 781w\" loading=\"lazy\" decode=\"async\"\/> | \u043e\u0431\u044b\u0447\u043d\u043e, <img decoding=\"async\" class=\"formula inline\" source=\"p_{i_{fix}, k}\" alt=\"p_{i_{fix}, k}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c0\/0c046976101412c4bff4dd3a47a86b79.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c0\/0c046976101412c4bff4dd3a47a86b79.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c0\/0c046976101412c4bff4dd3a47a86b79.svg 781w\" loading=\"lazy\" decode=\"async\"\/> &#8212; \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0430 1 \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0443\u043b\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<h3>\ud83d\udccc \u0412\u044b\u0432\u043e\u0434: MLE \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438<\/h3>\n<p>\u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c:<\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"y_i \\in \\{0, 1\\}\" alt=\"y_i \\in \\{0, 1\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4dc\/4dc340bfe8cf14595da5e1b26774f45c.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4dc\/4dc340bfe8cf14595da5e1b26774f45c.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4dc\/4dc340bfe8cf14595da5e1b26774f45c.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"p_i = \\sigma(x_i^\\top w)\" alt=\"p_i = \\sigma(x_i^\\top w)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/98\/985\/985c3eac395eafa4b9ec1eb76afb9eb3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/98\/985\/985c3eac395eafa4b9ec1eb76afb9eb3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/98\/985\/985c3eac395eafa4b9ec1eb76afb9eb3.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u0438\u0435:<\/p>\n<pre><code>L(w) = \\prod_i p_i^{y_i} (1 - p_i)^{1 - y_i} <\/code><\/pre>\n<p>\u041b\u043e\u0433\u0430\u0440\u0438\u0444\u043c\u0438\u0440\u0443\u0435\u043c:<\/p>\n<pre><code>\\log L(w) = \\sum_i y_i \\log p_i + (1 - y_i) \\log(1 - p_i) <\/code><\/pre>\n<p>\u041f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c <img decoding=\"async\" class=\"formula inline\" source=\"p_i = \\sigma(x_i^\\top w)\" alt=\"p_i = \\sigma(x_i^\\top w)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/98\/985\/985c3eac395eafa4b9ec1eb76afb9eb3.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/98\/985\/985c3eac395eafa4b9ec1eb76afb9eb3.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/98\/985\/985c3eac395eafa4b9ec1eb76afb9eb3.svg 781w\" loading=\"lazy\" decode=\"async\"\/>:<\/p>\n<p>\u0418 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c <strong>\u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0442\u0435\u0440\u044c<\/strong>:<\/p>\n<pre><code>\\mathcal{L}(w) = - \\sum_i \\left[   y_i \\log \\sigma(x_i^\\top w) + (1 - y_i) \\log(1 - \\sigma(x_i^\\top w)) \\right] <\/code><\/pre>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041f\u043e\u0447\u0435\u043c\u0443 \u0441\u044b\u0440\u0430\u044f \u043b\u0438\u043d\u0435\u0439\u043a\u0430 \u043f\u043b\u043e\u0445\u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438? \u0410 \u043b\u043e\u0433-\u0440\u0435\u0433 \u0445\u043e\u0440\u043e\u0448? <\/summary>\n<div class=\"spoiler__content\">\n<p>\u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043b\u043e\u0433-\u0440\u0435\u0433 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438, \u0447\u0435\u043c \u043b\u0438\u043d\u0435\u0439\u043a\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0445\u0432\u0430\u0441\u0442\u0430\u0442\u044c\u0441\u044f. \u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0430\u043a\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0430 \u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c!<\/p>\n<p>\u041d\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043e SVM, \u0438 \u0443\u0432\u0438\u0434\u0438\u043c \u0447\u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u0432\u044b\u0445\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u0434\u0438\u0430\u043f\u043e\u0437\u043e\u043d <img decoding=\"async\" class=\"formula inline\" source=\"[0, 1]\" alt=\"[0, 1]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/26\/264\/264884439b70ab09a86bc848421c6de6.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/26\/264\/264884439b70ab09a86bc848421c6de6.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/26\/264\/264884439b70ab09a86bc848421c6de6.svg 781w\" loading=\"lazy\" decode=\"async\"\/> !<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0438\u043c\u0435\u0440: \u043a\u043b\u0430\u0441\u0441 0 \u0441\u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u043a\u043b\u0430\u0441\u0441 1 \u2014 \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0442\u044f\u043d\u0443\u0442 \u0432\u043f\u0440\u0430\u0432\u043e  # \u041a\u043b\u0430\u0441\u0441 0 \u2014 50 \u0442\u043e\u0447\u0435\u043a \u043e\u043a\u043e\u043b\u043e x = 0 X0 = np.random.normal(loc=0, scale=0.5, size=(50, 1)) y0 = np.zeros(50)  # \u041a\u043b\u0430\u0441\u0441 1 \u2014 50 \u0442\u043e\u0447\u0435\u043a \u0441 \u0440\u0430\u0441\u0442\u0443\u0449\u0438\u043c x (\u043e\u0442 10 \u0434\u043e 500) # X1 = np.linspace(5, 25, 10).reshape(-1, 1) X1 = np.linspace(10, 500, 10).reshape(-1, 1) y1 = np.ones(10)  # \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c X_all = np.vstack([X0, X1]) y_all = np.concatenate([y0, y1])  # \u041e\u0431\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0438 linreg = LinearRegression().fit(X_all, y_all) logreg = LogisticRegression().fit(X_all, y_all)  # \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 \u0441\u0435\u0442\u043a\u0435 x_grid = np.linspace(-2, 30, 500).reshape(-1, 1) lin_preds = linreg.predict(x_grid) log_probs = logreg.predict_proba(x_grid)[:, 1]  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f plt.figure(figsize=(10, 5)) plt.scatter(X0, y0, color='blue', label='\u041a\u043b\u0430\u0441\u0441 0 (\u0441\u043a\u0443\u0447\u0435\u043d\u043d\u044b\u0439)', alpha=0.7) plt.scatter(X1, y1, color='orange', label='\u041a\u043b\u0430\u0441\u0441 1 (\u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439)', alpha=0.9) plt.plot(x_grid, lin_preds, color='green', linestyle='--', label='Linear Regression') plt.plot(x_grid, log_probs, color='black', label='Logistic Regression') plt.xlabel(\"x\") plt.ylabel(\"\u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \/ \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u044c\") plt.title(\"\u041b\u0438\u043d\u0435\u0439\u043d\u0430\u044f vs \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f \u043f\u0440\u0438 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 1\") plt.ylim(-0.1, 1.1) 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\/hl\/g8\/ge\/hlg8gewlhlh9hwovugalwmgkuma.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/hl\/g8\/ge\/hlg8gewlhlh9hwovugalwmgkuma.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/hl\/g8\/ge\/hlg8gewlhlh9hwovugalwmgkuma.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<h4>9. \u041c\u043d\u043e\u0433\u043e\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f. \u041e\u0434\u0438\u043d-\u043f\u0440\u043e\u0442\u0438\u0432-\u043e\u0434\u043d\u043e\u0433\u043e, \u043e\u0434\u0438\u043d-\u043f\u0440\u043e\u0442\u0438\u0432-\u0432\u0441\u0435\u0445, \u0438\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430.<\/h4>\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<ul>\n<li>\n<p><strong>One-vs-Rest (OvR)<\/strong>: \u043e\u0431\u0443\u0447\u0430\u0435\u043c <img decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u00ab\u043a\u043b\u0430\u0441\u0441 vs \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435\u00bb, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u043c\u0430\u043a\u0441. \u043e\u0442\u043a\u043b\u0438\u043a\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p><strong>One-vs-One (OvO)<\/strong>: \u043e\u0431\u0443\u0447\u0430\u0435\u043c <img decoding=\"async\" class=\"formula inline\" source=\"\\frac{K(K-1)}{2}\" alt=\"\\frac{K(K-1)}{2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c9\/0c97ac7c2c3255227b4565c72a3e328e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c9\/0c97ac7c2c3255227b4565c72a3e328e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c9\/0c97ac7c2c3255227b4565c72a3e328e.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043f\u043e \u043f\u0430\u0440\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u2014 \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0443 \u0433\u043e\u043b\u043e\u0441\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<ol>\n<li>\n<p>\u041f\u0440\u0438 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0438 \u0438\u043d\u0444\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0432\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438!<\/p>\n<\/li>\n<li>\n<p>\u0412 One-vs-One \u043d\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043b\u0438\u0448\u044c \u0444\u0430\u043a\u0442 \u043f\u043e\u0431\u0435\u0434\u044b.<\/p>\n<\/li>\n<\/ol>\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<h3>\ud83d\udccc One-vs-Rest (OvR)<\/h3>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p><img decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 <img decoding=\"async\" class=\"formula inline\" source=\"f_k(x)\" alt=\"f_k(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2f\/2fd\/2fd2d8b9444762a6e12096c20301f6ab.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2f\/2fd\/2fd2d8b9444762a6e12096c20301f6ab.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/2f\/2fd\/2fd2d8b9444762a6e12096c20301f6ab.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u043a\u0430\u0436\u0434\u0430\u044f \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442 \u043a\u043b\u0430\u0441\u0441 <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\"\/> \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p>\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u043e\u0442\u043a\u043b\u0438\u043a\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"f_0(x), f_1(x), \\dots, f_{K-1}(x)\" alt=\"f_0(x), f_1(x), \\dots, f_{K-1}(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7f\/7ff\/7ffc40ab1572cfe1d9515a05b03f2fde.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7f\/7ff\/7ffc40ab1572cfe1d9515a05b03f2fde.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/7f\/7ff\/7ffc40ab1572cfe1d9515a05b03f2fde.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0441 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\hat{y} = \\arg\\max_k f_k(x)\" alt=\"\\hat{y} = \\arg\\max_k f_k(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/dd\/dd8\/dd87fc9e0fa6ff160e465ce7ac58bcad.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/dd\/dd8\/dd87fc9e0fa6ff160e465ce7ac58bcad.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d\/dd\/dd8\/dd87fc9e0fa6ff160e465ce7ac58bcad.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u044b\u0434\u0430\u0451\u0442 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"P(y = k \\mid x)\" alt=\"P(y = k \\mid x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1d3\/1d38391e2042b606f7750abeacafde91.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1d3\/1d38391e2042b606f7750abeacafde91.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/1d\/1d3\/1d38391e2042b606f7750abeacafde91.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e \u043d\u0438\u043c.<\/p>\n<h3>\ud83d\udccc One-vs-One (OvO)<\/h3>\n<p>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p>\u0421\u0442\u0440\u043e\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u0430\u0440 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"f_{i,j}(x) \\text{ \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 } i \\text{ \u0438 } j\" alt=\"f_{i,j}(x) \\text{ \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 } i \\text{ \u0438 } j\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/76c\/76cf7a3a33dca079154b2180c4278bd9.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/76c\/76cf7a3a33dca079154b2180c4278bd9.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7\/76\/76c\/76cf7a3a33dca079154b2180c4278bd9.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0412\u0441\u0435\u0433\u043e <img decoding=\"async\" class=\"formula inline\" source=\"\\frac{K(K-1)}{2}\" alt=\"\\frac{K(K-1)}{2}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c9\/0c97ac7c2c3255227b4565c72a3e328e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c9\/0c97ac7c2c3255227b4565c72a3e328e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/0c\/0c9\/0c97ac7c2c3255227b4565c72a3e328e.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435:<\/p>\n<ul>\n<li>\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0433\u043e\u043b\u043e\u0441\u0443\u0435\u0442: <img decoding=\"async\" class=\"formula inline\" source=\"f_{i,j}(x) \\in \\{i, j\\}\" alt=\"f_{i,j}(x) \\in \\{i, j\\}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bb\/bb1\/bb1c82492842acf56a605cb786f582de.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bb\/bb1\/bb1c82492842acf56a605cb786f582de.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bb\/bb1\/bb1c82492842acf56a605cb786f582de.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/li>\n<li>\n<p>\u0421\u0447\u0438\u0442\u0430\u0435\u043c \u0447\u0438\u0441\u043b\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0437\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u043a\u043b\u0430\u0441\u0441<\/p>\n<\/li>\n<li>\n<p>\u0418\u0442\u043e\u0433:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\hat{y} = \\arg\\max_k \\text{(\u043a\u043e\u043b-\u0432\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0437\u0430 } k)\" alt=\"\\hat{y} = \\arg\\max_k \\text{(\u043a\u043e\u043b-\u0432\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0437\u0430 } k)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/21\/21b\/21b53c21ca58a83c6d5c42d9121b1f16.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/21\/21b\/21b53c21ca58a83c6d5c42d9121b1f16.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/2\/21\/21b\/21b53c21ca58a83c6d5c42d9121b1f16.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<\/ul>\n<p>\u0413\u043e\u043b\u043e\u0441\u0430 \u2014 \u0434\u0438\u0441\u043a\u0440\u0435\u0442\u043d\u044b\u0435, \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 One-vs-Rest \u0438 One-vs-One \u043d\u0430 Iris<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from sklearn.datasets import load_iris from sklearn.linear_model import LogisticRegression from sklearn.multiclass import OneVsRestClassifier, OneVsOneClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score, confusion_matrix import numpy as np import pandas as pd from IPython.display import display  # --- 1. \u0414\u0430\u043d\u043d\u044b\u0435 X, y = load_iris(return_X_y=True) X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=0)  # --- 2. \u041c\u043e\u0434\u0435\u043b\u044c base_model = LogisticRegression(max_iter=1000)  # --- 3. One-vs-Rest (OvR) clf_ovr = OneVsRestClassifier(base_model).fit(X_tr, y_tr) y_pred_ovr = clf_ovr.predict(X_te)  # --- 4. One-vs-One (OvO) clf_ovo = OneVsOneClassifier(base_model).fit(X_tr, y_tr) y_pred_ovo = clf_ovo.predict(X_te)  # --- 5. Confusion matrices cm_ovr = confusion_matrix(y_te, y_pred_ovr) cm_ovo = confusion_matrix(y_te, y_pred_ovo)  print(\"Confusion Matrix (OvR):\") print(cm_ovr)  print(\"\\nConfusion Matrix (OvO):\") print(cm_ovo)  # --- 6. \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0434\u043b\u044f OvR ovr_split = pd.DataFrame({     '\u041a\u043b\u0430\u0441\u0441': list(range(len(clf_ovr.estimators_))),     '\u041f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445': [(y_tr == k).sum() for k in range(len(clf_ovr.estimators_))],     '\u041e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445': [(y_tr != k).sum() for k in range(len(clf_ovr.estimators_))],     '\u0412\u0441\u0435\u0433\u043e': [len(y_tr)] * len(clf_ovr.estimators_) })  print(\"\\nOvR \u2014 \u0440\u0430\u0437\u0431\u0438\u0432\u043a\u0430 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c:\") display(ovr_split)  # --- 7. \u0420\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0434\u043b\u044f OvO ovo_pairs = [(est.classes_[0], est.classes_[1]) for est in clf_ovo.estimators_]  ovo_data = [] for a, b in ovo_pairs:     count_a = np.sum(y_tr == a)     count_b = np.sum(y_tr == b)     total = count_a + count_b     ovo_data.append({         '\u041f\u0430\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u043e\u0432': f\"{a} vs {b}\",         f\"#{a}\": count_a,         f\"#{b}\": count_b,         '\u0421\u0443\u043c\u043c\u0430\u0440\u043d\u043e': total     })  ovo_split = pd.DataFrame(ovo_data)  print(\"\\nOvO \u2014 \u0440\u0430\u0437\u0431\u0438\u0432\u043a\u0430 \u043f\u043e \u043f\u0430\u0440\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432:\") display(ovo_split)  # --- 8. Accuracy summary print(f\"\\nOvR Accuracy: {accuracy_score(y_te, y_pred_ovr):.3f}\") print(f\"OvO Accuracy: {accuracy_score(y_te, y_pred_ovo):.3f}\")  <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/cw\/mk\/gp\/cwmkgpphwymeeokdk1hdorades0.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/cw\/mk\/gp\/cwmkgpphwymeeokdk1hdorades0.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/cw\/mk\/gp\/cwmkgpphwymeeokdk1hdorades0.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0412\u0438\u0434\u043d\u043e \u0447\u0442\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e <s>\u0445\u043e\u0440\u043e\u0448\u0438\u0439<\/s> \u0438\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u044b\u0439, \u0442\u0443\u0442 \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0445\u043e\u0440\u043e\u0448\u043e \u0438 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0432\u0441\u0435 \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e (\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0435\u043c\u043d\u043e\u0433\u043e).<\/p>\n<\/div>\n<\/details>\n<h4>10. \u041c\u0435\u0442\u043e\u0434 \u043e\u043f\u043e\u0440\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432. \u0417\u0430\u0434\u0430\u0447\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0434\u043b\u044f SVM. \u0422\u0440\u044e\u043a \u0441 \u044f\u0434\u0440\u043e\u043c. \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u044f\u0434\u0440\u0430.<\/h4>\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>SVM (support vector machine)<\/strong> \u2014 \u044d\u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (&#171;\u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f&#187;), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0449\u0435\u0442 <strong>\u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c<\/strong>, \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e <strong>\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e \u043a\u043b\u0430\u0441\u0441\u044b \u0441 \u0437\u0430\u0437\u043e\u0440\u043e\u043c<\/strong> (margin).<\/p>\n<p>\u041e\u043d \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 <strong>\u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0442\u0441\u0442\u0443\u043f\u0430<\/strong>, \u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0435\u043b\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b:<\/p>\n<ul>\n<li>\n<p>\u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043b\u0435\u0436\u0430\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u044b (\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u044f\u0434\u0440\u043e\u043c, \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e &lt;<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\"\/>, <img decoding=\"async\" class=\"formula inline\" source=\"\\hat{y}\" alt=\"\\hat{y}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5d\/5d2\/5d28a7ba1a44a73b8c2ed21321697c59.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5d\/5d2\/5d28a7ba1a44a73b8c2ed21321697c59.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/5\/5d\/5d2\/5d28a7ba1a44a73b8c2ed21321697c59.svg 781w\" loading=\"lazy\" decode=\"async\"\/>&gt;)<\/p>\n<\/li>\n<li>\n<p>\u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u043b\u0438\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u043e\u0442\u0441\u0442\u0443\u043f\u0430 (\u0447\u0435\u0440\u0435\u0437 \u043c\u044f\u0433\u043a\u0438\u0435 \u0448\u0442\u0440\u0430\u0444\u044b) (\u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0437\u043e\u0440\u0430=\u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b 1 &#8212; M).<\/p>\n<\/li>\n<li>\n<p>\u044f\u0434\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0431\u0440\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 &#8212; \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0435<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c (hinge-loss)<\/strong> \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b:<\/p>\n<ul>\n<li>\n<p>\u043d\u0435 \u0448\u0442\u0440\u0430\u0444\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441 \u043e\u0442\u0441\u0442\u0443\u043f\u043e\u043c <img decoding=\"async\" class=\"formula inline\" source=\"\\ge 1\" alt=\"\\ge 1\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4da\/4da9f150e9fd49343f3abe2868f9db55.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4da\/4da9f150e9fd49343f3abe2868f9db55.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4da\/4da9f150e9fd49343f3abe2868f9db55.svg 781w\" loading=\"lazy\" decode=\"async\"\/>,<\/p>\n<\/li>\n<li>\n<p>\u0438 <strong>\u043d\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c<\/strong> \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u00ab\u043b\u0435\u0437\u0443\u0442\u00bb \u0432 \u0431\u0443\u0444\u0435\u0440\u043d\u0443\u044e \u0437\u043e\u043d\u0443 \u0438\u043b\u0438 \u043e\u0448\u0438\u0431\u0430\u044e\u0442\u0441\u044f (=\u043b\u0438\u0431\u043e \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0435, \u043b\u0438\u0431\u043e \u043d\u0435\u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435!):<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\mathcal{L}(w) = \\frac{1}{n} \\sum \\max(0, 1 - y_i (w^\\top x_i + b)) + \\frac{\\lambda}{2} \\|w\\|^2\" alt=\"\\mathcal{L}(w) = \\frac{1}{n} \\sum \\max(0, 1 - y_i (w^\\top x_i + b)) + \\frac{\\lambda}{2} \\|w\\|^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4db\/4db7b19f5932851ff8963db70dc9bf39.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4db\/4db7b19f5932851ff8963db70dc9bf39.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/4d\/4db\/4db7b19f5932851ff8963db70dc9bf39.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<blockquote>\n<p>\u0427\u0435\u043c, \u0436\u0435 \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0435 \u0447\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438? \u0410 \u0442\u0435\u043c, \u0447\u0442\u043e SVM \u0440\u0435\u0448\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0430 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0438\u044f \u0441\u0442\u0430\u0440\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u043d\u0438\u0445!<\/p>\n<\/blockquote>\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<h3>\ud83d\udccc \u041c\u043e\u0434\u0435\u043b\u044c<\/h3>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\hat{y}(x) = \\text{sign}(w^\\top x + b)\" alt=\"\\hat{y}(x) = \\text{sign}(w^\\top x + b)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/be\/be6\/be6f983337122928af2936a4d8ed17f1.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/be\/be6\/be6f983337122928af2936a4d8ed17f1.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/be\/be6\/be6f983337122928af2936a4d8ed17f1.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u041e\u0442\u0441\u0442\u0443\u043f (margin):<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"M_i = y_i (w^\\top x_i + b)\" alt=\"M_i = y_i (w^\\top x_i + b)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/13\/133\/1334df33d9866fd20fa0b402dabbbf0a.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/13\/133\/1334df33d9866fd20fa0b402dabbbf0a.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/13\/133\/1334df33d9866fd20fa0b402dabbbf0a.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 <img decoding=\"async\" class=\"formula inline\" source=\"M_i\" alt=\"M_i\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/cf\/cf0\/cf02c22fc164faf4976cae168d7d73bd.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/cf\/cf0\/cf02c22fc164faf4976cae168d7d73bd.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/cf\/cf0\/cf02c22fc164faf4976cae168d7d73bd.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0442\u0435\u043c \u0432\u044b\u0448\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<hr\/>\n<h3>\ud83d\udccc \u0426\u0435\u043b\u0435\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (hinge loss)<\/h3>\n<p>SVM \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\mathcal{L}(w) = \\frac{1}{n} \\sum_{i=1}^n \\max(0, 1 - y_i(w^\\top x_i + b)) + \\frac{\\lambda}{2} \\|w\\|^2\" alt=\"\\mathcal{L}(w) = \\frac{1}{n} \\sum_{i=1}^n \\max(0, 1 - y_i(w^\\top x_i + b)) + \\frac{\\lambda}{2} \\|w\\|^2\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f7\/f7d\/f7d6f3cc42cd0c85b6f6e80c2f33cf81.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f7\/f7d\/f7d6f3cc42cd0c85b6f6e80c2f33cf81.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f7\/f7d\/f7d6f3cc42cd0c85b6f6e80c2f33cf81.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<ul>\n<li>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0447\u043b\u0435\u043d \u2014 \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043c\u0430\u043b\u044b\u0439 \u043e\u0442\u0441\u0442\u0443\u043f (\u043e\u0448\u0438\u0431\u043a\u0438 \u0438\u043b\u0438 \u00ab\u043f\u043e\u0447\u0442\u0438 \u043e\u0448\u0438\u0431\u043a\u0438\u00bb)<\/p>\n<\/li>\n<li>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u2014 <strong>\u0440\u0435\u0433\u0443\u043b\u044f\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/strong> (\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u0437\u0430 \u043d\u043e\u0440\u043c\u043e\u0439 <img decoding=\"async\" class=\"formula inline\" source=\"w\" alt=\"w\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f1\/f12\/f1290186a5d0b1ceab27f4e77c0c5d68.svg 781w\" loading=\"lazy\" decode=\"async\"\/>)<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\ud83d\udccc \u042f\u0434\u0440\u043e\u0432\u043e\u0439 \u0442\u0440\u044e\u043a (kernel trick)<\/h3>\n<p>\u0412\u043c\u0435\u0441\u0442\u043e \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0433\u043e <img decoding=\"async\" class=\"formula inline\" source=\"x \\cdot x'\" alt=\"x \\cdot x'\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/869\/8695f5a31aaf29d201747baceda79cb1.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/869\/8695f5a31aaf29d201747baceda79cb1.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8\/86\/869\/8695f5a31aaf29d201747baceda79cb1.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"K(x, x') = \\langle \\phi(x), \\phi(x') \\rangle\" alt=\"K(x, x') = \\langle \\phi(x), \\phi(x') \\rangle\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a09e257cea049045c0973eb75f4b461f.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a09e257cea049045c0973eb75f4b461f.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a09e257cea049045c0973eb75f4b461f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u2192 \u041d\u0435 \u043d\u0443\u0436\u043d\u043e \u044f\u0432\u043d\u043e \u0441\u0442\u0440\u043e\u0438\u0442\u044c <img decoding=\"async\" class=\"formula inline\" source=\"\\phi(x)\" alt=\"\\phi(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/163\/163cde00287e629f33dae509a8414505.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/163\/163cde00287e629f33dae509a8414505.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/163\/163cde00287e629f33dae509a8414505.svg 781w\" loading=\"lazy\" decode=\"async\"\/>, \u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <strong>\u043d\u0435\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439<\/strong>.<\/p>\n<hr\/>\n<h3>\ud83d\udccc \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u044f\u0434\u0435\u0440<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u042f\u0434\u0440\u043e<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0424\u043e\u0440\u043c\u0443\u043b\u0430<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041b\u0438\u043d\u0435\u0439\u043d\u043e\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K(x, x') = x^\\top x'\" alt=\"K(x, x') = x^\\top x'\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c4\/c4a\/c4a5337c8159c7b9b470d3596c3ad70b.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c4\/c4a\/c4a5337c8159c7b9b470d3596c3ad70b.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c\/c4\/c4a\/c4a5337c8159c7b9b470d3596c3ad70b.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u043e\u043b\u0438\u043d\u043e\u043c\u0438\u0430\u043b\u044c\u043d\u043e\u0435<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K(x, x') = (x^\\top x' + c)^d\" alt=\"K(x, x') = (x^\\top x' + c)^d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a42\/a421e385c5a6c55a98d770f97855839e.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a42\/a421e385c5a6c55a98d770f97855839e.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a4\/a42\/a421e385c5a6c55a98d770f97855839e.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">RBF (\u0413\u0430\u0443\u0441\u0441)<\/p>\n<\/td>\n<td>\n<p align=\"left\"><img decoding=\"async\" class=\"formula inline\" source=\"K(x, x') = \\exp(-\\gamma |x - x'|^2)\" alt=\"K(x, x') = \\exp(-\\gamma |x - x'|^2)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f5\/f53\/f53305dcd8dd05d3eedb4282458272af.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f5\/f53\/f53305dcd8dd05d3eedb4282458272af.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f\/f5\/f53\/f53305dcd8dd05d3eedb4282458272af.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u2705 \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0433\u043e \u044f\u0434\u0440\u0430 (\u044f\u0434\u0440\u043e\u0432\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438)<\/h3>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <img decoding=\"async\" class=\"formula inline\" source=\"K(x, x')\" alt=\"K(x, x')\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/42\/424\/424f6fff61421c23acb8ef2061b9f146.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/42\/424\/424f6fff61421c23acb8ef2061b9f146.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/4\/42\/424\/424f6fff61421c23acb8ef2061b9f146.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e\u0435 <strong>\u044f\u0434\u0440\u043e<\/strong>, \u0435\u0441\u043b\u0438 \u043e\u043d\u043e:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0438\u043c\u043c\u0435\u0442\u0440\u0438\u0447\u043d\u0430<\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"K(x, x') = K(x', x)\" alt=\"K(x, x') = K(x', x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/04\/04f\/04f6030420d650180c9920c19c447265.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/04\/04f\/04f6030420d650180c9920c19c447265.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0\/04\/04f\/04f6030420d650180c9920c19c447265.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/li>\n<li>\n<p><strong>\u041f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0443\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0430\u044f (PSD)<\/strong>:<br \/> \u0414\u043b\u044f \u043b\u044e\u0431\u044b\u0445 <img decoding=\"async\" class=\"formula inline\" source=\"x_1, \\dots, x_n \\in \\mathbb{R}^d\" alt=\"x_1, \\dots, x_n \\in \\mathbb{R}^d\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9e\/9e3\/9e3593a113a420f06a57c4bbd6fead98.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9e\/9e3\/9e3593a113a420f06a57c4bbd6fead98.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9\/9e\/9e3\/9e3593a113a420f06a57c4bbd6fead98.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0438 \u043b\u044e\u0431\u044b\u0445 \u0432\u0435\u0441\u043e\u0432 <img decoding=\"async\" class=\"formula inline\" source=\"\\alpha_1, \\dots, \\alpha_n \\in \\mathbb{R}\" alt=\"\\alpha_1, \\dots, \\alpha_n \\in \\mathbb{R}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bb\/bbc\/bbca2b8beec01bb4c4a2bfb05bf44c01.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bb\/bbc\/bbca2b8beec01bb4c4a2bfb05bf44c01.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b\/bb\/bbc\/bbca2b8beec01bb4c4a2bfb05bf44c01.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"\\sum_{i=1}^n \\sum_{j=1}^n \\alpha_i \\alpha_j K(x_i, x_j) \\ge 0\" alt=\"\\sum_{i=1}^n \\sum_{j=1}^n \\alpha_i \\alpha_j K(x_i, x_j) \\ge 0\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3b\/3b6\/3b60fe6138b8d4af762e9b3424d95957.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3b\/3b6\/3b60fe6138b8d4af762e9b3424d95957.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3\/3b\/3b6\/3b60fe6138b8d4af762e9b3424d95957.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442: \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0413\u0440\u0430\u043c\u0430 <img decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0442\u043e\u0447\u0435\u043a \u2014 <strong>\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043b\u0443\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u0430\u044f<\/strong>.<\/p>\n<\/li>\n<\/ol>\n<h3>\u041f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e?<\/h3>\n<p>\u0415\u0441\u043b\u0438 <img decoding=\"async\" class=\"formula inline\" source=\"K\" alt=\"K\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a5\/a5f\/a5f3c6a11b03839d46af9fb43c97c188.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u2014 \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0435 \u044f\u0434\u0440\u043e, \u0442\u043e \u043f\u043e <strong>\u0442\u0435\u043e\u0440\u0435\u043c\u0435 \u041c\u0435\u0440\u0441\u0435\u0440\u0430<\/strong>:<\/p>\n<p><img decoding=\"async\" class=\"formula\" source=\"K(x, x') = \\langle \\phi(x), \\phi(x') \\rangle\" alt=\"K(x, x') = \\langle \\phi(x), \\phi(x') \\rangle\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a09e257cea049045c0973eb75f4b461f.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a09e257cea049045c0973eb75f4b461f.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a\/a0\/a09\/a09e257cea049045c0973eb75f4b461f.svg 781w\" loading=\"lazy\" decode=\"async\"\/><\/p>\n<p>\u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f <img decoding=\"async\" class=\"formula inline\" source=\"\\phi(\\cdot)\" alt=\"\\phi(\\cdot)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/143\/143c84eda304ce710729dd74d9280351.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/143\/143c84eda304ce710729dd74d9280351.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/14\/143\/143c84eda304ce710729dd74d9280351.svg 781w\" loading=\"lazy\" decode=\"async\"\/> \u0432 (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0435) \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432.<\/p>\n<p>\u2192 \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 SVM \u0441 \u044f\u0434\u0440\u043e\u043c <strong>\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u043c \u0432 \u044d\u0442\u043e\u043c \u0441\u043a\u0440\u044b\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435<\/strong>, \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f <img decoding=\"async\" class=\"formula inline\" source=\"\\phi(x)\" alt=\"\\phi(x)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/163\/163cde00287e629f33dae509a8414505.svg\" width=\"auto\" height=\"auto\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/163\/163cde00287e629f33dae509a8414505.svg 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1\/16\/163\/163cde00287e629f33dae509a8414505.svg 781w\" loading=\"lazy\" decode=\"async\"\/>.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb  \u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u044b\u0445 SVM \u044f\u0434\u0435\u0440: linear vs poly vs RBF<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from sklearn.datasets import make_classification from sklearn.svm import SVC from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score import matplotlib.pyplot as plt import numpy as np  # --- 1. \u0414\u0430\u043d\u043d\u044b\u0435 X, y = make_classification(n_samples=300, n_features=2, n_redundant=0,                            n_clusters_per_class=1, class_sep=1.0, random_state=42) X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=0)  # --- 2. \u041c\u043e\u0434\u0435\u043b\u0438 clf_linear = SVC(kernel='linear', C=1).fit(X_tr, y_tr) clf_rbf = SVC(kernel='rbf', gamma=1, C=1).fit(X_tr, y_tr) clf_poly = SVC(kernel='poly', degree=3, C=1).fit(X_tr, y_tr)   # --- 3. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f def plot_decision_boundary(model, X, y, ax, title):     h = 0.02     x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1     y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1     xx, yy = np.meshgrid(np.arange(x_min, x_max, h),                          np.arange(y_min, y_max, h))     Z = model.predict(np.c_[xx.ravel(), yy.ravel()])     Z = Z.reshape(xx.shape)      ax.contourf(xx, yy, Z, alpha=0.3, cmap=plt.cm.coolwarm)     ax.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm, edgecolors='k')     ax.set_title(title)     ax.set_xlabel(\"x\u2081\")     ax.set_ylabel(\"x\u2082\")     ax.grid(True)  # --- 4. \u0413\u0440\u0430\u0444\u0438\u043a\u0438 fig, axes = plt.subplots(1, 3, figsize=(12, 5)) plot_decision_boundary(clf_linear, X_te, y_te, axes[0], \"\u041b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 SVM\") plot_decision_boundary(clf_poly, X_te, y_te, axes[1], \"\u041f\u043e\u043b\u0438\u043d\u043e\u043c\u0438\u0430\u043b\u044c\u043d\u044b\u0439 3-\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 SVM\") plot_decision_boundary(clf_rbf, X_te, y_te, axes[2], \"RBF SVM\") plt.tight_layout() plt.show()   y_pred_linear = clf_linear.predict(X_te) y_pred_poly = clf_poly.predict(X_te) y_pred_rbf = clf_rbf.predict(X_te)  # Accuracy acc_linear = accuracy_score(y_te, y_pred_linear) acc_poly = accuracy_score(y_te, y_pred_poly) acc_rbf = accuracy_score(y_te, y_pred_rbf) print(f\"Linear SVM Accuracy: {acc_linear:.3f}\") print(f\"Polynomial SVM Accuracy: {acc_poly:.3f}\") print(f\"RBF SVM Accuracy: {acc_rbf:.3f}\") # Linear SVM Accuracy: 0.944 # Polynomial SVM Accuracy: 0.911 # RBF SVM Accuracy: 0.967 <\/code><\/pre>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/3w\/aj\/nr\/3wajnrxv5cgzd8pkhj9ax7ifike.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/3w\/aj\/nr\/3wajnrxv5cgzd8pkhj9ax7ifike.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/3w\/aj\/nr\/3wajnrxv5cgzd8pkhj9ax7ifike.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<\/div>\n<\/details>\n<hr\/>\n<h4>\u0427\u0442\u043e \u0434\u0430\u043b\u044c\u0448\u0435?<\/h4>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ob\/p5\/u9\/obp5u9lxvi00vlu2-sa_-ntdxaw.png\" width=\"600\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ob\/p5\/u9\/obp5u9lxvi00vlu2-sa_-ntdxaw.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ob\/p5\/u9\/obp5u9lxvi00vlu2-sa_-ntdxaw.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0423\u0447\u0438\u043c\u0441\u044f \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u043e\u0432\u0430\u0440\u0438\u0432\u0430\u0435\u043c \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0437. \u0420\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u0440\u0443\u0437\u044c\u044f\u043c, \u043b\u0438\u0431\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0441\u0435\u0431\u0435 \u0438 \u0441\u043b\u0443\u0448\u0430\u0435\u043c.<\/p>\n<p>\u041f\u043e\u043a\u0430 \u0433\u043e\u0442\u043e\u0432\u0438\u043c\u0441\u044f, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u043a\u0430\u0432\u0435\u0440\u0437\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043f\u0440\u043e\u0441\u0442\u043e \u0434\u0430\u0442\u044c \u0432\u0435\u0440\u043d\u044b\u0435\/\u043b\u0435\u0433\u043a\u0438\u0438 \u043e\u0442\u0432\u0435\u0442\u044b. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435, \u043f\u043e\u0442\u043e\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435!<\/p>\n<h4>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/h4>\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 \u0431\u0443\u0434\u0443\u0442 PCA, Bias\u2013variance tradeoff, \u0434\u0435\u0440\u0435\u0432\u044c\u044f, \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u0438, \u0431\u0443\u0441\u0442\u0438\u043d\u0433, \u0438 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. \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\/918438\/\"> https:\/\/habr.com\/ru\/articles\/918438\/<\/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>\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.<\/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<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 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u043b\u043e\u0441\u044c \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<h3>\ud83d\udcda \u0413\u043b\u0430\u0432\u0430 1: \u041c\u043e\u0434\u0435\u043b\u0438, \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0438 \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0411\u0430\u0439\u0435\u0441\u0430<\/h3>\n<h4>0. \u0417\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c. \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f, \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/h4>\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<ul>\n<li>\n<p><strong>\u041e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c<\/strong> \u2014 \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0441\u043d\u0430\u0431\u0436\u0451\u043d \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c , \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0430\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 .<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/strong>: \u0435\u0441\u043b\u0438  (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0446\u0435\u043d\u0430, \u0442\u0435\u043c\u043f\u0435\u0440\u0430\u0442\u0443\u0440\u0430).<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>: \u0435\u0441\u043b\u0438 , \u0442\u043e \u0435\u0441\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u0438\u043b\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0438\u0430\u0433\u043d\u043e\u0437, \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\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<h3>\u041e\u0431\u0449\u0430\u044f \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h3>\n<p>\u0412 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0438\u0437 \u043f\u0430\u0440<\/p>\n<p>\u0433\u0434\u0435  \u2014 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432,  \u2014 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f. \u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c , \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f.<\/p>\n<hr\/>\n<h3>\u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f<\/h3>\n<p>\u0415\u0441\u043b\u0438  \u0438\u043b\u0438 , \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439<\/strong>.<br \/> \u041c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435. \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c:<\/p>\n<ul>\n<li>\n<p>Mean Squared Error (MSE)<\/p>\n<\/li>\n<li>\n<p>Mean Absolute Error (MAE)<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0446\u0435\u043d\u044b \u043d\u0435\u0434\u0432\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u041e\u0446\u0435\u043d\u043a\u0430 \u0441\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0442\u043e\u0432\u0430\u0440<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<h3>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0415\u0441\u043b\u0438  \u2014 \u0437\u0430\u0434\u0430\u0447\u0430 <strong>\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/strong>.<br \/> \u0412 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 <strong>\u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;\u0434\u0430\/\u043d\u0435\u0442&#187;).<br \/> \u041f\u0440\u0438 <\/p>\n<p> \u2014 <strong>\u043c\u043d\u043e\u0433\u043e\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u0430\u044f<\/strong>. \u0422\u0430\u043a\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 <strong>multi-label \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f<\/strong>, \u043a\u043e\u0433\u0434\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u043a. <\/p>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0432\u044b\u0434\u0430\u0435\u0442 \u043b\u0438\u0431\u043e \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c (soft), \u043b\u0438\u0431\u043e \u0441\u0440\u0430\u0437\u0443 \u043c\u0435\u0442\u043a\u0443 (hard). \u0427\u0430\u0441\u0442\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u044e\u0442 logloss \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 surrogate-\u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0440\u0443\u043a\u043e\u043f\u0438\u0441\u043d\u044b\u0445 \u0446\u0438\u0444\u0440 (0\u20139)<\/p>\n<\/li>\n<li>\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f e-mail \u043a\u0430\u043a &#171;\u0441\u043f\u0430\u043c \/ \u043d\u0435 \u0441\u043f\u0430\u043c&#187;<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0438 \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0438\u0438<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0417\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0447\u0443\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u043f\u043e\u043a\u0430\u0436\u0435\u043c, \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0438\u0438 (\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439  \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439) \u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0435\u0439)<\/p>\n<pre><code class=\"python\">from sklearn.linear_model import LinearRegression, LogisticRegression from sklearn.datasets import make_regression, make_classification  # --- \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- X_reg, y_reg = make_regression(n_samples=100, n_features=2, noise=0.1, random_state=43) # [100, 2], [100] reg = LinearRegression().fit(X_reg, y_reg)  # --- \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f --- X_clf, y_clf = make_classification(n_samples=100, n_features=2, n_classes=2, n_redundant=0, random_state=43) # [100, 2], [100] clf = LogisticRegression().fit(X_clf, y_clf) <\/code><\/pre>\n<pre><code class=\"python\">  # --- \u041e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0430 --- import matplotlib.pyplot as plt import numpy as np  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0438\u0433\u0443\u0440\u0443 \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u043e\u0434\u0433\u0440\u0430\u0444\u0438\u043a\u0430\u043c\u0438 fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 5))  # --- \u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0442\u043a\u0443 \u0442\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u043b\u0438\u043d\u0438\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 x_grid = np.linspace(X_reg[:, 0].min(), X_reg[:, 0].max(), 100).reshape(-1, 1) # \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0438\u0437\u043d\u0430\u043a (\u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435) # \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043f\u0440\u0438\u0437\u043d\u0430\u043a \u043c\u043e\u0436\u0435\u043c =&gt; \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u043c\u0443 \u0443\u0441\u0440\u0435\u0434\u043d\u0438\u043c!  # \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u043b\u043e\u0445\u043e! \u043d\u043e \u0434\u043b\u044f \u0438\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 - \u043e\u043a! x_grid_full = np.column_stack([x_grid, np.full_like(x_grid, X_reg[:, 1].mean())]) y_pred = reg.predict(x_grid_full)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438 ax1.scatter(X_reg[:, 0], y_reg, alpha=0.5, label='\u0414\u0430\u043d\u043d\u044b\u0435') ax1.plot(x_grid, y_pred, 'r-', label='\u041b\u0438\u043d\u0438\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438') ax1.set_title('\u0420\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f') ax1.set_xlabel('\u041f\u0440\u0438\u0437\u043d\u0430\u043a 1') ax1.set_ylabel('\u0426\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f') ax1.legend()  # --- \u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f --- # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0435\u0442\u043a\u0443 \u0442\u043e\u0447\u0435\u043a \u0434\u043b\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 x_min, x_max = X_clf[:, 0].min() - 0.5, X_clf[:, 0].max() + 0.5 y_min, y_max = X_clf[:, 1].min() - 0.5, X_clf[:, 1].max() + 0.5 xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.02),                      np.arange(y_min, y_max, 0.02))  # \u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u043e\u0447\u0435\u043a \u0441\u0435\u0442\u043a\u0438 Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) Z = Z.reshape(xx.shape)  # \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 ax2.contourf(xx, yy, Z, alpha=0.3, cmap='viridis') ax2.contour(xx, yy, Z, [0.5], colors='red', linewidths=2)  scatter = ax2.scatter(X_clf[:, 0], X_clf[:, 1], c=y_clf, cmap='viridis', alpha=0.5) ax2.set_title('\u041a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f') ax2.set_xlabel('\u041f\u0440\u0438\u0437\u043d\u0430\u043a 1') ax2.set_ylabel('\u041f\u0440\u0438\u0437\u043d\u0430\u043a 2') ax2.legend(*scatter.legend_elements(), title=\"\u041a\u043b\u0430\u0441\u0441\u044b\")  plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><\/figure>\n<\/div>\n<\/details>\n<h4>1. \u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438: accuracy, balanced accuracy, precision, recall, f1-score, ROC-AUC, \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/h4>\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\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 () \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e \u043d\u0438\u043c \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438:<\/p>\n<figure class=\"\"><\/figure>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041c\u0435\u0442\u0440\u0438\u043a\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0424\u043e\u0440\u043c\u0443\u043b\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0421\u043c\u044b\u0441\u043b<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Accuracy<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>Accuracy = (TP + TN) \/ (TP + TN + FP + FN)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0431\u0449\u0430\u044f \u0434\u043e\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Balanced Accuracy<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>0.5 * (TPR + TNR) = 0.5 * (TP \/ (TP + FN) + TN \/ (TN + FP))<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0441\u0440\u0435\u0434\u043d\u0451\u043d\u043d\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u043f\u0440\u0438 \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Precision<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>TP \/ (TP + FP)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043b\u044f \u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Recall<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>TP \/ (TP + FN)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043b\u044f \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0438 \u0432\u0441\u0435\u0445 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">F1(b)-score<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>2 * P * R \/ (P + R) = 2 \/ (1\/P + 1\/R) = [b=1] = (b^2 + 1) \/ (b^2 r^-1 + r^-1)  <\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0411\u0430\u043b\u0430\u043d\u0441 \u043c\u0435\u0436\u0434\u0443 precision \u0438 recall<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">AUC<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u043e\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440 \u0441\u0440\u0435\u0434\u0438 (Negative, Positive)<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u043b\u043e\u0449\u0430\u0434\u044c \u043f\u043e\u0434 ROC-\u043a\u0440\u0438\u0432\u043e\u0439 (TPR (y) vs FPR (x) \u043f\u0440\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0440\u043e\u0433\u0430\u0445)<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<figure class=\"\"><\/figure>\n<p>\u041b\u0435\u0433\u0447\u0435 \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u043a\u0430\u043a TPR = recall \u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 FPR = 1 &#8212; recall \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 !<\/p>\n<p>\u041a\u0430\u043a \u043f\u043e \u043c\u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u043f\u0435\u0440\u0435\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u043a\u0430 &#8212; \u044d\u0442\u043e \u0434\u043e\u043b\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0445 \u043f\u0430\u0440 \u0441\u0440\u0435\u0434\u0438 (Negative, Positive)<\/p>\n<figure class=\"\"><\/figure>\n<ul>\n<li>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u043b\u043e\u0445\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 &#8212; AUC=0.5 \u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0432\u0435\u0440\u0441\u043d\u0443\u0442\u044c!<\/p>\n<\/li>\n<li>\n<p>\u041b\u0443\u0447\u0448\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 AUC=1<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<p>\u0414\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 &#8212; \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 one-vs-rest \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u043e\u0448\u0438\u0431\u043e\u043a. \u0414\u0430\u043b\u0435\u0435 \u043b\u0438\u0431\u043e \u043c\u0438\u043a\u0440\u043e-\u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u043c (\u0441\u0443\u043c\u043c\u0438\u0440\u0443\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438 \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u043c\u0435\u0442\u0440\u043a\u0443) \u0438\u043b\u0438 \u043c\u0430\u043a\u0440\u043e-\u0443\u0441\u0440\u0435\u0434\u043d\u0435\u043d\u0438\u0435 (\u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0438 \u0443\u0441\u0440\u0435\u0434\u043d\u044f\u0435\u043c)<\/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>\u041e\u0447\u0435\u043d\u044c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u043e <a href=\"https:\/\/education.yandex.ru\/handbook\/ml\/article\/metriki-klassifikacii-i-regressii\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a>!<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0430\u043a \u0436\u0435 \u043d\u0430:<\/p>\n<ul>\n<li>\n<p>Recall@k, Precision@k<\/p>\n<\/li>\n<li>\n<p>Average Precision<\/p>\n<\/li>\n<\/ul>\n<p>\u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 &#8212; \u0442\u0430\u043c \u0438 \u0440\u0430\u0437\u0433\u0443\u043b\u044f\u0435\u043c\u0441\u044f (\u0438\u043d\u0430\u0447\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043a\u0430\u043f\u0430\u0442\u044c\u0441\u044f)!<\/p>\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 AUC ROC<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\"> from sklearn.datasets import make_classification from sklearn.linear_model import LogisticRegression from sklearn.dummy import DummyClassifier from sklearn.model_selection import train_test_split from sklearn.metrics import roc_curve, roc_auc_score import matplotlib.pyplot as plt  # --- 1. \u0421\u0438\u043d\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435, \"\u0433\u0440\u044f\u0437\u043d\u044b\u0435\" \u0434\u0430\u043d\u043d\u044b\u0435 --- X, y = make_classification(     n_samples=1000,     n_features=20,     n_informative=5,     n_redundant=4,     n_classes=2,     weights=[0.75, 0.25],  # \u0434\u0438\u0441\u0431\u0430\u043b\u0430\u043d\u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u0432     flip_y=0.1,            # 10% \u043c\u0435\u0442\u043e\u043a \u0448\u0443\u043c\u043d\u044b\u0435     class_sep=0.8,         # \u043a\u043b\u0430\u0441\u0441\u044b \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f     random_state=42 )  # --- 2. \u0414\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 train\/test --- X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=42)  # --- 3. \u041b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- model = LogisticRegression(max_iter=1000).fit(X_tr, y_tr) y_prob = model.predict_proba(X_te)[:, 1] fpr_model, tpr_model, _ = roc_curve(y_te, y_prob) auc_model = roc_auc_score(y_te, y_prob)  # --- 4. Dummy-\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 (\u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f stratified) --- dummy = DummyClassifier(strategy='stratified', random_state=42).fit(X_tr, y_tr) y_dummy_prob = dummy.predict_proba(X_te)[:, 1] fpr_dummy, tpr_dummy, _ = roc_curve(y_te, y_dummy_prob) auc_dummy = roc_auc_score(y_te, y_dummy_prob)  # --- 5. \u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f ROC-\u043a\u0440\u0438\u0432\u044b\u0445 --- plt.figure(figsize=(8, 6)) plt.plot(fpr_model, tpr_model, label=f\"Logistic Regression (AUC = {auc_model:.2f})\") plt.plot(fpr_dummy, tpr_dummy, linestyle='--', label=f\"Dummy Stratified (AUC = {auc_dummy:.2f})\") plt.plot([0, 1], [0, 1], 'k:', label=\"Random Guess (AUC = 0.50)\")  plt.xlabel(\"False Positive Rate (FPR)\") plt.ylabel(\"True Positive Rate (TPR)\") plt.title(\"ROC-\u043a\u0440\u0438\u0432\u0430\u044f: \u043b\u043e\u0433\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f vs \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\") plt.legend() plt.grid(True) plt.tight_layout() plt.show() <\/code><\/pre>\n<figure class=\"\"><\/figure>\n<\/div>\n<\/details>\n<h4>2. \u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438: MSE, MAE, R\u00b2<\/h4>\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<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041c\u0435\u0442\u0440\u0438\u043a\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0424\u043e\u0440\u043c\u0443\u043b\u0430<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u0421\u043c\u044b\u0441\u043b<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MSE<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>mean((y_true - y_pred) ** 2)<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u0440\u0435\u0434\u043d\u0435\u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430. \u041d\u0430\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441\u0438\u043b\u044c\u043d\u0435\u0435.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">MAE<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>mean(abs(y_true - y_pred))<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430. \u0418\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">R\u00b2 score<\/p>\n<\/td>\n<td>\n<p align=\"left\"><code>1 - MSE_model \/ MSE_const<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043b\u0443\u0447\u0448\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f(=\u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043f\u0440\u0438 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 MSE) . \u041e\u0442 0 \u0434\u043e 1 (\u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c &lt; 0 \u043f\u0440\u0438 \u043f\u043b\u043e\u0445\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438).<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\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><strong>MSE (Mean Squared Error)<\/strong><br \/> \u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0451\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c. \u041e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u0432\u0430\u0434\u0440\u0430\u0442, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u043c\u0435\u0442\u0440\u0438\u043a\u0443 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c.<br \/> <code>MSE = mean((y - \u0177) ** 2)<\/code><\/p>\n<p><strong>MAE (Mean Absolute Error)<\/strong><br \/> \u0410\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e\u0435 \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f\u043c\u0438 \u0438 \u0438\u0441\u0442\u0438\u043d\u043e\u0439. \u041c\u0435\u043d\u0435\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u0430 \u043a \u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c(=\u0440\u043e\u0431\u0430\u0441\u0442\u043d\u0435\u0435), \u0445\u043e\u0440\u043e\u0448\u043e \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f (\u0432 \u0442\u0435\u0445 \u0436\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u0430\u0445, \u0447\u0442\u043e \u0438 \u0446\u0435\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f).<br \/> <code>MAE = mean(|y - \u0177|)<\/code><\/p>\n<p><strong>Huber Loss<\/strong> \u2014 \u0433\u0438\u0431\u0440\u0438\u0434 \u043c\u0435\u0436\u0434\u0443 MSE \u0438 MAE: \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u0439 \u0448\u0442\u0440\u0430\u0444, \u0434\u0430\u043b\u044c\u0448\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439.<\/p>\n<p><strong>R\u00b2 (\u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0434\u0435\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0446\u0438\u0438)<\/strong><br \/> \u041f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u0438 \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c.<br \/> <code>R\u00b2 = 1 - (MSE_model \/ MSE_const)<\/code><br \/> \u0413\u0434\u0435 <code>MSE_const<\/code> \u2014 \u043e\u0448\u0438\u0431\u043a\u0430 \u043d\u0430\u0438\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u043d\u0435\u0435.<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\ud83d\udcbb \u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043e\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score from sklearn.datasets import make_regression from sklearn.linear_model import LinearRegression, HuberRegressor from sklearn.model_selection import train_test_split  # \u0414\u0430\u043d\u043d\u044b\u0435 X, y = make_regression(n_samples=500, noise=15, random_state=42) X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.3, random_state=42)  # --- \u041b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- model_lr = LinearRegression().fit(X_tr, y_tr) y_pred_lr = model_lr.predict(X_te)  print(\"=== Linear Regression ===\") print(\"MSE:\", mean_squared_error(y_te, y_pred_lr)) print(\"MAE:\", mean_absolute_error(y_te, y_pred_lr)) print(\"R\u00b2:\", r2_score(y_te, y_pred_lr))  # --- Huber-\u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044f --- model_huber = HuberRegressor().fit(X_tr, y_tr) y_pred_huber = model_huber.predict(X_te)  print(\"\\n=== Huber Regressor ===\") print(\"MSE:\", mean_squared_error(y_te, y_pred_huber)) print(\"MAE:\",<\/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-463413","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/463413","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=463413"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/463413\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=463413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=463413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=463413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}