{"id":354635,"date":"2024-05-20T22:52:22","date_gmt":"2024-05-20T22:52:22","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=354635"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=354635","title":{"rendered":"<span>\u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0432 pySpark: \u043e\u0442 \u0441\u0435\u043c\u0435\u0447\u043a\u0430 \u0434\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/532\/af8\/fc1\/532af8fc10dd5d4c1f91cb84abb69dfc.PNG\" width=\"727\" height=\"421\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440! <\/p>\n<p> \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0430 \u0441\u0432\u044f\u0437\u0438 \u041f\u043e\u0440\u0442\u043d\u043e\u0432 \u041a\u043b\u0438\u043c, \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a <a href=\"https:\/\/newtechaudit.ru\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 NTA<\/a>.<\/p>\n<p>\u0412\u00a0\u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0434\u043b\u044f\u00a0\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u043d\u043e\u00a0\u0432\u00a0\u0442\u043e\u00a0\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435\u00a0\u2014 \u0434\u0435\u0440\u0435\u0432\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u0435\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439\u00a0\u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043b\u0435\u0441\u0430\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0438 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e PySpark MLib.<\/p>\n<details class=\"spoiler\">\n<summary>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u043f\u043e\u0441\u0442\u0443<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><a href=\"#%D1%87%D1%82%D0%BE\" rel=\"noopener noreferrer nofollow\">\u0427\u0442\u043e\u00a0\u0442\u0430\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BF%D0%BE%D0%B4%D0%B3%D0%BE%D1%82%D0%BE%D0%B2%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BF%D0%B5%D1%80%D0%B2%D0%BE%D0%B5\" rel=\"noopener noreferrer nofollow\">\u041d\u0430\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BE%D0%BF%D1%82%D0%B8%D0%BC%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" rel=\"noopener noreferrer nofollow\">\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%81%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D1%8B%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%81%D1%80%D0%B0%D0%B2%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%B2%D1%8B%D0%B2%D0%BE%D0%B4\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0432\u043e\u0434<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u00a0\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u00a0PySpark MLib \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u044e \u043d\u0430\u0438\u0432\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0431\u0443\u0434\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0443\u0442\u0435\u043c \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>\u0412\u00a0\u043a\u043e\u043d\u0446\u0435 \u0437\u0430\u0441\u0435\u044e \u0446\u0435\u043b\u044b\u0439 \u043b\u0435\u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0438 \u043d\u0435\u00a0\u0437\u0430\u0431\u0443\u0434\u0443 \u043f\u0440\u043e\u00a0\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439?<\/h2>\n<p><a class=\"anchor\" name=\"%D1%87%D1%82%D0%BE\" id=\"\u0447\u0442\u043e\"><\/a><\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f\u00a0\u043f\u0435\u0440\u0432\u043e\u043f\u0440\u043e\u0445\u043e\u0434\u0446\u0435\u0432. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441\u00a0\u0434\u0430\u043d\u043d\u044b\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c, \u0442\u043e \u0441\u043c\u0435\u043b\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u0435 \u043a\u00a0<a href=\"#%D0%BF%D0%BE%D0%B4%D0%B3%D0%BE%D1%82%D0%BE%D0%B2%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0441\u0442\u0430<\/a>.<\/p>\n<h3>\u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/h3>\n<p>\u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u00a0\u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430: <\/p>\n<ul>\n<li>\n<p>\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u043a\u00a0\u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c \u0432\u00a0\u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0432\u00a0\u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430\u0445 \u0431\u0435\u0437\u00a0\u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043b\u0438\u00a0\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0438 \u0433\u043b\u0430\u0432\u043d\u043e\u0435\u00a0\u2014 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f\u00a0\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u00a0\u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435\u00a0\u0436\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f, \u0432\u043e\u043f\u043b\u043e\u0449\u0435\u043d\u043d\u044b\u0435 \u0432\u00a0\u0434\u0435\u0440\u0435\u0432\u044c\u044f\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043d\u0435\u044f\u0432\u043d\u043e \u0432\u00a0\u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u0440\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u00ab\u0434\u0430\/\u043d\u0435\u0442\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a\u00a0\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0443 \u0431\u0443\u0434\u0435\u0442\u00a0\u043b\u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0430\u00a0\u0443\u043b\u0438\u0446\u0435 \u0438\u043b\u0438\u00a0\u043d\u0435\u0442.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1ea\/0a4\/7ae\/1ea0a47ae1630f4570ef5d471bb460cb.png\" width=\"456\" height=\"321\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1ea\/0a4\/7ae\/1ea0a47ae1630f4570ef5d471bb460cb.png\"\/><\/figure>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0430\u043c\u0430 \u00ab\u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0442\u00bb \u044d\u0442\u0438 \u0440\u0430\u0437\u0432\u0438\u043b\u043a\u0438. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0432\u0438\u043b\u043e\u043a, \u0442\u0435\u043c \u0442\u043e\u0447\u043d\u0435\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u00a0\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e\u00a0\u043d\u0430\u00a0\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u043e\u043d\u0430 \u043d\u0430\u0447\u043d\u0435\u0442 \u0447\u0430\u0449\u0435 \u043e\u0448\u0438\u0431\u0430\u0442\u044c\u0441\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u0435\u043d\u0438\u044f, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u043a\u0430\u043a\u00a0\u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435.<\/p>\n<h3>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439    <\/h3>\n<p>\u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043e\u0431\u043e\u0431\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u00a0\u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0449\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0438\u0441\u043a \u043f\u0435\u0440\u0435\u043e\u0441\u043d\u0430\u0449\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432, \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0439 \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u00a0\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/companies\/productstar\/articles\/523044\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. <\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D0%BE%D0%B4%D0%B3%D0%BE%D1%82%D0%BE%D0%B2%D0%BA%D0%B0\" id=\"\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430\"><\/a><\/p>\n<p>\u0414\u043b\u044f\u00a0\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u00a0PySpark MLib \u043d\u0430\u0434\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u00a0\u0433\u043e\u043b\u043e\u0432\u0435, \u0447\u0442\u043e\u00a0\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 <strong>\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440<\/strong>. \u0418 \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u043a\u0430\u043a\u043e\u0439 \u0443\u00a0\u0432\u0430\u0441 \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439, \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0439, \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u044b\u0439).<\/p>\n<h3>\u0414\u0430\u0442\u0430\u0441\u0435\u0442<\/h3>\n<p>\u0414\u043b\u044f\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0443 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<a href=\"https:\/\/ttps:\/\/www.kaggle.com\/datasets\/ruthgn\/bank-marketing-data-set\" rel=\"noopener noreferrer nofollow\"> Bank Marketing<\/a>. \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u043f\u043e\u00a0\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0437\u0432\u043e\u043d\u043a\u043e\u0432 \u043f\u043e\u0440\u0442\u0443\u0433\u0430\u043b\u044c\u0441\u043a\u043e\u0439 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 (2008\u00a0\u2014 2010\u00a0\u0433\u043e\u0434\u0430\u0445) \u0438 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f\u00a0\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438: \u0441\u0434\u0435\u043b\u0430\u0435\u0442\u00a0\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 term deposit (\u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0432\u043a\u043b\u0430\u0434) \u0438\u043b\u0438\u00a0\u043d\u0435\u0442.<\/p>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (features):<\/strong><\/p>\n<ul>\n<li>\n<p><strong>age<\/strong> (numeric);<\/p>\n<\/li>\n<li>\n<p><strong>job<\/strong>: type of job (categorical: &#171;admin&#187;, &#171;unknown&#187;, &#171;unemployed&#187;, &#171;management&#187;, &#171;housemaid&#187;, &#171;entrepreneur&#187;, &#171;student&#187;, &#171;blue-collar&#187;, &#171;self-employed&#187;, &#171;retired&#187;, &#171;technician&#187;, &#171;services&#187;);<\/p>\n<\/li>\n<li>\n<p><strong>marital<\/strong>: marital status (categorical: &#171;married&#187;, &#171;divorced&#187;, &#171;single&#187;; note: &#171;divorced&#187; means divorced or widowed);<\/p>\n<\/li>\n<li>\n<p><strong>education<\/strong>: (categorical: &#171;unknown&#187;, &#171;secondary&#187;, &#171;primary&#187;, &#171;tertiary&#187;);<\/p>\n<\/li>\n<li>\n<p><strong>default<\/strong>: has credit in default? (binary: &#171;yes&#187;, &#171;no&#187;);<\/p>\n<\/li>\n<li>\n<p><strong>balance<\/strong>: average yearly balance, in euros (numeric);<\/p>\n<\/li>\n<li>\n<p><strong>housing<\/strong>: has housing loan? (binary: &#171;yes&#187;, &#171;no&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>loan<\/strong>: has personal loan? (binary: &#171;yes&#187;, &#171;no&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>contact<\/strong>: contact communication type (categorical: &#171;unknown&#187;, &#171;telephone&#187;, &#171;cellular&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>day<\/strong>: last contact day of the month (numeric); <\/p>\n<\/li>\n<li>\n<p><strong>month<\/strong>: last contact month of year (categorical: &#171;jan&#187;, &#171;feb&#187;, &#171;mar&#187;, &#8230;, &#171;nov&#187;, &#171;dec&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>duration<\/strong>: last contact duration, in seconds (numeric); <\/p>\n<\/li>\n<li>\n<p><strong>campaign<\/strong>: number of contacts performed during this campaign and for this client (numeric, includes last contact); <\/p>\n<\/li>\n<li>\n<p><strong>pdays<\/strong>: number of days that passed by after the client was last contacted from a previous campaign (numeric, -1 means client was not previously contacted);<\/p>\n<\/li>\n<li>\n<p><strong>previous<\/strong>: number of contacts performed before this campaign and for this client (numeric);<\/p>\n<\/li>\n<li>\n<p><strong>poutcome<\/strong>: outcome of the previous marketing campaign (categorical: &#171;unknown&#187;, &#171;other&#187;, &#171;failure&#187;, &#171;success&#187;).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (target):<\/strong> <strong>y <\/strong>&#8212; has the client subscribed a term deposit? (binary: &#171;yes&#187;, &#171;no&#187;) <\/p>\n<p>\u0421 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0441\u044f, \u043f\u0435\u0440\u0435\u0445\u043e\u0436\u0443 \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<h3>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044e spark \u0441\u0435\u0441\u0441\u0438\u044e:<\/p>\n<pre><code class=\"python\">from pyspark.sql import functions as F import pyspark.sql.types as T import pandas as pd  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043f\u0430\u0440\u043a \u0441\u0435\u0441\u0441\u0438\u044e spark = SparkSession \\     .builder \\     .config(\"spark.ui.enabled\", \"true\") \\     .config(\"spark.driver.memory\", \"8g\") \\     .config(\"spark.executor.instances\", \"4\") \\     .config(\"spark.executor.cores\", \"4\") \\     .config(\"spark.executor.memory\", \"6g\") \\     .config(\"spark.executor.memoryOverhead\", \"200m\") \\     .config(\"spark.dynamicAllocation.enabled\", \"true\") \\     .config(\"spark.dynamicAllocation.shuffleTracking.enabled\", \"true\") \\     .config(\"spark.sql.parquet.compression.codec\", \"snappy\") \\     .config(\"spark.sql.execution.arrow.pyspark.enabled\", \"true\") \\     .getOrCreate()<\/code><\/pre>\n<p>\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u044e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 pyspark.Dataframe():<\/p>\n<pre><code class=\"python\">data_raw = spark.read.option(\"inferSchema\", \"true\").csv(\"bank-full.csv\", sep=';',encoding = \"UTF-8\", header = True) data_raw.printSchema()<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/dfd\/daa\/b6e\/dfddaab6e9675240591ef0eacef77a73.png\" width=\"338\" height=\"343\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/dfd\/daa\/b6e\/dfddaab6e9675240591ef0eacef77a73.png\"\/><\/figure>\n<p>\u0414\u043b\u044f\u00a0\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442\u00a0type string. \u041d\u0435\u0442, \u043d\u0435\u00a0\u043f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435, \u0447\u0442\u043e\u00a0\u044f \u0432\u044b\u0440\u0435\u0436\u0443 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0445\u043e\u0442\u044f\u00a0\u0431\u044b\u043b\u043e\u00a0\u0431\u044b \u0441\u043b\u0430\u0432\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442\u00a0target (\u0448\u0443\u0442\u043a\u0430). \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e\u00a0target \u0432\u00a0\u043c\u043e\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435\u00a0\u2014 \u044d\u0442\u043e \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u00aby\u00bb.<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0434\u043b\u044f\u00a0\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043e\u0442\u00a0string \u043a\u00a0integer, \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u043f\u0430\u0440\u043e\u0447\u043a\u0443.<\/p>\n<h4>\u041f\u0435\u0440\u0432\u044b\u0439: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c udf \u0444\u0443\u043d\u043a\u0446\u0438\u0438   <\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u00a0sparkDataframe, \u043a\u0430\u043a\u00a0\u0441\u00a0pandasDataframe, \u043d\u043e\u00a0\u0431\u0435\u0437\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f toPandas(), \u0447\u0442\u043e\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043a\u0443\u0447\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043d\u0435\u0440\u0432\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a.<\/p>\n<pre><code class=\"python\"># \u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 (month \u0438 y) \u0438\u0437 \u0442\u0438\u043f\u0430 string \u0432 \u0442\u0438\u043f integer  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c udf \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \"\"\"Transforms yes\/no to digit 1\/0\"\"\" @F.pandas_udf(T.IntegerType()) def y_to_digit(y: pd.Series) -> pd.Series:     return (y == 'yes')  \"\"\"Transforms months to digit\"\"\" @F.pandas_udf(T.IntegerType()) def month_to_digit(month: pd.Series) -> pd.Series:     months = {'jan': 1, 'feb': 2, 'mar': 3, 'apr': 4, 'may': 5, 'jun': 6, 'jul': 7, 'aug': 8, 'sep': 9, 'oct': 10, 'nov': 11, 'dec': 12}     return month.map(months)  # \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 data_after_udf = data_raw.withColumn('y', y_to_digit(F.col('y'))).withColumn('month', month_to_digit(F.col('month'))) data_after_udf.show(20)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8c4\/35c\/c71\/8c435cc7152c2e5b3e839821146e1b92.png\" width=\"1073\" height=\"152\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8c4\/35c\/c71\/8c435cc7152c2e5b3e839821146e1b92.png\"\/><\/figure>\n<h4>\u0412\u0442\u043e\u0440\u043e\u0439: OneHotEncoder \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430    <\/h4>\n<p>\u0414\u043b\u044f\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c \u0438 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c pipeline. \u042f \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e \u043d\u0435\u043a\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u00a0\u0441\u043f\u0438\u0441\u043a\u0435 stages, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c pipeline \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442.<\/p>\n<pre><code class=\"python\">from pyspark.ml.feature import OneHotEncoder, StringIndexer, VectorAssembler  # \u0414\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 pipeline # stages \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 stages = []<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e \u0432\u0441\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 categoricalColumns = ['job', 'marital', 'education', 'default', 'housing', 'loan', 'contact', 'poutcome'] for categoricalCol in categoricalColumns:     stringIndexer = StringIndexer(inputCol = categoricalCol, outputCol = categoricalCol + 'Index', handleInvalid = 'keep')     encoder = OneHotEncoder(inputCol = stringIndexer.getOutputCol(), outputCol = categoricalCol + \"classVec\")     stages += [stringIndexer, encoder]<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0435\u0440\u0443 \u0432\u0441\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0432 \u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 PySpark MLib.<\/p>\n<pre><code class=\"python\"># C\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432 \u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440 assembler numericCols = ['age', 'balance', 'day', 'month', 'duration', 'campaign', 'pdays', 'previous'] assemblerInputs = [c + \"classVec\" for c in categoricalColumns] + numericCols assembler = VectorAssembler(inputCols = assemblerInputs, outputCol = \"features\") stages += [assembler]<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u044e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u042f \u0441\u043e\u0437\u0434\u0430\u044e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 pipeline, \u043d\u043e \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0432 \u043d\u0435\u0433\u043e \u043d\u0438\u043a\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041c\u0435\u0442\u043e\u0434 fit \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439 udf \u0444\u0443\u043d\u043a\u0446\u0438\u0439. <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043d\u0430 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"python\"># \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u0434\u043e\u043f. \u0440\u0430\u0437\u0434\u0435\u043b) from pyspark.ml import Pipeline  pipeline = Pipeline(stages=stages) model = pipeline.fit(data_after_udf) how_transform_data = model.transform(data_after_udf) how_transform_data.select(F.col('job'), F.col('jobclassVec'), F.col('features')).show(10, truncate = False)<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/af2\/b0d\/c38\/af2b0dc38909d0c7891f4b31865a138e.png\" width=\"1243\" height=\"274\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/af2\/b0d\/c38\/af2b0dc38909d0c7891f4b31865a138e.png\"\/><\/figure>\n<p>\u0412\u0441\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u044f\u0442\u0441\u044f \u0432\u00a0sparse \u0432\u0435\u043a\u0442\u043e\u0440\u0430. (\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, job \u2192 jobclassVec).<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (features) \u2192 sparse vector \u0441\u00a0\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e 40.<\/p>\n<h3>\u0414\u0435\u043b\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 train \u0438 test<\/h3>\n<pre><code class=\"python\"># \u0414\u0435\u043b\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438 (train_data, test_data) = data_after_udf.randomSplit([0.9, 0.1])<\/code><\/pre>\n<h2>\u041d\u0430\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D0%B5%D1%80%D0%B2%D0%BE%D0%B5\" id=\"\u043f\u0435\u0440\u0432\u043e\u0435\"><\/a><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0445\u043e\u0436\u0443 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"python\"># \u0418\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 from pyspark.ml.classification import DecisionTreeClassifier  # labelCol \u2013 target, featuresCol \u2013 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, predictionCol \u2013 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c classifier_tree = DecisionTreeClassifier(seed = 1234, labelCol=\"y\", featuresCol=\"features\", predictionCol=\"prediction\") stages += [classifier_tree]<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 pipeline \u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438: <\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441\u043e \u0441\u0442\u0430\u0434\u0438\u044f\u043c\u0438 stages from pyspark.ml import Pipeline  pipeline_first_tree = Pipeline(stages = stages)  # \u0422\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c model_first_tree = pipeline_first_tree.fit(train_data)  # \u0414\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 predictions_first_tree = model_first_tree.transform(test_data)<\/code><\/pre>\n<p>\u041e\u0446\u0435\u043d\u044e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438. <\/p>\n<p>MulticlassClassificationEvaluator \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438. \u042f \u0431\u0443\u0434\u0443 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 (accuracy).<\/p>\n<pre><code class=\"python\"># \u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 from pyspark.ml.evaluation import MulticlassClassificationEvaluator  # setMetricName \u2013 \u0442\u0438\u043f \u043c\u0435\u0442\u0440\u0438\u043a\u0438 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2013 \"\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\") multiclassEval = MulticlassClassificationEvaluator(). \\     setLabelCol(\"y\"). \\     setPredictionCol(\"prediction\"). \\     setMetricName(\"accuracy\")  # \u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 multiclassEval.evaluate(predictions_first_tree) # 0.703<\/code><\/pre>\n<h2>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BE%D0%BF%D1%82%D0%B8%D0%BC%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" id=\"\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\"><\/a><\/p>\n<p>\u041f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0432 \u0435\u0451 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u0414\u043b\u044f\u00a0\u044d\u0442\u043e\u0433\u043e \u044f \u0432\u044b\u044f\u0441\u043d\u044e, \u043a\u0430\u043a\u0438\u0435 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0435\u0441\u0442\u044c \u0443\u00a0\u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f\u00a0\u0438\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u0430.<\/p>\n<h3>\u0413\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439   <\/h3>\n<p>\u0412\u0441\u0435 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.ensemble.RandomForestClassifier.html\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>.<\/p>\n<p>\u042f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u0430 (<strong>maxDepth<\/strong>)\u00a0\u2014 \u044d\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043c\u0435\u0442 \u0434\u043b\u044f\u00a0\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u042d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043d\u043e\u0432 (\u0440\u0430\u0437\u0432\u0438\u043b\u043e\u043a) \u0432\u00a0\u0434\u0435\u0440\u0435\u0432\u0435 (<strong>maxBins<\/strong>).<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0440\u0430 \u043f\u0440\u0438\u043c\u0435\u0441\u0438 (<strong>impurity<\/strong>)\u00a0\u2014 \u0445\u043e\u0440\u043e\u0448\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u0435\u043b\u044f\u0442 \u0446\u0435\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u00a0\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0434\u043d\u043e\u0440\u043e\u0434\u043d\u044b\u0435 \u0438\u043b\u0438 \u00ab\u0447\u0438\u0441\u0442\u044b\u0435\u00bb \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430. \u0412\u044b\u0431\u043e\u0440 \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0435\u0433\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0435\u0447\u0438\u0441\u0442\u043e\u0442\u044b \u0434\u0432\u0443\u0445 \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442. \u0412\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u0432\u0435 \u043c\u0435\u0440\u044b \u043f\u0440\u0438\u043c\u0435\u0441\u0438: gini \u0438 entropy.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 (<strong>minInfoGain)<\/strong>\u00a0\u2014 \u044d\u0442\u043e \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0438\u043b\u0438\u00a0\u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0441\u0435\u0439 \u0434\u043b\u044f\u00a0\u043f\u0440\u0430\u0432\u0438\u043b \u043f\u0440\u0438\u043d\u044f\u0442\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439\u2011\u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f   <\/h2>\n<p>\u0414\u043b\u044f\u00a0\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0443 \u00ab<a href=\"#%D0%BF%D0%B5%D1%80%D0%B2%D0%BE%D0%B5\" rel=\"noopener noreferrer nofollow\">\u041d\u0430\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e<\/a>\u00bb:<\/p>\n<pre><code class=\"python\"># \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0443 \u0441\u043e\u0437\u0434\u0430\u0451\u043c pipeline pipeline_with_optimization = pipeline_first_tree<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432 ParamGridBuilder \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u043d\u044f \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b from pyspark.ml.tuning import ParamGridBuilder  paramGrid_with_optimization = ParamGridBuilder(). \\     addGrid(classifier_tree.impurity, [\"gini\", \"entropy\"]). \\     addGrid(classifier_tree.maxDepth, [8, 10]). \\     addGrid(classifier_tree.maxBins, [20, 30]). \\     addGrid(classifier_tree.minInfoGain, [0.0]). \\     build() # impurity - \u041f\u0440\u0438\u0441\u043c\u0435\u0441\u044c # maxDepth - \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0433\u043b\u0443\u0431\u0438\u043d\u0430 \u0434\u0435\u0440\u0435\u0432\u0430 # maxBins - \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u043d\u043e\u0432 (\u0440\u043e\u0437\u0432\u0438\u043b\u043e\u043a) \u0432 \u0434\u0435\u0440\u0435\u0432\u0435 # minInfoGain- \u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043c \u0432\u00a0TrainValidationSplit \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 (pipeline_with_optimization), \u043c\u0435\u0442\u0440\u0438\u043a\u0443 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (multiclassEval), \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 (paramGrid_with_optimization) \u0438 \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435, \u043d\u0430\u00a0\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0437\u043e\u0431\u044c\u0451\u0442\u0441\u044f train (trainRatio), \u0442.\u00a0\u0435. dataset train \u0432\u043e\u00a0\u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430\u00a0\u0434\u0432\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438: \u043d\u0430\u00a0\u043e\u0434\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0443\u0447\u0430\u0442\u044c\u0441\u044f, \u0430\u00a0\u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<pre><code class=\"python\"># \u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442) from pyspark.ml.tuning import TrainValidationSplit  # estimator - \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441 \u043b\u043e\u0433\u0438\u0447\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 # evaluator - \u043f\u043e \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 # estimatorParamMaps - \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u043c \u0432\u0430\u0440\u044c\u0438\u0440\u043e\u0432\u0430\u0442\u044c # trainRatio - \u0441 \u043a\u0430\u043a\u0438\u043c \u0441\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u044c\u0451\u0442\u044c\u0441\u044f train \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f validator = TrainValidationSplit(seed=1234, estimator=pipeline_with_optimization, evaluator=multiclassEval, estimatorParamMaps=paramGrid_with_optimization, trainRatio=0.9) validator_with_optimization = validator.fit(train_data)<\/code><\/pre>\n<p>\u0415\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0442\u0430\u043a\u0436\u0435 \u0438\u0445 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<pre><code class=\"python\">metrics = validator_with_optimization.validationMetrics #\u043e\u0446\u0435\u043d\u043a\u0438 params = validator_with_optimization.getEstimatorParamMaps() #\u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b metrics_and_params = list(zip(metrics, params)) metrics_and_params.sort(key=lambda x: x[0], reverse=True)  metrics_and_params<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/344\/562\/a0a\/344562a0ad1c35789b3ab8df1b87a8aa.png\" width=\"1474\" height=\"311\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/344\/562\/a0a\/344562a0ad1c35789b3ab8df1b87a8aa.png\"\/><\/figure>\n<p>\u0421\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 bestModel \u00ab\u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u044e\u00bb \u043b\u0443\u0447\u0448\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437\u00a0\u043d\u0430\u0431\u043e\u0440\u0430.<\/p>\n<pre><code class=\"python\"># \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043b\u0443\u0447\u0448\u0435\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 best_model = validator_with_optimization.bestModel multiclassEval.evaluate(best_model.transform(test_data)) # 0.899<\/code><\/pre>\n<h2>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/h2>\n<p><a class=\"anchor\" name=\"%D1%81%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D1%8B%D0%B5\" id=\"\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435\"><\/a><\/p>\n<p>\u0411\u044b\u043b\u043e\u00a0\u0431\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u00a0\u043e\u0434\u043d\u043e \u0434\u0435\u0440\u0435\u0432\u043e, \u0430\u00a0\u043c\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432, \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437\u00a0\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u0435\u0442 \u0440\u0430\u0437\u0443\u043c\u043d\u044b\u0435, \u043d\u043e\u00a0\u0440\u0430\u0437\u043d\u044b\u0435 \u0438 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u043e\u0446\u0435\u043d\u043a\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0446\u0435\u043b\u0435\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0418\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0439 \u0441\u0440\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u0434\u043e\u043b\u0436\u0435\u043d\u00a0\u0431\u044b\u0442\u044c \u0431\u043b\u0438\u0437\u043e\u043a \u043a\u00a0\u0438\u0441\u0442\u0438\u043d\u043d\u043e\u043c\u0443 \u043e\u0442\u0432\u0435\u0442\u0443 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0434\u0435\u0440\u0435\u0432\u0430. \u042d\u0442\u043e \u0435\u0441\u0442\u044c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430\u00a0\u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0432\u0437\u0432\u0435\u0448\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432. \u0414\u043b\u044f\u00a0\u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0446\u0435\u043b\u0438 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442\u00a0\u0431\u044b\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0433\u043e\u043b\u043e\u0441\u043e\u0432 \u0438\u043b\u0438\u00a0\u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0435 \u043d\u0430\u00a0\u0441\u0440\u0435\u0434\u043d\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e\u0441\u0442\u0435\u0439, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u044f\u043c\u0438. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430, \u043a\u0430\u043a\u00a0\u0438 \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u044e, \u0438 \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u043b\u0435\u0441\u0430 \u0432\u00a0\u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u0447\u0438\u0441\u043b\u043e, \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u0430\u0436\u0434\u044b\u043c \u0434\u0435\u0440\u0435\u0432\u043e\u043c.<\/p>\n<p>\u0425\u043e\u0442\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0449\u043d\u044b\u043c \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438, \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043d\u043e\u0432\u043e\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u00a0\u0442\u043e\u043c, \u0447\u0442\u043e\u00a0\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0438\u0447\u0435\u043c \u043d\u0435\u00a0\u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u00a0\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0435\u0440\u0435\u0432\u0430.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0437\u0430\u043c\u0435\u043d\u0438\u043c \u0432 stages \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0433\u043e \u043b\u0435\u0441\u0430:<\/p>\n<pre><code class=\"python\">from pyspark.ml.classification import RandomForestClassifier  # \u041f\u043e\u043c\u0435\u043d\u044f\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441 \u0434\u0435\u0440\u0435\u0432\u0430 \u043d\u0430 \u043b\u0435\u0441 classifier_forest = RandomForestClassifier().setLabelCol(\"y\").setFeaturesCol(\"features\").setPredictionCol(\"prediction\")  stages_new = stages stages_new.pop(-1) # \u041a\u0438\u043a\u0430\u0435\u043c \u0434\u0435\u0440\u0435\u0432\u043e  stages_new += [classifier_forest]  pipeline_forest = Pipeline(stages = stages_new)<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440: numTrees \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432 \u043b\u0435\u0441\u0435:<\/p>\n<pre><code class=\"python\"># \u041d\u043e\u0432\u044b\u0439 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 numTrees \u2013 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432  paramGrid_forest = ParamGridBuilder(). \\     addGrid(classifier_forest.impurity, [\"gini\"]). \\     addGrid(classifier_forest.maxDepth, [8]). \\     addGrid(classifier_forest.maxBins, [20]). \\     addGrid(classifier_forest.minInfoGain, [0.0]). \\     addGrid(classifier_forest.numTrees, [2, 4, 6]). \\     build() <\/code><\/pre>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0440\u0430\u0437\u0434\u0435\u043b\u0443 \u0442\u0440\u0435\u043d\u0438\u0440\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0443\u044e:<\/p>\n<pre><code class=\"python\"># \u041f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043a\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0439 \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442) validator = TrainValidationSplit(seed=1234, estimator=pipeline_forest, evaluator=multiclassEval, estimatorParamMaps=paramGrid_forest, trainRatio=0.9) validator_forest = validator.fit(train_data)  # \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u044e  RandomForestClassifier() \u0438\u0437 PipelineModel best_model_forest = validator_forest.bestModel multiclassEval.evaluate(best_model_forest.transform(test_data)) #0.9501<\/code><\/pre>\n<h2>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/h2>\n<p><a class=\"anchor\" name=\"%D1%81%D1%80%D0%B0%D0%B2%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5\" id=\"\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\"><\/a><\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u043c \u043c\u043e\u0434\u0435\u043b\u044c randomizer, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441. \u0411\u0443\u0434\u0443 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u043b\u0430\u0434\u0430\u0435\u0442 \u043d\u0430\u0438\u0445\u0443\u0434\u0448\u0435\u0439 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\u044e.<\/p>\n<pre><code class=\"python\">from pyspark.sql import DataFrame from pyspark.sql.functions import col  def class_probabilities(data):     total = data.count()     return data.groupBy(\"y\").count().orderBy(\"y\").select(col(\"count\").cast(T.DoubleType())).\\         withColumn(\"count_proportion\", col(\"count\")\/total).\\         select(\"count_proportion\").collect()  train_prior_probabilities = class_probabilities(train_data) #\u0434\u043e\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e target \u0432 total test_prior_probabilities = class_probabilities(test_data)  train_prior_probabilities = [p[0] for p in train_prior_probabilities] test_prior_probabilities = [p[0] for p in test_prior_probabilities]  print(sum([train_p * cv_p for train_p, cv_p in zip(train_prior_probabilities, test_prior_probabilities)])) #0.3796<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b9a\/685\/827\/b9a685827a6d9ad478e730ea73b6b431.PNG\" width=\"720\" height=\"259\"\/><\/figure>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p><a class=\"anchor\" name=\"%D0%B2%D1%8B%D0%B2%D0%BE%D0%B4\" id=\"\u0432\u044b\u0432\u043e\u0434\"><\/a><\/p>\n<p>\u0414\u043b\u044f\u00a0\u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0440\u0438\u043a \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0432\u00a0PySpark \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e. \u0421\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430\u00a0\u0442\u043e, \u0447\u0442\u043e\u00a0\u043a\u0430\u0436\u0434\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0433\u0438\u043f\u0435\u0440\u0435\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0439 \u043b\u0435\u0441 \u0432\u00a0\u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b, \u043d\u043e\u00a0\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432.<\/p>\n<p>P.\u00a0S. \u041d\u0430\u00a0\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u043f\u043e\u0441\u0442\u0430 \u043c\u0435\u043d\u044f \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u043b\u0430 \u043a\u043d\u0438\u0433\u0430 \u0438\u0437\u0434\u0430\u0442\u0435\u043b\u044c\u0441\u0442\u0432\u0430 O&#8217;Reilly \u00abAdvanced Analytics with PySpark\u00bb.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/760444\/\"> https:\/\/habr.com\/ru\/articles\/760444\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440! <\/p>\n<p> \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043d\u0430 \u0441\u0432\u044f\u0437\u0438 \u041f\u043e\u0440\u0442\u043d\u043e\u0432 \u041a\u043b\u0438\u043c, \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a <a href=\"https:\/\/newtechaudit.ru\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 NTA<\/a>.<\/p>\n<p>\u0412\u00a0\u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u00a0\u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0434\u043b\u044f\u00a0\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f, \u043d\u043e\u00a0\u0432\u00a0\u0442\u043e\u00a0\u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435\u00a0\u2014 \u0434\u0435\u0440\u0435\u0432\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0430\u00a0\u0442\u0430\u043a\u0436\u0435 \u0435\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0435\u0439\u00a0\u2014 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u043b\u0435\u0441\u0430\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0438 \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u00a0\u043f\u043e\u043c\u043e\u0449\u044c\u044e PySpark MLib.<\/p>\n<details class=\"spoiler\">\n<summary>\u041d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f \u043f\u043e \u043f\u043e\u0441\u0442\u0443<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><a href=\"#%D1%87%D1%82%D0%BE\" rel=\"noopener noreferrer nofollow\">\u0427\u0442\u043e\u00a0\u0442\u0430\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BF%D0%BE%D0%B4%D0%B3%D0%BE%D1%82%D0%BE%D0%B2%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BF%D0%B5%D1%80%D0%B2%D0%BE%D0%B5\" rel=\"noopener noreferrer nofollow\">\u041d\u0430\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BE%D0%BF%D1%82%D0%B8%D0%BC%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" rel=\"noopener noreferrer nofollow\">\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%81%D0%BB%D1%83%D1%87%D0%B0%D0%B9%D0%BD%D1%8B%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%81%D1%80%D0%B0%D0%B2%D0%BD%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%B2%D1%8B%D0%B2%D0%BE%D0%B4\" rel=\"noopener noreferrer nofollow\">\u0412\u044b\u0432\u043e\u0434<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e\u00a0\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u00a0PySpark MLib \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u044e \u043d\u0430\u0438\u0432\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0431\u0443\u0434\u0443 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u0443\u0442\u0435\u043c \u043f\u043e\u0434\u0431\u043e\u0440\u0430 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432.<\/p>\n<p>\u0412\u00a0\u043a\u043e\u043d\u0446\u0435 \u0437\u0430\u0441\u0435\u044e \u0446\u0435\u043b\u044b\u0439 \u043b\u0435\u0441 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0438 \u043d\u0435\u00a0\u0437\u0430\u0431\u0443\u0434\u0443 \u043f\u0440\u043e\u00a0\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439.<\/p>\n<h2>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0439?<\/h2>\n<p><a class=\"anchor\" name=\"%D1%87%D1%82%D0%BE\" id=\"\u0447\u0442\u043e\">\u043e&#187;<\/a><\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f\u00a0\u043f\u0435\u0440\u0432\u043e\u043f\u0440\u043e\u0445\u043e\u0434\u0446\u0435\u0432. \u0415\u0441\u043b\u0438 \u0432\u044b \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u0441\u00a0\u0434\u0430\u043d\u043d\u044b\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c, \u0442\u043e \u0441\u043c\u0435\u043b\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442\u0435 \u043a\u00a0<a href=\"#%D0%BF%D0%BE%D0%B4%D0%B3%D0%BE%D1%82%D0%BE%D0%B2%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u0441\u0442\u0430<\/a>.<\/p>\n<h3>\u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/h3>\n<p>\u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u0435\u043c\u0435\u0439\u0441\u0442\u0432\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043a\u0430\u043a\u00a0\u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430: <\/p>\n<ul>\n<li>\n<p>\u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u043a\u00a0\u0432\u044b\u0431\u0440\u043e\u0441\u0430\u043c \u0432\u00a0\u0434\u0430\u043d\u043d\u044b\u0445;<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0438 \u0432\u00a0\u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0430\u0445 \u0431\u0435\u0437\u00a0\u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438\u043b\u0438\u00a0\u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0438 \u0433\u043b\u0430\u0432\u043d\u043e\u0435\u00a0\u2014 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f\u00a0\u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u00a0\u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435\u00a0\u0436\u0435 \u0440\u0430\u0441\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f, \u0432\u043e\u043f\u043b\u043e\u0449\u0435\u043d\u043d\u044b\u0435 \u0432\u00a0\u0434\u0435\u0440\u0435\u0432\u044c\u044f\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043d\u0435\u044f\u0432\u043d\u043e \u0432\u00a0\u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u0440\u0438\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u00ab\u0434\u0430\/\u043d\u0435\u0442\u00bb, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a\u00a0\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0443 \u0431\u0443\u0434\u0435\u0442\u00a0\u043b\u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u043d\u0430\u00a0\u0443\u043b\u0438\u0446\u0435 \u0438\u043b\u0438\u00a0\u043d\u0435\u0442.<\/p>\n<figure class=\"\"><\/figure>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0435\u0440\u0435\u0432\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u0441\u0430\u043c\u0430 \u00ab\u043f\u0440\u0438\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0442\u00bb \u044d\u0442\u0438 \u0440\u0430\u0437\u0432\u0438\u043b\u043a\u0438. \u0427\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0432\u0438\u043b\u043e\u043a, \u0442\u0435\u043c \u0442\u043e\u0447\u043d\u0435\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430\u00a0\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u043e\u00a0\u043d\u0430\u00a0\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u0445 \u043e\u043d\u0430 \u043d\u0430\u0447\u043d\u0435\u0442 \u0447\u0430\u0449\u0435 \u043e\u0448\u0438\u0431\u0430\u0442\u044c\u0441\u044f. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0430\u043b\u0430\u043d\u0441, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u0435\u043d\u0438\u044f, \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u043a\u0430\u043a\u00a0\u043f\u0435\u0440\u0435\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435.<\/p>\n<h3>\u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u0439    <\/h3>\n<p>\u0414\u0435\u0440\u0435\u0432\u044c\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043e\u0431\u043e\u0431\u0449\u0430\u044e\u0442\u0441\u044f \u0432\u00a0\u0431\u043e\u043b\u0435\u0435 \u043c\u043e\u0449\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430. \u0421\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0435 \u043b\u0435\u0441\u0430 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0440\u0438\u0441\u043a \u043f\u0435\u0440\u0435\u043e\u0441\u043d\u0430\u0449\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0434\u0438\u0441\u043f\u0435\u0440\u0441\u0438\u044e \u043f\u0440\u043e\u0433\u043d\u043e\u0437\u043e\u0432, \u0434\u0435\u043b\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0439 \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u00a0\u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0431 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0435 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c <a href=\"https:\/\/habr.com\/ru\/companies\/productstar\/articles\/523044\/\" rel=\"noopener noreferrer nofollow\">\u0442\u0443\u0442<\/a>. <\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D0%BE%D0%B4%D0%B3%D0%BE%D1%82%D0%BE%D0%B2%D0%BA%D0%B0\" id=\"\u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430\">\u043e\u0432\u043a\u0430&#187;><\/a><\/p>\n<p>\u0414\u043b\u044f\u00a0\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0432\u00a0PySpark MLib \u043d\u0430\u0434\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u00a0\u0433\u043e\u043b\u043e\u0432\u0435, \u0447\u0442\u043e\u00a0\u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 <strong>\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440<\/strong>. \u0418 \u043d\u0435\u0432\u0430\u0436\u043d\u043e, \u043a\u0430\u043a\u043e\u0439 \u0443\u00a0\u0432\u0430\u0441 \u043d\u0430\u0431\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439, \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0439, \u0441\u043c\u0435\u0448\u0430\u043d\u043d\u044b\u0439).<\/p>\n<h3>\u0414\u0430\u0442\u0430\u0441\u0435\u0442<\/h3>\n<p>\u0414\u043b\u044f\u00a0\u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0443 \u043e\u0431\u0449\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445<a href=\"https:\/\/ttps:\/\/www.kaggle.com\/datasets\/ruthgn\/bank-marketing-data-set\" rel=\"noopener noreferrer nofollow\"> Bank Marketing<\/a>. \u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u043f\u043e\u00a0\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0437\u0432\u043e\u043d\u043a\u043e\u0432 \u043f\u043e\u0440\u0442\u0443\u0433\u0430\u043b\u044c\u0441\u043a\u043e\u0439 \u043c\u0430\u0440\u043a\u0435\u0442\u0438\u043d\u0433\u043e\u0432\u043e\u0439 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 (2008\u00a0\u2014 2010\u00a0\u0433\u043e\u0434\u0430\u0445) \u0438 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f\u00a0\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438: \u0441\u0434\u0435\u043b\u0430\u0435\u0442\u00a0\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 term deposit (\u0441\u0440\u043e\u0447\u043d\u044b\u0439 \u0432\u043a\u043b\u0430\u0434) \u0438\u043b\u0438\u00a0\u043d\u0435\u0442.<\/p>\n<p><strong>\u0412\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (features):<\/strong><\/p>\n<ul>\n<li>\n<p><strong>age<\/strong> (numeric);<\/p>\n<\/li>\n<li>\n<p><strong>job<\/strong>: type of job (categorical: &#171;admin&#187;, &#171;unknown&#187;, &#171;unemployed&#187;, &#171;management&#187;, &#171;housemaid&#187;, &#171;entrepreneur&#187;, &#171;student&#187;, &#171;blue-collar&#187;, &#171;self-employed&#187;, &#171;retired&#187;, &#171;technician&#187;, &#171;services&#187;);<\/p>\n<\/li>\n<li>\n<p><strong>marital<\/strong>: marital status (categorical: &#171;married&#187;, &#171;divorced&#187;, &#171;single&#187;; note: &#171;divorced&#187; means divorced or widowed);<\/p>\n<\/li>\n<li>\n<p><strong>education<\/strong>: (categorical: &#171;unknown&#187;, &#171;secondary&#187;, &#171;primary&#187;, &#171;tertiary&#187;);<\/p>\n<\/li>\n<li>\n<p><strong>default<\/strong>: has credit in default? (binary: &#171;yes&#187;, &#171;no&#187;);<\/p>\n<\/li>\n<li>\n<p><strong>balance<\/strong>: average yearly balance, in euros (numeric);<\/p>\n<\/li>\n<li>\n<p><strong>housing<\/strong>: has housing loan? (binary: &#171;yes&#187;, &#171;no&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>loan<\/strong>: has personal loan? (binary: &#171;yes&#187;, &#171;no&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>contact<\/strong>: contact communication type (categorical: &#171;unknown&#187;, &#171;telephone&#187;, &#171;cellular&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>day<\/strong>: last contact day of the month (numeric); <\/p>\n<\/li>\n<li>\n<p><strong>month<\/strong>: last contact month of year (categorical: &#171;jan&#187;, &#171;feb&#187;, &#171;mar&#187;, &#8230;, &#171;nov&#187;, &#171;dec&#187;); <\/p>\n<\/li>\n<li>\n<p><strong>duration<\/strong>: last contact duration, in seconds (numeric); <\/p>\n<\/li>\n<li>\n<p><strong>campaign<\/strong>: number of contacts performed during this campaign and for this client (numeric, includes last contact); <\/p>\n<\/li>\n<li>\n<p><strong>pdays<\/strong>: number of days that passed by after the client was last contacted from a previous campaign (numeric, -1 means client was not previously contacted);<\/p>\n<\/li>\n<li>\n<p><strong>previous<\/strong>: number of contacts performed before this campaign and for this client (numeric);<\/p>\n<\/li>\n<li>\n<p><strong>poutcome<\/strong>: outcome of the previous marketing campaign (categorical: &#171;unknown&#187;, &#171;other&#187;, &#171;failure&#187;, &#171;success&#187;).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 (target):<\/strong> <strong>y <\/strong>&#8212; has the client subscribed a term deposit? (binary: &#171;yes&#187;, &#171;no&#187;) <\/p>\n<p>\u0421 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0441\u044f, \u043f\u0435\u0440\u0435\u0445\u043e\u0436\u0443 \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438.<\/p>\n<h3>\u0427\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u044e spark \u0441\u0435\u0441\u0441\u0438\u044e:<\/p>\n<pre><code class=\"python\">from pyspark.sql import functions as F import pyspark.sql.types as T import pandas as pd  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u043f\u0430\u0440\u043a \u0441\u0435\u0441\u0441\u0438\u044e spark = SparkSession \\     .builder \\     .config(\"spark.ui.enabled\", \"true\") \\     .config(\"spark.driver.memory\", \"8g\") \\     .config(\"spark.executor.instances\", \"4\") \\     .config(\"spark.executor.cores\", \"4\") \\     .config(\"spark.executor.memory\", \"6g\") \\     .config(\"spark.executor.memoryOverhead\", \"200m\") \\     .config(\"spark.dynamicAllocation.enabled\", \"true\") \\     .config(\"spark.dynamicAllocation.shuffleTracking.enabled\", \"true\") \\     .config(\"spark.sql.parquet.compression.codec\", \"snappy\") \\     .config(\"spark.sql.execution.arrow.pyspark.enabled\", \"true\") \\     .getOrCreate()<\/code><\/pre>\n<p>\u0421\u0447\u0438\u0442\u044b\u0432\u0430\u044e \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 pyspark.Dataframe():<\/p>\n<pre><code class=\"python\">data_raw = spark.read.option(\"inferSchema\", \"true\").csv(\"bank-full.csv\", sep=';',encoding = \"UTF-8\", header = True) data_raw.printSchema()<\/code><\/pre>\n<figure class=\"\"><\/figure>\n<p>\u0414\u043b\u044f\u00a0\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442\u00a0type string. \u041d\u0435\u0442, \u043d\u0435\u00a0\u043f\u043e\u0434\u0443\u043c\u0430\u0439\u0442\u0435, \u0447\u0442\u043e\u00a0\u044f \u0432\u044b\u0440\u0435\u0436\u0443 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0445\u043e\u0442\u044f\u00a0\u0431\u044b\u043b\u043e\u00a0\u0431\u044b \u0441\u043b\u0430\u0432\u043d\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442\u00a0target (\u0448\u0443\u0442\u043a\u0430). \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0447\u0442\u043e\u00a0target \u0432\u00a0\u043c\u043e\u0435\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435\u00a0\u2014 \u044d\u0442\u043e \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u00aby\u00bb.<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u0434\u043b\u044f\u00a0\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430 \u043e\u0442\u00a0string \u043a\u00a0integer, \u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u044e \u043f\u0430\u0440\u043e\u0447\u043a\u0443.<\/p>\n<h4>\u041f\u0435\u0440\u0432\u044b\u0439: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c udf \u0444\u0443\u043d\u043a\u0446\u0438\u0438   <\/h4>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441\u00a0sparkDataframe, \u043a\u0430\u043a\u00a0\u0441\u00a0pandasDataframe, \u043d\u043e\u00a0\u0431\u0435\u0437\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f toPandas(), \u0447\u0442\u043e\u00a0\u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u043a\u0443\u0447\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043d\u0435\u0440\u0432\u043d\u044b\u0445 \u043a\u043b\u0435\u0442\u043e\u043a.<\/p>\n<pre><code class=\"python\"># \u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 (month \u0438 y) \u0438\u0437 \u0442\u0438\u043f\u0430 string \u0432 \u0442\u0438\u043f integer  # \u0421\u043e\u0437\u0434\u0430\u0435\u043c udf \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c\u0438 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \"\"\"Transforms yes\/no to digit 1\/0\"\"\" @F.pandas_udf(T.IntegerType()) def y_to_digit(y: pd.Series) -> pd.Series:     return (y == 'yes')  \"\"\"Transforms months to digit\"\"\" @F.pandas_udf(T.IntegerType()) def month_to_digit(month: pd.Series) -> pd.Series:     months = {'jan': 1, 'feb': 2, 'mar': 3, 'apr': 4, 'may': 5, 'jun': 6, 'jul': 7, 'aug': 8, 'sep': 9, 'oct': 10, 'nov': 11, 'dec': 12}     return month.map(months)  # \u0422\u0440\u0430\u043d\u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 data_after_udf = data_raw.withColumn('y', y_to_digit(F.col('y'))).withColumn('month', month_to_digit(F.col('month'))) data_after_udf.show(20)<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<h4>\u0412\u0442\u043e\u0440\u043e\u0439: OneHotEncoder \u0438\u043b\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430    <\/h4>\n<p>\u0414\u043b\u044f\u00a0\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c \u0438 \u0434\u043b\u044f\u00a0\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c pipeline. \u042f \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e \u043d\u0435\u043a\u043e\u0435 \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0432\u00a0\u0441\u043f\u0438\u0441\u043a\u0435 stages, \u0430\u00a0\u0437\u0430\u0442\u0435\u043c pipeline \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442.<\/p>\n<pre><code class=\"python\">from pyspark.ml.feature import OneHotEncoder, StringIndexer, VectorAssembler  # \u0414\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 pipeline # stages \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0432 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0435 stages = []<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e \u0432\u0441\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"python\"># \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u0432\u0435\u043a\u0442\u043e\u0440\u0430 categoricalColumns = ['job', 'marital', 'education', 'default', 'housing', 'loan', 'contact', 'poutcome'] for categoricalCol in categoricalColumns:     stringIndexer = StringIndexer(inputCol = categoricalCol, outputCol = categoricalCol + 'Index', handleInvalid = 'keep')     encoder = OneHotEncoder(inputCol = stringIndexer.getOutputCol(), outputCol = categoricalCol + \"classVec\")     stages += [stringIndexer, encoder]<\/code><\/pre>\n<p>\u0421\u043e\u0431\u0435\u0440\u0443 \u0432\u0441\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u0432 \u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0432 PySpark MLib.<\/p>\n<pre><code class=\"python\"># C\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 \u0432 \u043e\u0434\u0438\u043d \u0432\u0435\u043a\u0442\u043e\u0440 assembler numericCols = ['age', 'balance', 'day', 'month', 'duration', 'campaign', 'pdays', 'previous'] assemblerInputs = [c + \"classVec\" for c in categoricalColumns] + numericCols assembler = VectorAssembler(inputCols = assemblerInputs, outputCol = \"features\") stages += [assembler]<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u044e, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f. \u042f \u0441\u043e\u0437\u0434\u0430\u044e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 pipeline, \u043d\u043e \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0432 \u043d\u0435\u0433\u043e \u043d\u0438\u043a\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041c\u0435\u0442\u043e\u0434 fit \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439 udf \u0444\u0443\u043d\u043a\u0446\u0438\u0439. <\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043e\u043d\u0430 \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u043a\u0430\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<pre><code class=\"python\"># \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u0434\u043e\u043f. \u0440\u0430\u0437\u0434\u0435\u043b) from pyspark.ml import Pipeline  pipeline = Pipeline(stages=stages) model = pipeline.fit(data_after_udf) how_transform_data = model.transform(data_after_udf) how_transform_data.select(F.col('job'), F.col('jobclassVec'), F.col('features')).show(10, truncate = False)<\/code><\/pre>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412\u0441\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u044f\u0442\u0441\u044f \u0432\u00a0sparse \u0432\u0435\u043a\u0442\u043e\u0440\u0430. (\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, job \u2192 jobclassVec).<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432 (features) \u2192 sparse vector \u0441\u00a0\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c\u044e 40.<\/p>\n<h3>\u0414\u0435\u043b\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 train \u0438 test<\/h3>\n<pre><code class=\"python\"># \u0414\u0435\u043b\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0438 \u0442\u0435\u0441\u0442\u043e\u0432\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0438 (train_data, test_data) = data_after_udf.randomSplit([0.9, 0.1])<\/code><\/pre>\n<h2>\u041d\u0430\u0448\u0435 \u043f\u0435\u0440\u0432\u043e\u0435 \u0434\u0435\u0440\u0435\u0432\u043e<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D0%B5%D1%80%D0%B2%D0%BE%D0%B5\" id=\"\u043f\u0435\u0440\u0432\u043e\u0435\">\u043e\u0435&#187;><\/a><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0445\u043e\u0436\u0443 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430:<\/p>\n<pre><code class=\"python\"># \u0418\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 from pyspark.ml.classification import DecisionTreeClassifier  # labelCol \u2013 target, featuresCol \u2013 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0438, predictionCol \u2013 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c classifier_tree = DecisionTreeClassifier(seed = 1234, labelCol=\"y\", featuresCol=\"features\", predictionCol=\"prediction\") stages += [classifier_tree]<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 pipeline \u0438 \u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043a\u0430 \u043c\u043e\u0434\u0435\u043b\u0438: <\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0441\u043e \u0441\u0442\u0430\u0434\u0438\u044f\u043c\u0438 stages from pyspark.ml import Pipeline  pipeline_first_tree = Pipeline(stages = stages)  # \u0422\u0440\u0435\u043d\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c model_first_tree = pipeline_first_tree.fit(train_data)  # \u0414\u0435\u043b\u0430\u0435\u043c \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 predictions_first_tree = model_first_tree.transform(test_data)<\/code><\/pre>\n<p>\u041e\u0446\u0435\u043d\u044e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438. <\/p>\n<p>MulticlassClassificationEvaluator \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u043c\u043e\u0434\u0435\u043b\u0438. \u042f \u0431\u0443\u0434\u0443 \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 (accuracy).<\/p>\n<pre><code class=\"python\"># \u041e\u0446\u0435\u043d\u043a\u0430 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0438 from pyspark.ml.evaluation import MulticlassClassificationEvaluator  # setMetricName \u2013 \u0442\u0438\u043f \u043c\u0435\u0442\u0440\u0438\u043a\u0438 (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u2013 \"\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c\") multiclassEval = MulticlassClassificationEvaluator(). \\     setLabelCol(\"y\"). \\     setPredictionCol(\"prediction\"). \\     setMetricName(\"accuracy\")  # \u0422\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0439 \u043f\u0435\u0440\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 multiclassEval.evaluate(predictions_first_tree) # 0.703<\/code><\/pre>\n<h2>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u0439<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BE%D0%BF%D1%82%D0%B8%D0%BC%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" id=\"\u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f\">\u0437<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-354635","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/354635","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=354635"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/354635\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=354635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=354635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=354635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}