{"id":297568,"date":"2020-01-23T15:00:37","date_gmt":"2020-01-23T15:00:37","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297568"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297568","title":{"rendered":"SVM. \u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0441 \u043d\u0443\u043b\u044f, \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/ods\/blog\/484148\/\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0443\u0442\u044c ML-\u0441\u0430\u043c\u0443\u0440\u0430\u044f!<\/p>\n<p>  <\/p>\n<p><b>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/b><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u043e\u0440\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 (<i>\u0430\u043d\u0433\u043b. SVM, Support Vector Machine<\/i>) \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u0411\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0435\u0433\u043e \u0432\u0435\u0441\u043e\u0432 \u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/50c\/036\/e72\/50c036e72210eebc108541ad3d104d37.svg\" alt=\"$Iris$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438\/\u043d\u0435\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0ba\/d21\/a1f\/0bad21a1feb1341dc1267f2bceaaf5f6.svg\" alt=\"$R^2$\" data-tex=\"inline\"><\/math> \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f\/\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u043e\u0437\u0432\u0443\u0447\u0435\u043d\u044b \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0435\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/th\/qo\/am\/thqoam8wiyi5gepkmu86xbx6md0.png\" alt=\"image\"><br \/>  <i>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1. \u0424\u043e\u0442\u043e \u0446\u0432\u0435\u0442\u043a\u0430 \u0438\u0440\u0438\u0441\u0430 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/i><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p><b>\u0420\u0435\u0448\u0430\u0435\u043c\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430:<\/b><\/p>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 (\u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u0441\u0435\u0433\u043e \u0434\u0432\u0430) \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0442\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445 \u0438\u0437 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b \u043c\u0435\u0442\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0414\u0430\u043b\u0435\u0435 \u0443\u0436\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043a\u0443 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439\/\u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438. \u041c\u0435\u0442\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8e8\/c41\/1ce\/8e8c411ce266c1c74d8d3e69f77eb497.svg\" alt=\"$Y = \\{-1, +1\\}$\" data-tex=\"inline\"><\/math>. \u041e\u0431\u044a\u0435\u043a\u0442 \u2014 \u0432\u0435\u043a\u0442\u043e\u0440 c N \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c86\/165\/634\/c861656340b73ce6444d3a228532fb63.svg\" alt=\"$x = (x_1, x_2, \u2026, x_n)$\" data-tex=\"inline\"><\/math> \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfa\/23e\/30c\/dfa23e30c44791c7046e5e973aeb1cb4.svg\" alt=\"$R^n$\" data-tex=\"inline\"><\/math>. \u041f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/22a\/2f9\/891\/22a2f9891e4c4321316e9d4fb90c4830.svg\" alt=\"$F(x)=y$\" data-tex=\"inline\"><\/math>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math> \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfa\/23e\/30c\/dfa23e30c44791c7046e5e973aeb1cb4.svg\" alt=\"$R^n$\" data-tex=\"inline\"><\/math> \u0438 \u0432\u044b\u0434\u0430\u0435\u0442 \u043c\u0435\u0442\u043a\u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b3\/4c4\/da5\/9b34c4da5c757d4982bbd1b6f2e8998a.svg\" alt=\"$y$\" data-tex=\"inline\"><\/math>.<\/p>\n<p><cut><\/cut>  <\/p>\n<p><b>\u041e\u0431\u0449\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u043e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435:<\/b><\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044e \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c. SVM \u2014 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c. \u041d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043c\u043d\u043e\u0433\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 <a href=\"https:\/\/vas3k.ru\/blog\/machine_learning\/\">\u044d\u0442\u043e\u0439 \u0442\u043e\u043f\u043e\u0432\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> (\u0441\u043c. \u0440\u0430\u0437\u0434\u0435\u043b \u00ab\u041a\u0430\u0440\u0442\u0430 \u043c\u0438\u0440\u0430 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f\u00bb). \u041d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c, \u0447\u0442\u043e SVM \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0438 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u0438, \u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d SVM-\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440.<\/p>\n<p>  <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u0430\u044f \u0446\u0435\u043b\u044c SVM \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u2014 \u043d\u0430\u0439\u0442\u0438 \u0443\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438<br \/>  <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a41\/3ec\/353\/a413ec353dc67440a9d3e755b22d14a2.svg\" alt=\"$w_1x_1+w_2x_2+\u2026+w_nx_n+w_0=0$\" data-tex=\"inline\"><\/math> \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/dfa\/23e\/30c\/dfa23e30c44791c7046e5e973aeb1cb4.svg\" alt=\"$R^n$\" data-tex=\"inline\"><\/math>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b\u0430 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435\u043a\u0438\u043c \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041e\u0431\u0449\u0438\u0439 \u0432\u0438\u0434 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/b8b\/97c\/656\/b8b97c6567171cc2b6a7f303a0fa8b0a.svg\" alt=\"$F$\" data-tex=\"inline\"><\/math> \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math> \u0432 \u043c\u0435\u0442\u043a\u0443 \u043a\u043b\u0430\u0441\u0441\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c62\/ff2\/5ef\/c62ff25ef4caeaeaef7122a489ef9d07.svg\" alt=\"$Y$\" data-tex=\"inline\"><\/math>: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/ed0\/cbf\/d83\/ed0cbfd835f8fc1cca2784e7f525fb2a.svg\" alt=\"$F(x) = sign(w^Tx-b)$\" data-tex=\"inline\"><\/math>. \u0411\u0443\u0434\u0435\u043c \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/691\/1bb\/50f\/6911bb50f68ac148fe91043a96735847.svg\" alt=\"$w = (w_1, w_2, \u2026, w_n), b=-w_0$\" data-tex=\"inline\"><\/math>. \u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432\u0435\u0441\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math> (\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f), \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u043f\u043e \u043e\u0434\u043d\u0443 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u043e\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0439 \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438, \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0435 \u043f\u043e \u0434\u0440\u0443\u0433\u0443\u044e \u0441\u0442\u043e\u0440\u043e\u043d\u0443 \u2014 \u0432\u0442\u043e\u0440\u043e\u0439 \u043a\u043b\u0430\u0441\u0441.<\/p>\n<p>  <\/p>\n<p>\u0412\u043d\u0443\u0442\u0440\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/46e\/b0c\/060\/46eb0c0601e19c5ad5accf7e8ffaa86e.svg\" alt=\"$sign()$\" data-tex=\"inline\"><\/math> \u0441\u0442\u043e\u0438\u0442 \u043b\u0438\u043d\u0435\u0439\u043d\u0430\u044f \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441 \u0432\u0435\u0441\u0430\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 SVM \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043b\u0438\u043d\u0435\u0439\u043d\u044b\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430\u043c. \u0420\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043d\u043e \u0432 SVM \u0432\u0435\u0441\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math> \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043b\u0435\u0436\u0430\u043b\u0438 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u0437\u043e\u0440 (<i>\u0430\u043d\u0433\u043b. margin<\/i>) \u043c\u0435\u0436\u0434\u0443 \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c\u044e \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u044b \u0431\u043b\u0438\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0435\u0439. \u0422\u0430\u043a\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e\u043f\u043e\u0440\u043d\u044b\u043c\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0430\u043c\u0438 (\u0441\u043c. \u0440\u0438\u0441.2). \u041e\u0442\u0441\u044e\u0434\u0430 \u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/n-\/5u\/gy\/n-5ugyyyqejoobj9javfcxaycpk.png\" alt=\"image\"><br \/>  <i>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 2. SVM (\u043e\u0441\u043d\u043e\u0432\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0430 <a href=\"https:\/\/staesthetic.files.wordpress.com\/2014\/02\/svm.png?w=1060\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>)<\/i><\/p>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432\u0435\u0441\u043e\u0432 SVM:<\/strong><\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u043e\u0442\u0441\u0442\u043e\u044f\u043b\u0430 \u043e\u0442 \u0442\u043e\u0447\u0435\u043a \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0448\u0438\u0440\u0438\u043d\u0430 \u043f\u043e\u043b\u043e\u0441\u044b \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439. \u0412\u0435\u043a\u0442\u043e\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math> \u2014 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438. \u0417\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u043e\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u0432\u0443\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u043a\u0430\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bd9\/bb6\/ae1\/bd9bb6ae133ed408ec03a0f9702eed74.svg\" alt=\"$\\langle a,b\\rangle$\" data-tex=\"inline\"><\/math> \u0438\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a7e\/54a\/380\/a7e54a3803c8ff2827b6250f51b1dafe.svg\" alt=\"$a^Tb$\" data-tex=\"inline\"><\/math>.\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0439\u0434\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044e \u0432\u0435\u043a\u0442\u043e\u0440\u0430, \u043a\u043e\u043d\u0446\u0430\u043c\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0443\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043e\u043f\u043e\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438. \u042d\u0442\u0430 \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f \u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0448\u0438\u0440\u0438\u043d\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u043b\u043e\u0441\u044b (\u0441\u043c. \u0440\u0438\u0441.3):<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/5s\/g-\/k9\/5sg-k9ytduiqgxlsv66u6jprvsi.png\" alt=\"image\"><br \/>  <i>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 3. \u0412\u044b\u0432\u043e\u0434 \u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432\u0435\u0441\u043e\u0432 (\u043e\u0441\u043d\u043e\u0432\u0430 \u0440\u0438\u0441\u0443\u043d\u043a\u0430 <a href=\"https:\/\/staesthetic.files.wordpress.com\/2014\/02\/svm.png?w=1060\">\u043e\u0442\u0441\u044e\u0434\u0430<\/a>)<\/i><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/927\/1cb\/fd1\/9271cbfd159a655d644aca487802dc36.svg\" alt=\"$\\langle(x_+-x_-),w\/\\Arrowvert w\\Arrowvert\\rangle = (\\langle x_+,w\\rangle - \\langle x_-,w\\rangle)\/\\Arrowvert w\\Arrowvert = ((b+1)-(b-1))\/\\Arrowvert w\\Arrowvert = 2\/\\Arrowvert w\\Arrowvert$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/c88\/6b4\/bad\/c886b4badccff2cad5ee08cf34936895.svg\" alt=\"$2\/\\Arrowvert w\\Arrowvert \\rightarrow max$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/fd5\/2f7\/9e3\/fd52f79e31b43256d5f87412e8c1cf94.svg\" alt=\"$\\Arrowvert w\\Arrowvert \\rightarrow min$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/127\/978\/e5f\/127978e5f35541717dbd8de210d959e9.svg\" alt=\"$(w^Tw)\/2 \\rightarrow min$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u0441\u0442\u0443\u043f\u043e\u043c (<em>\u0430\u043d\u0433\u043b. margin<\/em>) \u043e\u0431\u044a\u0435\u043a\u0442\u0430 x \u043e\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/313\/202\/716\/313202716a85cbb55e46e15eb3df0277.svg\" alt=\"$M=y(w^Tx-b)$\" data-tex=\"inline\"><\/math>. \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u043e\u0442\u0441\u0442\u0443\u043f <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/94d\/13e\/e0a\/94d13ee0aadd7f17977e0d279af38d42.svg\" alt=\"$M$\" data-tex=\"inline\"><\/math> \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u0435\u043d (\u043a\u043e\u0433\u0434\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b3\/4c4\/da5\/9b34c4da5c757d4982bbd1b6f2e8998a.svg\" alt=\"$y$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e9b\/762\/0a8\/e9b7620a8fc33ec04469340beac93786.svg\" alt=\"$(w^Tx-b)$\" data-tex=\"inline\"><\/math> \u0440\u0430\u0437\u043d\u044b\u0445 \u0437\u043d\u0430\u043a\u043e\u0432). \u0415\u0441\u043b\u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/49a\/47a\/91f\/49a47a91fe09a191e4c2b85a91cd7d14.svg\" alt=\"$M \u2208 (0, 1)$\" data-tex=\"inline\"><\/math>, \u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u043f\u043e\u043b\u043e\u0441\u044b. \u0415\u0441\u043b\u0438 <math>$inline$M &gt; 1$inline$<\/math>, \u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 x \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u043f\u043e\u043b\u043e\u0441\u044b. \u0417\u0430\u043f\u0438\u0448\u0435\u043c \u0438 \u044d\u0442\u0443 \u0441\u0432\u044f\u0437\u044c:<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3f7\/793\/70d\/3f779370d07168ef4d59999514206e32.svg\" alt=\"$y(w^Tx-b) \\geqslant 1$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 <em>SVM \u0441 \u0436\u0435\u0441\u0442\u043a\u0438\u043c \u0437\u0430\u0437\u043e\u0440\u043e\u043c<\/em> (<em>hard-margin SVM<\/em>), \u043a\u043e\u0433\u0434\u0430 \u043d\u0438\u043a\u0430\u043a\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443 \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u043d\u0430 \u043f\u043e\u043b\u043e\u0441\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0420\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0447\u0435\u0440\u0435\u0437 \u0442\u0435\u043e\u0440\u0435\u043c\u0443 \u041a\u0443\u043d\u0430-\u0422\u0430\u043a\u043a\u0435\u0440\u0430. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u0430 \u0434\u0432\u043e\u0439\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u043f\u043e\u0438\u0441\u043a\u0430 \u0441\u0435\u0434\u043b\u043e\u0432\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u041b\u0430\u0433\u0440\u0430\u043d\u0436\u0430.<\/p>\n<p>  <\/p>\n<p><math>$$display$$ \\left\\{ \\begin{array}{ll} (w^Tw)\/2 \\rightarrow min &amp; \\textrm{}\\\\ y(w^Tx-b) \\geqslant 1 &amp; \\textrm{} \\end{array} \\right. $$display$$<\/math><\/p>\n<p>  <\/p>\n<p>\u0412\u0441\u0451 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0443 \u043d\u0430\u0441 \u043a\u043b\u0430\u0441\u0441\u044b \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b. \u0427\u0442\u043e\u0431\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043c\u043e\u0433 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438 \u0441 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u043d\u0435\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u043c\u0438, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443. \u041f\u043e\u0437\u0432\u043e\u043b\u0438\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0430\u0440\u0430\u0435\u043c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0431\u044b\u043b\u043e \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435. \u0412\u0432\u0435\u0434\u0451\u043c \u043d\u0430\u0431\u043e\u0440 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 <math>$inline$\\xi _i &gt; 0$inline$<\/math>, \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0437\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0443 \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/42f\/173\/c29\/42f173c2992cf2826d484e0dac62fb74.svg\" alt=\"$x_i$\" data-tex=\"inline\"><\/math>. \u0412\u0432\u0435\u0434\u0451\u043c \u0432 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u0441\u0443\u043c\u043c\u0430\u0440\u043d\u0443\u044e \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p>  <\/p>\n<p><math>$$display$$ \\left\\{ \\begin{array}{ll} (w^Tw)\/2 + \\alpha\\sum\\xi _i \\rightarrow min &amp; \\textrm{}\\\\ y(w^Tx_i-b) \\geqslant 1 -\\xi _i &amp; \\textrm{}\\\\ \\xi _i\\geqslant0&amp; \\textrm{} \\end{array} \\right. $$display$$<\/math><\/p>\n<p>  <\/p>\n<p>\u0411\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 (\u043a\u043e\u0433\u0434\u0430 M&lt;0). \u041d\u0430\u0437\u043e\u0432\u0435\u043c \u044d\u0442\u043e \u0448\u0442\u0440\u0430\u0444\u043e\u043c (<em>Penalty<\/em>). \u0422\u043e\u0433\u0434\u0430 \u0448\u0442\u0440\u0430\u0444 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u0435\u043d \u0441\u0443\u043c\u043c\u0435 \u0448\u0442\u0440\u0430\u0444\u043e\u0432 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/42f\/173\/c29\/42f173c2992cf2826d484e0dac62fb74.svg\" alt=\"$x_i$\" data-tex=\"inline\"><\/math>, \u0433\u0434\u0435 <math>$inline$[M_i&lt;0]$inline$<\/math> \u2014 \u043f\u043e\u0440\u043e\u0433\u043e\u0432\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (\u0441\u043c. \u0440\u0438\u0441.4):<\/p>\n<p>  <\/p>\n<p><math>$$display$$Penalty = \\sum[M_i &lt; 0]$$display$$<\/math><\/p>\n<p>  <\/p>\n<p><math>$$display$$ [M_i &lt; 0] = \\left\\{ \\begin{array}{ll} 1 &amp; \\textrm{, \u0435\u0441\u043b\u0438 }M_i &lt; 0\\\\ 0 &amp; \\textrm{, \u0435\u0441\u043b\u0438 }M_i\\geqslant 0 \\end{array} \\right. $$display$$<\/math><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0448\u0442\u0440\u0430\u0444 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043a \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u0435 \u043e\u0448\u0438\u0431\u043a\u0438 \u0438 \u0437\u0430\u043e\u0434\u043d\u043e \u0432\u0432\u0435\u0434\u0435\u043c \u0448\u0442\u0440\u0430\u0444 \u0437\u0430 \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432:<\/p>\n<p>  <\/p>\n<p><math>$$display$$Penalty = \\sum[M_i &lt; 0] \\leqslant \\sum(1- M_i)_+ = \\sum max(0,1-M_i)$$display$$<\/math><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043a \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e \u0448\u0442\u0440\u0430\u0444\u0430 \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u043e\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/798\/ed0\/15d\/798ed015d301c5d9218a0f05e1c883f9.svg\" alt=\"$\\alpha(w^Tw)\/2$\" data-tex=\"inline\"><\/math> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0444\u0443\u043a\u0446\u0438\u044e \u043f\u043e\u0442\u0435\u0440\u044c <em>SVM \u0441 \u043c\u044f\u0433\u043a\u0438\u043c \u0437\u0430\u0437\u043e\u0440\u043e\u043c<\/em> (<em>soft-margin SVM<\/em>) \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430:<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3b3\/994\/65e\/3b399465e0751707a36caf13c155987e.svg\" alt=\"$Q =max(0,1- M_i) + \\alpha(w^Tw)\/2$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/25c\/1b1\/df1\/25c1b1df17ffb65c7b5d70d1dfa768be.svg\" alt=\"$Q =max(0,1- yw^Tx) + \\alpha(w^Tw)\/2$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/eb9\/04b\/678\/eb904b678aba503fe98f5759398e5ee0.svg\" alt=\"$Q$\" data-tex=\"inline\"><\/math> \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0442\u0435\u0440\u044c, \u043e\u043d\u0430 \u0436\u0435 loss function. \u0418\u043c\u0435\u043d\u043d\u043e \u0435\u0435 \u043c\u044b \u0438 \u0431\u0443\u0434\u0435\u043c \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0443\u043a\u0430\u043c\u0438. \u0412\u044b\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432, \u0433\u0434\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bb9\/97f\/87c\/bb997f87cffdb02b3cf68579e8e7f520.svg\" alt=\"$\\eta$\" data-tex=\"inline\"><\/math> \u2013 \u0448\u0430\u0433 \u0441\u043f\u0443\u0441\u043a\u0430:<\/p>\n<p>  <\/p>\n<p><math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/730\/037\/a5a\/730037a5a4688bb1e09c71fb7c1b9669.svg\" alt=\"$w = w \u2013 \\eta\\bigtriangledown Q$\" data-tex=\"display\"><\/math><\/p>\n<p>  <\/p>\n<p><math>$$display$$ \\bigtriangledown Q = \\left\\{ \\begin{array}{ll} \\alpha w-yx &amp; \\textrm{, \u0435\u0441\u043b\u0438 }yw^Tx&lt;1\\\\ \\alpha w &amp; \\textrm{, \u0435\u0441\u043b\u0438 }yw^Tx\\geqslant 1 \\end{array} \\right. $$display$$<\/math><\/p>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f\u0445 (\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u0445):<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0431\u0449\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0440\u043e SVM: <em>\u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e Hinge_loss \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0437\u0430\u0437\u043e\u0440?<\/em> \u2013 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c \u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u0432\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432\u0435\u0441\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/302\/c72\/04e\/302c7204ea9987e698a70307646abd71.svg\" alt=\"$b$\" data-tex=\"inline\"><\/math>. \u0412\u0435\u0441\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043b\u043e\u0441\u0441-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u0440\u0430\u0432\u043d\u044b \u043d\u0443\u043b\u044e (\u043e\u0431\u044b\u0447\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f\u0442: \u201c\u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0442\u0435\u043a\u0443\u0442\u201d). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u043b\u0438 \u0442\u0430\u043a\u0443\u044e \u043b\u043e\u0441\u0441-\u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0442\u0435\u0447\u044c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0432 \u043d\u0443\u0436\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a4c\/8b2\/43e\/a4c8b243e2bf23fd15edfa40df292be3.svg\" alt=\"$Hinge loss$\" data-tex=\"inline\"><\/math> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8ae\/572\/c04\/8ae572c047c7c5df8033679a3658ab49.svg\" alt=\"$H = max(0,1-y(w^Tx))$\" data-tex=\"inline\"><\/math>. \u041f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0437\u0430\u0437\u043e\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/169\/718\/e6a\/169718e6adbe38be642d5beb5ba62395.svg\" alt=\"$m=y(w^Tx)$\" data-tex=\"inline\"><\/math>. \u041a\u043e\u0433\u0434\u0430 \u0437\u0430\u0437\u043e\u0440 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/e2e\/33f\/15a\/e2e33f15a96008ca33579599483c4531.svg\" alt=\"$m$\" data-tex=\"inline\"><\/math> \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/3e4\/c77\/a6e\/3e4c77a6e7c579a778fa84a18b6f4be0.svg\" alt=\"$1$\" data-tex=\"inline\"><\/math> \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435), \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d56\/169\/81c\/d5616981c7ea5b88b2063710aa53971f.svg\" alt=\"$(1-m)$\" data-tex=\"inline\"><\/math> \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043c\u0435\u043d\u044c\u0448\u0435 \u043d\u0443\u043b\u044f \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/7bc\/27b\/c57\/7bc27bc576d65dd44efc4fd92441d9aa.svg\" alt=\"$H=0$\" data-tex=\"inline\"><\/math> (\u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u043d\u0435 \u0442\u0435\u043a\u0443\u0442 \u0438 \u0432\u0435\u0441\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f). \u0415\u0441\u043b\u0438 \u0436\u0435 \u0437\u0430\u0437\u043e\u0440 m \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043c\u0430\u043b\u044b\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0430 \u043f\u043e\u043b\u043e\u0441\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438\/\u0438\u043b\u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 (\u043f\u0440\u0438 \u043d\u0435\u0432\u0435\u0440\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438), \u0442\u043e Hinge_loss \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 (<math>$inline$H&gt;0$inline$<\/math>), \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0442\u0435\u0447\u044c \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0438 \u0432\u0435\u0441\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u0420\u0435\u0437\u044e\u043c\u0438\u0440\u0443\u044f: \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b \u0442\u0435\u043a\u0443\u0442 \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445: \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u043e\u043f\u0430\u043b \u0432\u043d\u0443\u0442\u0440\u044c \u043f\u043e\u043b\u043e\u0441\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0438 \u043d\u0435\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0443\u0440\u043e\u0432\u043d\u044f \u0438\u043d\u043e\u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b: <em>What are the similarities and differences between LogisticRegression and SVM?<\/em> \u2013 firstly, we will talk about similarities: both of algorithms are linear classification algorithms in supervised learning. Some similarities are in their arguments of loss functions: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/901\/62d\/9eb\/90162d9ebedcded6762259cc199aadca.svg\" alt=\"$log(1+exp(-y(w^Tx)))$\" data-tex=\"inline\"><\/math> for LogReg and <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/39d\/c70\/e22\/39dc70e228cab0427f3ea55a08ed9415.svg\" alt=\"$max(0,1-y(w^Tx))$\" data-tex=\"inline\"><\/math> for SVM (look at picture 4). Both of algorithms we can configure using gradient descent. Next let\u2019s talk about differences: SVM return class label of object unlike LogReg, which return probability of class membership. SVM can\u2019t work with class labels <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0bb\/459\/50d\/0bb45950d4655c3f3be8486e02084853.svg\" alt=\"$\\{0,1\\}$\" data-tex=\"inline\"><\/math> (without renaming classes) unlike LogReg (LogReg loss finction for <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0bb\/459\/50d\/0bb45950d4655c3f3be8486e02084853.svg\" alt=\"$\\{0,1\\}$\" data-tex=\"inline\"><\/math>: <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/a16\/2b5\/076\/a162b50761c8a26376fd82087380e52c.svg\" alt=\"$-plog(y)-(1-p)log(1-y)$\" data-tex=\"inline\"><\/math>, where <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9b3\/4c4\/da5\/9b34c4da5c757d4982bbd1b6f2e8998a.svg\" alt=\"$y$\" data-tex=\"inline\"><\/math> \u2013 real class label, <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/839\/f25\/c27\/839f25c2746382debd4f08ea25ad5ecf.svg\" alt=\"$p$\" data-tex=\"inline\"><\/math> \u2013 algorithm\u2019s return, probability of belonging object <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/817\/b92\/407\/817b92407f764f57af9226e50cc788fd.svg\" alt=\"$x$\" data-tex=\"inline\"><\/math> to class<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/20c\/2a5\/707\/20c2a5707a423cd7a6df01acc730b139.svg\" alt=\"$\\{1\\}$\" data-tex=\"inline\"><\/math>). More than that, we can solve hard-margin SVM problem without gradient descent. The task of searching support vectors is reduced to search saddle point in the Lagrange function \u2013 this task refers to quadratic programming only.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Loss function&#39;s code:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import numpy as np import matplotlib.pyplot as plt %matplotlib inline  xx = np.linspace(-4,3,100000) plt.plot(xx, [(x&lt;0).astype(int) for x in xx], linewidth=2, label='1 if M&lt;0, else 0') plt.plot(xx, [np.log2(1+2.76**(-x))  for x in xx], linewidth=4, label='logistic = log(1+e^-M)') plt.plot(xx, [np.max(np.array([0,1-x]))  for x in xx], linewidth=4, label='hinge = max(0,1-M)') plt.title('Loss = F(Margin)') plt.grid() plt.legend(prop={'size': 14});<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g8\/kd\/hv\/g8kdhvspafgvsac5hn_9u30oxsq.png\" alt=\"image\"><br \/>  <em>\u0420\u0438c\u0443\u043d\u043e\u043a 4. \u0424\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c<\/em><\/p>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e soft-margin SVM:<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0421\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u041d\u0438\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0431\u043b\u043e\u043a\u0438 \u043a\u043e\u0434\u0430, \u0432\u044b\u0440\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043b\u043e\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0431\u043b\u043e\u043a\u043e\u0432. \u041f\u043e\u0434 \u043c\u043d\u043e\u0433\u0438\u043c\u0438 \u0431\u043b\u043e\u043a\u0430\u043c\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442, \u043a\u0430\u043a \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043a\u043e\u0434, \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0434 \u043d\u0435\u0439.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u0440\u0443\u0431\u0438\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043b\u0438\u043d\u0438\u0438:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import numpy as np import warnings warnings.filterwarnings('ignore')  import matplotlib.pyplot as plt import matplotlib.lines as mlines plt.rcParams['figure.figsize'] = (8,6) %matplotlib inline  from sklearn.datasets import load_iris from sklearn.decomposition import PCA from sklearn.model_selection import train_test_split  def newline(p1, p2, color=None): # \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u043b\u0438\u043d\u0438\u0438     #function kredits to: https:\/\/fooobar.com\/questions\/626491\/how-to-draw-a-line-with-matplotlib     ax = plt.gca()     xmin, xmax = ax.get_xbound()      if(p2[0] == p1[0]):         xmin = xmax = p1[0]         ymin, ymax = ax.get_ybound()     else:         ymax = p1[1]+(p2[1]-p1[1])\/(p2[0]-p1[0])*(xmax-p1[0])         ymin = p1[1]+(p2[1]-p1[1])\/(p2[0]-p1[0])*(xmin-p1[0])      l = mlines.Line2D([xmin,xmax], [ymin,ymax], color=color)     ax.add_line(l)     return l<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">Python \u043a\u043e\u0434 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 soft-margin SVM:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def add_bias_feature(a):     a_extended = np.zeros((a.shape[0],a.shape[1]+1))     a_extended[:,:-1] = a     a_extended[:,-1] = int(1)       return a_extended  class CustomSVM(object):      __class__ = &quot;CustomSVM&quot;     __doc__ = &quot;&quot;&quot;     This is an implementation of the SVM classification algorithm     Note that it works only for binary classification      #############################################################     ######################   PARAMETERS    ######################     #############################################################      etha: float(default - 0.01)         Learning rate, gradient step      alpha: float, (default - 0.1)         Regularization parameter in 0.5*alpha*||w||^2      epochs: int, (default - 200)         Number of epochs of training      #############################################################     #############################################################     #############################################################     &quot;&quot;&quot;      def __init__(self, etha=0.01, alpha=0.1, epochs=200):         self._epochs = epochs         self._etha = etha         self._alpha = alpha         self._w = None         self.history_w = []         self.train_errors = None         self.val_errors = None         self.train_loss = None         self.val_loss = None      def fit(self, X_train, Y_train, X_val, Y_val, verbose=False): #arrays: X; Y =-1,1          if len(set(Y_train)) != 2 or len(set(Y_val)) != 2:             raise ValueError(&quot;Number of classes in Y is not equal 2!&quot;)          X_train = add_bias_feature(X_train)         X_val = add_bias_feature(X_val)         self._w = np.random.normal(loc=0, scale=0.05, size=X_train.shape[1])         self.history_w.append(self._w)         train_errors = []         val_errors = []         train_loss_epoch = []         val_loss_epoch = []          for epoch in range(self._epochs):              tr_err = 0             val_err = 0             tr_loss = 0             val_loss = 0             for i,x in enumerate(X_train):                 margin = Y_train[i]*np.dot(self._w,X_train[i])                 if margin &gt;= 1: # \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0432\u0435\u0440\u043d\u043e                     self._w = self._w - self._etha*self._alpha*self._w\/self._epochs                     tr_loss += self.soft_margin_loss(X_train[i],Y_train[i])                 else: # \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u043d\u0430 \u043f\u043e\u043b\u043e\u0441\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438 0&lt;m&lt;1                     self._w = self._w +\\                     self._etha*(Y_train[i]*X_train[i] - self._alpha*self._w\/self._epochs)                     tr_err += 1                     tr_loss += self.soft_margin_loss(X_train[i],Y_train[i])                 self.history_w.append(self._w)             for i,x in enumerate(X_val):                 val_loss += self.soft_margin_loss(X_val[i], Y_val[i])                 val_err += (Y_val[i]*np.dot(self._w,X_val[i])&lt;1).astype(int)             if verbose:                 print('epoch {}. Errors={}. Mean Hinge_loss={}'\\                       .format(epoch,err,loss))             train_errors.append(tr_err)             val_errors.append(val_err)             train_loss_epoch.append(tr_loss)             val_loss_epoch.append(val_loss)         self.history_w = np.array(self.history_w)             self.train_errors = np.array(train_errors)         self.val_errors = np.array(val_errors)         self.train_loss = np.array(train_loss_epoch)         self.val_loss = np.array(val_loss_epoch)                          def predict(self, X:np.array) -&gt; np.array:         y_pred = []         X_extended = add_bias_feature(X)         for i in range(len(X_extended)):             y_pred.append(np.sign(np.dot(self._w,X_extended[i])))         return np.array(y_pred)               def hinge_loss(self, x, y):         return max(0,1 - y*np.dot(x, self._w))      def soft_margin_loss(self, x, y):         return self.hinge_loss(x,y)+self._alpha*np.dot(self._w, self._w)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0441\u0442\u0440\u043e\u0447\u0435\u043a:<\/p>\n<p>  <\/p>\n<p>1) \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <em>add_bias_feature(a)<\/em>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u0435\u043a\u0442\u043e\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0432 \u043a\u043e\u043d\u0435\u0446 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0447\u0438\u0441\u043b\u043e 1. \u042d\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u00ab\u0437\u0430\u0431\u044b\u0442\u044c\u00bb \u043f\u0440\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u044b\u0439 \u0447\u043b\u0435\u043d b. \u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/8fa\/ab2\/565\/8faab25652fc6ef7816fced9be5bdfc6.svg\" alt=\"$w^Tx-b$\" data-tex=\"inline\"><\/math> \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/527\/d89\/6a5\/527d896a576aaa863c90cd2c4b612c46.svg\" alt=\"$w_1x_1+w_2x_2+\u2026+w_nx_n+w_0*1$\" data-tex=\"inline\"><\/math>. \u041c\u044b \u0443\u0441\u043b\u043e\u0432\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u0435\u043c, \u0447\u0442\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u2014 \u044d\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 x, \u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f8d\/111\/0fc\/f8d1110fc9cfae494cf2584a35982589.svg\" alt=\"$w_0=-b$\" data-tex=\"inline\"><\/math>. \u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0432\u0435\u0441\u043e\u0432 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/1d0\/034\/a09\/1d0034a09108db7af7cf42ea23a91ecd.svg\" alt=\"$w$\" data-tex=\"inline\"><\/math> \u0438 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/f9f\/764\/ab0\/f9f764ab001c8a8b74efe64ad3ca8ead.svg\" alt=\"$w_0$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u0430 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">def add_bias_feature(a):     a_extended = np.zeros((a.shape[0],a.shape[1]+1))     a_extended[:,:-1] = a     a_extended[:,-1] = int(1)       return a_extended<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>2) \u0434\u0430\u043b\u0435\u0435 \u043e\u043f\u0438\u0448\u0435\u043c \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440. \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u0431\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <em>init()<\/em>, \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f <em>fit()<\/em>, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f <em>predict()<\/em>, \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043b\u043e\u0441\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>hinge_loss()<\/em> \u0438 \u043d\u0430\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0439 \u043b\u043e\u0441\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441 \u043c\u044f\u0433\u043a\u0438\u043c \u0437\u0430\u0437\u043e\u0440\u043e\u043c <em>soft_margin_loss()<\/em>.<\/p>\n<p>  <\/p>\n<p>3) \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0432\u043e\u0434\u044f\u0442\u0441\u044f 3 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430: _etha \u2013 \u0448\u0430\u0433 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u043d\u043e\u0433\u043e \u0441\u043f\u0443\u0441\u043a\u0430 (<math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/bb9\/97f\/87c\/bb997f87cffdb02b3cf68579e8e7f520.svg\" alt=\"$\\eta$\" data-tex=\"inline\"><\/math>), _alpha \u2013 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0431\u044b\u0441\u0442\u0440\u043e\u0442\u044b \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432 (\u043f\u0435\u0440\u0435\u0434 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u044b\u043c \u0441\u043b\u0430\u0433\u0430\u0435\u043c\u044b\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/723\/4a5\/2ba\/7234a52ba041cdb09b9328a047048fb2.svg\" alt=\"$\\alpha$\" data-tex=\"inline\"><\/math>), _epochs \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043f\u043e\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">    def __init__(self, etha=0.01, alpha=0.1, epochs=200):         self._epochs = epochs         self._etha = etha         self._alpha = alpha         self._w = None         self.history_w = []         self.train_errors = None         self.val_errors = None         self.train_loss = None         self.val_loss = None<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>4) \u043f\u0440\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u044d\u043f\u043e\u0445\u0438 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 (X_train, Y_train) \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u0438\u0437 \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0437\u0430\u0437\u043e\u0440 \u043c\u0435\u0436\u0434\u0443 \u044d\u0442\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u0438 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0414\u0430\u043b\u0435\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0432\u0435\u043b\u0438\u0447\u0438\u043d\u044b \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0437\u043e\u0440\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0432\u0435\u0441\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0442\u0435\u0440\u044c <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/eb9\/04b\/678\/eb904b678aba503fe98f5759398e5ee0.svg\" alt=\"$Q$\" data-tex=\"inline\"><\/math>. \u0417\u0430\u043e\u0434\u043d\u043e \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u044d\u043f\u043e\u0445\u0435 \u0438 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0432\u0435\u0441\u0430 \u0437\u0430 \u044d\u043f\u043e\u0445\u0443. \u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0448\u043b\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u043a \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 \u0432\u0435\u0441\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0445 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">    def fit(self, X_train, Y_train, X_val, Y_val, verbose=False): #arrays: X; Y =-1,1          if len(set(Y_train)) != 2 or len(set(Y_val)) != 2:             raise ValueError(&quot;Number of classes in Y is not equal 2!&quot;)          X_train = add_bias_feature(X_train)         X_val = add_bias_feature(X_val)         self._w = np.random.normal(loc=0, scale=0.05, size=X_train.shape[1])         self.history_w.append(self._w)         train_errors = []         val_errors = []         train_loss_epoch = []         val_loss_epoch = []          for epoch in range(self._epochs):              tr_err = 0             val_err = 0             tr_loss = 0             val_loss = 0             for i,x in enumerate(X_train):                 margin = Y_train[i]*np.dot(self._w,X_train[i])                 if margin &gt;= 1: # \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u0432\u0435\u0440\u043d\u043e                     self._w = self._w - self._etha*self._alpha*self._w\/self._epochs                     tr_loss += self.soft_margin_loss(X_train[i],Y_train[i])                 else: # \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0432\u0435\u0440\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u043d\u0430 \u043f\u043e\u043b\u043e\u0441\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438 0&lt;m&lt;1                     self._w = self._w +\\                     self._etha*(Y_train[i]*X_train[i] - self._alpha*self._w\/self._epochs)                     tr_err += 1                     tr_loss += self.soft_margin_loss(X_train[i],Y_train[i])                 self.history_w.append(self._w)             for i,x in enumerate(X_val):                 val_loss += self.soft_margin_loss(X_val[i], Y_val[i])                 val_err += (Y_val[i]*np.dot(self._w,X_val[i])&lt;1).astype(int)             if verbose:                 print('epoch {}. Errors={}. Mean Hinge_loss={}'\\                       .format(epoch,err,loss))             train_errors.append(tr_err)             val_errors.append(val_err)             train_loss_epoch.append(tr_loss)             val_loss_epoch.append(val_loss)         self.history_w = np.array(self.history_w)             self.train_errors = np.array(train_errors)         self.val_errors = np.array(val_errors)         self.train_loss = np.array(train_loss_epoch)         self.val_loss = np.array(val_loss_epoch)<\/code><\/pre>\n<\/div>\n<\/div>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430:<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u0448 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0433\u0440\u0443\u0448\u0435\u0447\u043d\u043e\u043c \u043d\u0430\u0431\u043e\u0440\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 Iris. \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435. \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u044b 1 \u0438 2 \u043a\u0430\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/9d1\/49e\/a8e\/9d149ea8ef8692eb106a55ce5af36ccd.svg\" alt=\"$+1$\" data-tex=\"inline\"><\/math>, \u0430 \u043a\u043b\u0430\u0441\u0441 0 \u043a\u0430\u043a <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/d06\/719\/edc\/d06719edc69908e7467f7e6189302b74.svg\" alt=\"$-1$\" data-tex=\"inline\"><\/math>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 PCA (\u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 <a href=\"https:\/\/habr.com\/ru\/company\/ods\/blog\/325654\/\">\u0442\u0443\u0442<\/a>) \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e 4-\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0434\u043e 2-\u0445 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u043e\u0442\u0435\u0440\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043d\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0449\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c \u0437\u0430 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u0440\u0430\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c). \u0414\u0430\u043b\u0435\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e (\u0442\u0440\u0435\u0439\u043d) \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u0443\u044e (\u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u043e\u043d\u043d\u0443\u044e). \u041e\u0431\u0443\u0447\u0438\u043c \u043d\u0430 \u0442\u0440\u0435\u0439\u043d \u0432\u044b\u0431\u043e\u0440\u043a\u0435, \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u0443\u0435\u043c \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0430 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439. \u041f\u043e\u0434\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u044b \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043b\u043e\u0441\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0430\u0434\u0430\u043b\u0430. \u0412\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043b\u043e\u0441\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0438 \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0431\u043b\u043e\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 iris = load_iris() X = iris.data Y = iris.target  pca = PCA(n_components=2) X = pca.fit_transform(X) Y = (Y &gt; 0).astype(int)*2-1 # [0,1,2] --&gt; [False,True,True] --&gt; [0,1,1] --&gt; [0,2,2] --&gt; [-1,1,1]  X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, random_state=2020)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0431\u043b\u043e\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0446\u0438\u0438 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f svm = CustomSVM(etha=0.005, alpha=0.006, epochs=150) svm.fit(X_train, Y_train, X_test, Y_test)  print(svm.train_errors) # numbers of error in each epoch print(svm._w) # w0*x_i[0]+w1*x_i[1]+w2=0  plt.plot(svm.train_loss, linewidth=2, label='train_loss') plt.plot(svm.val_loss, linewidth=2, label='test_loss') plt.grid() plt.legend(prop={'size': 15}) plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/rt\/cr\/sl\/rtcrslgemybgvqn8icejdp7tvvg.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u043f\u043e\u043b\u043e\u0441\u044b:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">d = {-1:'green', 1:'red'} plt.scatter(X_train[:,0], X_train[:,1], c=[d[y] for y in Y_train]) newline([0,-svm._w[2]\/svm._w[1]],[-svm._w[2]\/svm._w[0],0], 'blue') # \u0432 w0*x_i[0]+w1*x_i[1]+w2*1=0 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e                                                         # \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c x_i[0]=0, x_i[1]=0 newline([0,1\/svm._w[1]-svm._w[2]\/svm._w[1]],[1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=1 newline([0,-1\/svm._w[1]-svm._w[2]\/svm._w[1]],[-1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=-1 plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/xx\/aa\/92\/xxaa92b-708uc3so5uml1nq_bd0.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f y_pred = svm.predict(X_test) y_pred[y_pred != Y_test] = -100 # find and mark classification error print('\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043b\u044f \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438: ', (y_pred == -100).astype(int).sum()) d1 = {-1:'lime', 1:'m', -100: 'black'} # black = classification error plt.scatter(X_test[:,0], X_test[:,1], c=[d1[y] for y in y_pred]) newline([0,-svm._w[2]\/svm._w[1]],[-svm._w[2]\/svm._w[0],0], 'blue') newline([0,1\/svm._w[1]-svm._w[2]\/svm._w[1]],[1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=1 newline([0,-1\/svm._w[1]-svm._w[2]\/svm._w[1]],[-1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=-1 plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tz\/zh\/ae\/tzzhaeq5oedexyqe3yvifjdqgti.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u041d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0441 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043c \u0435\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b 0 \u0438 1 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 2:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0431\u043b\u043e\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 iris = load_iris() X = iris.data Y = iris.target  pca = PCA(n_components=2) X = pca.fit_transform(X) Y = (Y == 2).astype(int)*2-1 # [0,1,2] --&gt; [False,False,True] --&gt; [0,1,1] --&gt; [0,0,2] --&gt; [-1,1,1]  X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, random_state=2020)<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u0431\u043b\u043e\u043a \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0446\u0438\u0438 \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f svm = CustomSVM(etha=0.03, alpha=0.0001, epochs=300) svm.fit(X_train, Y_train, X_test, Y_test)  print(svm.train_errors[:150]) # numbers of error in each epoch print(svm._w) # w0*x_i[0]+w1*x_i[1]+w2=0  plt.plot(svm.train_loss, linewidth=2, label='train_loss') plt.plot(svm.val_loss, linewidth=2, label='test_loss') plt.grid() plt.legend(prop={'size': 15}) plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/e7\/v0\/03\/e7v003dacfpk8s2qwvrnidqk-bq.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0439\u0441\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u043f\u043e\u043b\u043e\u0441\u044b:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">d = {-1:'green', 1:'red'} plt.scatter(X_train[:,0], X_train[:,1], c=[d[y] for y in Y_train]) newline([0,-svm._w[2]\/svm._w[1]],[-svm._w[2]\/svm._w[0],0], 'blue') # \u0432 w0*x_i[0]+w1*x_i[1]+w2*1=0 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e                                                         # \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c x_i[0]=0, x_i[1]=0 newline([0,1\/svm._w[1]-svm._w[2]\/svm._w[1]],[1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=1 newline([0,-1\/svm._w[1]-svm._w[2]\/svm._w[1]],[-1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=-1 plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1i\/cf\/h_\/1icfh_hh5cm9hdk4nakg-zfbvw4.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0433\u0438\u0444\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043a\u0430\u0436\u0435\u0442, \u043a\u0430\u043a \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u043f\u0440\u044f\u043c\u0430\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u043b\u0430 \u0441\u0432\u043e\u0435 \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u0432\u0441\u0435\u0433\u043e 500 \u043a\u0430\u0434\u0440\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0441\u043e\u0432. \u041f\u0435\u0440\u0432\u044b\u0435 300 \u043f\u043e\u0434\u0440\u044f\u0434. \u0414\u0430\u043b\u0435\u0435 200 \u0448\u0442\u0443\u043a \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 130\u044b\u0439 \u043a\u0430\u0434\u0440):<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">import matplotlib.animation as animation from matplotlib.animation import PillowWriter  def one_image(w, X, Y):     axes = plt.gca()     axes.set_xlim([-4,4])     axes.set_ylim([-1.5,1.5])     d1 = {-1:'green', 1:'red'}     im = plt.scatter(X[:,0], X[:,1], c=[d1[y] for y in Y])     im = newline([0,-w[2]\/w[1]],[-w[2]\/w[0],0], 'blue') #    im = newline([0,1\/w[1]-w[2]\/w[1]],[1\/w[0]-w[2]\/w[0],0], 'lime') #w0*x_i[0]+w1*x_i[1]+w2*1=1 #    im = newline([0,-1\/w[1]-w[2]\/w[1]],[-1\/w[0]-w[2]\/w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=-1     return im  fig = plt.figure()  ims = [] for i in range(500):     if i&lt;=300:         k = i     else:         k = (i-298)*130     im = one_image(svm.history_w[k], X_train, Y_train)     ims.append([im])  ani = animation.ArtistAnimation(fig, ims, interval=20, blit=True,                                 repeat_delay=500)  writer = PillowWriter(fps=20) ani.save(&quot;my_demo.gif&quot;, writer='imagemagick')<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/h7\/vn\/dt\/h7vndtkzlinfkyoqzpcmjxecubu.gif\" alt=\"image\"><\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0411\u043b\u043e\u043a \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430:<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\"># \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f y_pred = svm.predict(X_test) y_pred[y_pred != Y_test] = -100 # find and mark classification error print('\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u0434\u043b\u044f \u043e\u0442\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438: ', (y_pred == -100).astype(int).sum()) d1 = {-1:'lime', 1:'m', -100: 'black'} # black = classification error plt.scatter(X_test[:,0], X_test[:,1], c=[d1[y] for y in y_pred]) newline([0,-svm._w[2]\/svm._w[1]],[-svm._w[2]\/svm._w[0],0], 'blue') newline([0,1\/svm._w[1]-svm._w[2]\/svm._w[1]],[1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=1 newline([0,-1\/svm._w[1]-svm._w[2]\/svm._w[1]],[-1\/svm._w[0]-svm._w[2]\/svm._w[0],0]) #w0*x_i[0]+w1*x_i[1]+w2*1=-1 plt.show()<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/aw\/7d\/ea\/aw7deavjl20x3bpezeo5nvbqom4.png\" alt=\"image\"><\/p>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u0421\u043f\u0440\u044f\u043c\u043b\u044f\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u0447\u0442\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0447\u0430\u044f \u0441 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0431\u044b\u043b\u0430 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0430 \u0438\u0434\u0435\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u0433\u0434\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b. \u0422\u0430\u043a\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043f\u0440\u044f\u043c\u043b\u044f\u044e\u0449\u0438\u043c. \u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0442\u0440\u043e\u043d\u0443\u0442\u044b \u0441\u043f\u0440\u044f\u043c\u043b\u044f\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u0438 \u044f\u0434\u0440\u0430. \u0421\u0430\u043c\u0443\u044e \u043f\u043e\u043b\u043d\u0443\u044e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0442\u0435\u043e\u0440\u0438\u044e \u0412\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/esokolov\/ml-course-hse\/tree\/master\/2017-spring\/lecture-notes\">14,15,16 \u043a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u0430\u0445 \u0415. \u0421\u043e\u043a\u043e\u043b\u043e\u0432\u0430<\/a> \u0438 \u0432 <a href=\"http:\/\/www.ccas.ru\/voron\/download\/SVM.pdf\">\u043b\u0435\u043a\u0446\u0438\u044f\u0445 \u041a.\u0412.\u0412\u043e\u0440\u043e\u043d\u0446\u043e\u0432\u0430<\/a>.<\/p>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 SVM \u0438\u0437 sklearn:<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0437\u0430 \u0412\u0430\u0441. \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430, \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <em>sklearn<\/em>.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"python\">from sklearn import svm from sklearn.metrics import recall_score  C = 1.0  # = self._alpha in our algorithm model1 = svm.SVC(kernel='linear', C=C) #model1 = svm.LinearSVC(C=C, max_iter=10000) #model1 = svm.SVC(kernel='rbf', gamma=0.7, C=C) #model1 = svm.SVC(kernel='poly', degree=3, gamma='auto', C=C)  model1.fit(X_train, Y_train) y_predict = model1.predict(X_test) print(recall_score(Y_test, y_predict, average=None))<\/code><\/pre>\n<\/div>\n<\/div>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u041f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e SVM:<\/strong><\/p>\n<p>  <\/p>\n<p>\u041f\u043b\u044e\u0441\u044b:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430;<\/li>\n<li>\u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430;<\/li>\n<li>\u0442\u0430\u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0443\u044e \u043f\u043e\u043b\u043e\u0441\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0430\u043a \u043f\u043e\u0434\u0443\u0448\u043a\u0430 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438;<\/li>\n<li>\u0442\u0430\u043a \u043a\u0430\u043a \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0440\u0435\u0448\u0435\u043d\u0438\u044e \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0432\u044b\u043f\u0443\u043a\u043b\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u0442\u043e \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u0435\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 (\u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0430\u044f \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044c \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0434\u043d\u0430).<\/li>\n<\/ol>\n<p>  <\/p>\n<p>\u041c\u0438\u043d\u0443\u0441\u044b:<\/p>\n<p>  <\/p>\n<ol>\n<li>\u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043d\u0430\u0431\u043e\u0440\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445);<\/li>\n<li>\u043d\u0435\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u043a \u0448\u0443\u043c\u0443: \u0432\u044b\u0431\u0440\u043e\u0441\u044b \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043e\u043f\u043e\u0440\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438-\u043d\u0430\u0440\u0443\u0448\u0438\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u043b\u0438\u044f\u044e\u0442 \u043d\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0449\u0435\u0439 \u0433\u0438\u043f\u0435\u0440\u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u0438;<\/li>\n<li>\u043d\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u043e\u0431\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u044f\u0434\u0435\u0440 \u0438 \u0441\u043f\u0440\u044f\u043c\u043b\u044f\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432, \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u043d\u0435\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u2013 \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u043e.<\/li>\n<\/ol>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 SVM:<\/strong><\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0431\u043e\u0440 \u0442\u043e\u0433\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u043e \u0432 \u043e\u0431\u0449\u0438\u0445 \u0441\u043b\u043e\u0432\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0437\u0430\u0434\u0430\u0447\u0438 \u0441 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445;<\/li>\n<li>\u0437\u0430\u0434\u0430\u0447\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. SVM \u0434\u0430\u0435\u0442 \u043d\u0435\u043f\u043b\u043e\u0445\u043e\u0439 baseline ([preprocessing] + [TF-iDF] + [SVM]), \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u0430\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0432\u0435\u0440\u0442\u043e\u0447\u043d\u044b\u0445\/\u0440\u0435\u043a\u0443\u0440\u0440\u0435\u043d\u0442\u043d\u044b\u0445 \u043d\u0435\u0439\u0440\u043e\u043d\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0439 (\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430). \u041e\u0442\u043b\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d <a href=\"https:\/\/habr.com\/ru\/post\/270449\/\">\u0442\u0443\u0442, &quot;\u0427\u0430\u0441\u0442\u044c 3. \u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0442\u0440\u044e\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u043e\u0431\u0443\u0447\u0430\u0435\u043c&quot;<\/a>;<\/li>\n<li>\u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u0432\u044f\u0437\u043a\u0430 [feature engineering] + [SVM] + [kernel] &quot;\u0432\u0441\u0435 \u0435\u0449\u0435 \u0442\u043e\u0440\u0442&quot;;<\/li>\n<li>\u0442\u0430\u043a \u043a\u0430\u043a Hinge loss \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e, \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c \u0432 Vowpal Wabbit (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e).<\/li>\n<\/ul>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u041c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430:<\/strong><\/p>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043f\u043e\u0440\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043d\u0430 \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u043e\u0432:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u041c\u0435\u0442\u043e\u0434 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 (Relevance Vector Machine, RVM)<\/li>\n<li>1-norm SVM (LASSO SVM)<\/li>\n<li>Doubly Regularized SVM (ElasticNet SVM)<\/li>\n<li>Support Features Machine (SFM)<\/li>\n<li>Relevance Features Machine (RFM)<\/li>\n<\/ul>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u043d\u0430 \u0442\u0435\u043c\u0443 SVM:<\/strong><\/p>\n<p>  <\/p>\n<ol>\n<li><a href=\"http:\/\/www.ccas.ru\/voron\/download\/SVM.pdf\">\u0422\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u043b\u0435\u043a\u0446\u0438\u0438 \u041a.\u0412.\u0412\u043e\u0440\u043e\u043d\u0446\u043e\u0432\u0430<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/esokolov\/ml-course-hse\/tree\/master\/2017-spring\/lecture-notes\">\u041a\u043e\u043d\u0441\u043f\u0435\u043a\u0442\u044b \u0415.\u0421\u043e\u043a\u043e\u043b\u043e\u0432\u0430<\/a> \u2014 14,15,16<\/li>\n<li>\u041d\u0430 \u0445\u0430\u0431\u0440\u0435 \u0435\u0441\u0442\u044c 2 \u0441\u0442\u0430\u0442\u044c\u0438, \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u043d\u044b\u0435 svm:<br \/> \n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/105220\/\">2010 \u0433.<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/428503\/\">2018 \u0433.<\/a><\/li>\n<\/ul>\n<\/li>\n<li>\u041d\u0430 \u0433\u0438\u0442\u0445\u0430\u0431\u0435 \u043c\u043e\u0433\u0443 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c 2 \u043a\u0440\u0443\u0442\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 SVM \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0430\u043c:<br \/> \n<ul>\n<li><a href=\"https:\/\/github.com\/rushter\/MLAlgorithms\">MLAlgorithms<\/a> \u043e\u0442 \u043e\u0442\u0435\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430<\/li>\n<li><a href=\"https:\/\/github.com\/eriklindernoren\/ML-From-Scratch\">ML-From-Scratch<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><cut><\/cut>  <\/p>\n<p><strong>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<p>  <\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u043e\u0435 \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435! \u0411\u0443\u0434\u0443 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d \u0437\u0430 \u043b\u044e\u0431\u044b\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u043e\u0442\u0437\u044b\u0432\u044b \u0438 \u0441\u043e\u0432\u0435\u0442\u044b.<br \/>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430\u0439\u0434\u0435\u0442\u0435 <a href=\"https:\/\/github.com\/Laggg\/SVM-by-hand\/blob\/master\/SVM_by_hand.ipynb\">\u043d\u0430 \u043c\u043e\u0435\u043c \u0433\u0438\u0442\u0445\u0430\u0431\u0435<\/a>.<\/p>\n<p>  <\/p>\n<p>p.s. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e <a href=\"https:\/\/habr.com\/ru\/users\/yorko\/\" class=\"user_link\">yorko<\/a> \u0437\u0430 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u044e &quot;\u0443\u0433\u043b\u043e\u0432&quot;. \u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0410\u043b\u0435\u043a\u0441\u0435\u044e \u0421\u0438\u0437\u044b\u0445 \u2014 \u0444\u0438\u0437\u0442\u0435\u0445\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u0432\u043b\u043e\u0436\u0438\u043b\u0441\u044f \u0432 \u043a\u043e\u0434.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/ods\/blog\/484148\/\"> https:\/\/habr.com\/ru\/company\/ods\/blog\/484148\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/ods\/blog\/484148\/\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0432\u0441\u0435\u043c, \u043a\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u043b \u043f\u0443\u0442\u044c ML-\u0441\u0430\u043c\u0443\u0440\u0430\u044f!<\/p>\n<p>  <\/p>\n<p><b>\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435:<\/b><\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u043e\u043f\u043e\u0440\u043d\u044b\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 (<i>\u0430\u043d\u0433\u043b. SVM, Support Vector Machine<\/i>) \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438. \u0411\u0443\u0434\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0432\u044b\u0432\u043e\u0434 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0435\u0433\u043e \u0432\u0435\u0441\u043e\u0432 \u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438. \u041d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/50c\/036\/e72\/50c036e72210eebc108541ad3d104d37.svg\" alt=\"$Iris$\" data-tex=\"inline\"><\/math> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441 \u043b\u0438\u043d\u0435\u0439\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438\/\u043d\u0435\u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043c\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 <math><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/formulas\/0ba\/d21\/a1f\/0bad21a1feb1341dc1267f2bceaaf5f6.svg\" alt=\"$R^2$\" data-tex=\"inline\"><\/math> \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f\/\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0430. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0443\u0442 \u043e\u0437\u0432\u0443\u0447\u0435\u043d\u044b \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430, \u0435\u0433\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/th\/qo\/am\/thqoam8wiyi5gepkmu86xbx6md0.png\" alt=\"image\"><br \/>  <i>\u0420\u0438\u0441\u0443\u043d\u043e\u043a 1. \u0424\u043e\u0442\u043e \u0446\u0432\u0435\u0442\u043a\u0430 \u0438\u0440\u0438\u0441\u0430 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432<\/i><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-297568","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297568","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=297568"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297568\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}