{"id":348178,"date":"2023-05-31T15:03:33","date_gmt":"2023-05-31T15:03:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=348178"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=348178","title":{"rendered":"<span>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0432 PySpark<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/06a\/adf\/249\/06aadf249d4435e87885b5223facb88b.jpg\" width=\"1920\" height=\"1080\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438&nbsp;<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>&nbsp;\u041a\u0443\u0445\u0442\u0435\u043d\u043a\u043e \u0410\u043d\u0434\u0440\u0435\u0439, \u041a\u0440\u0430\u0432\u0435\u0446 \u041c\u0430\u043a\u0441\u0438\u043c \u0438 \u0421\u0438\u044f\u043d\u043e\u0432 \u0410\u0440\u0442\u0435\u043c.<\/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=\"#%D0%BF%D0%BE%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 Spark \u0438 \u0438\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BF%D1%80%D0%B5%D0%B4%D0%B2%D0%B0%D1%80%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BA%D0%BB%D0%B0%D1%81%D1%82%D0%B5%D1%80%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" rel=\"noopener noreferrer nofollow\">\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%80%D0%B5%D0%B7%D1%83%D0%BB%D1%8C%D1%82%D0%B0%D1%82%D1%8B\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%B7%D0%B0%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D0%BE%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0\" id=\"\u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\"><\/a><\/p>\n<p>\u041b\u044e\u0431\u043e\u0439 \u0442\u0435\u043a\u0441\u0442&nbsp;\u2014 \u044d\u0442\u043e \u043d\u0435&nbsp;\u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u043b\u043e\u0432, \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u044b\u0441\u043b\u0438 \u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430. \u041d\u043e&nbsp;\u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c. \u0412&nbsp;\u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e&nbsp;\u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432&nbsp;\u044d\u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u043e\u0434\u043d\u043e\u0439 \u0438\u0437&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u044c ml \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Apache Spark, \u0441\u0447\u0438\u0442\u0430\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u0432&nbsp;\u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0432\u0445\u043e\u0434\u0438\u0442 \u0432&nbsp;\u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 Hadoop&nbsp;\u2014 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f&nbsp;\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430&nbsp;\u0442\u043e, \u0447\u0442\u043e&nbsp;\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043d\u0435&nbsp;\u0442\u0430\u043a \u0448\u0438\u0440\u043e\u043a, \u043a\u0430\u043a&nbsp;\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, scikit\u2011learn, \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432&nbsp;\u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0441\u0440\u043e\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0430&nbsp;\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435. \u0414\u043b\u044f&nbsp;\u0440\u0430\u0431\u043e\u0442\u044b \u0441&nbsp;\u0434\u0430\u043d\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u043d\u0430&nbsp;\u044f\u0437\u044b\u043a\u0435 Python \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 PySpark.<\/p>\n<p>\u041c\u044b \u043d\u0435&nbsp;\u043d\u0430\u0448\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430&nbsp;\u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f&nbsp;\u0431\u044b\u043b\u0430&nbsp;\u0431\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0430&nbsp;\u0432&nbsp;\u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043d\u0430&nbsp;\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0442\u043e\u0436\u0435&nbsp;\u0431\u044b\u043b\u043e \u043c\u0430\u043b\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0441\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u0448\u043b\u0438:<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><a href=\"https:\/\/levelup.gitconnected.com\/text-clustering-using-python-and-spark-69a3696a4320\" rel=\"noopener noreferrer nofollow\">Text Clustering using Python and Spark<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/towardsdatascience.com\/k-means-clustering-using-pyspark-on-big-data-6214beacdc8b\" rel=\"noopener noreferrer nofollow\">K Means Clustering using PySpark on Big Data<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/ieeexplore.ieee.org\/document\/9643401\" rel=\"noopener noreferrer nofollow\">A Scalable Short-Text Clustering Algorithm Using Apache Spark<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/blog-mjay.firebaseapp.com\/post\/text-clustering-in-databricks\/\" rel=\"noopener noreferrer nofollow\">Text Clustering at scale<\/a>   <\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0414\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u0441&nbsp;\u043f\u043e\u043c\u043e\u0449\u044c\u044e pyspark.ml \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0432&nbsp;\u0441\u0435\u0431\u0435 sms\u2011\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435. \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0430\u0436\u043d\u0443\u044e \u0434\u043b\u044f&nbsp;\u043d\u0430\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e&nbsp;\u043f\u043e\u043a\u0443\u043f\u043a\u0430\u0445, \u043e\u043f\u043b\u0430\u0442\u0430\u0445 \u0438 \u0441\u0431\u043e\u044f\u0445 \u043f\u0440\u0438&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u044d\u0442\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437&nbsp;\u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e52\/75b\/c89\/e5275bc8932bea43b3c90925b4c939b9.png\" width=\"1205\" height=\"178\"><\/figure>\n<p>\u041d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432&nbsp;\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0430&nbsp;\u0433\u0440\u0443\u043f\u043f\u044b, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432&nbsp;\u0441\u0435\u0431\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. <\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 Spark \u0438 \u0438\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/h2>\n<p><a class=\"anchor\" name=\"%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5\" id=\"\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\"><\/a><\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c Spark \u0441\u0435\u0441\u0441\u0438\u044e \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from pyspark import SparkContext, SparkConf, HiveContext # \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u043f\u0430\u0440\u043a\u0430 conf = SparkConf().setAppName('spark_dlab_app')  conf.setAll(     [         #\u0423\u043a\u0430\u0436\u0438\u0442\u0435 \u0442\u0443\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b Spark     ]) spark = SparkSession.builder.config(conf=conf).enableHiveSupport().getOrCreate()<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u0435\u0441\u0441\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/spark.apache.org\/docs\/latest\/configuration.html\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"python\"># \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 from pyspark.sql.functions import udf  # \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043a\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 from pyspark.sql.window import Window # \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 PySpark DataFrame from pyspark.sql import DataFrame # \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e udf \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 from pyspark.sql.types import StringType # \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 import re # \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Pandas DataFrame import pandas as pd # \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 from pyspark.ml.feature import HashingTF, IDF, Word2Vec,\\                                CountVectorizer, Tokenizer, StopWordsRemover # \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 from pyspark.ml.clustering import Kmeans, BisectingKmeans # \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430 from pyspark.ml import Pipeline # \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0441\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 from nltk.probability import FreqDist<\/code><\/pre>\n<h2>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D1%80%D0%B5%D0%B4%D0%B2%D0%B0%D1%80%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F\" id=\"\u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f\"><\/a><\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c DataFrame \u0438\u0437&nbsp;\u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430&nbsp;Hadoop, \u0432&nbsp;\u043d\u0430\u0448\u0435\u0439 \u0441\u0435\u0441\u0441\u0438\u0438:<\/p>\n<pre><code class=\"python\">t = spark.table('data')<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432&nbsp;\u0442\u0435\u043a\u0441\u0442\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435&nbsp;\u043d\u0435\u0441\u0451\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0446\u0438\u0444\u0440\u044b \u0438\u043b\u0438&nbsp;\u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f, \u043c\u044b \u0435\u0451 \u0443\u0434\u0430\u043b\u0438\u043c. \u0414\u043b\u044f&nbsp;\u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 UDF\u2011\u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441&nbsp;\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">def text_prep(text):    # \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440     text = str(text).lower()    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0435 \u0440\u0443\u0441\u0441\u043a\u0430\u044f \u0431\u0443\u043a\u0432\u0430, \u0438 \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u00ab\u0431\u0430\u043b\u0430\u043d\u0441\u00bb     text = re.sub('[^\u0430-\u044f\u0451]|\u0431\u0430\u043b\u0430\u043d\u0441',' ',text)    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u00ab\u043e\u0442\u00bb     text = re.sub('\u043e\u0442.+','',text)    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0435 \u0431\u0443\u043a\u0432\u044b     text = re.sub('\\s[\u0430-\u044f\u0451]\\s{0,1}','',text)    # \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0438\u0445 \u043d\u0430 \u043e\u0434\u0438\u043d     text = re.sub('\\s+',' ',text)    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044b \u0441\u043b\u0435\u0432\u0430 \u0438 \u0441\u043f\u0440\u0430\u0432\u0430     text = text.strip()     return text # \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 prep_text_udf = udf(text_prep, StringType())<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0443\u0431\u0435\u0440\u0435\u043c \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"python\">t = t.withColumn('prep_text', prep_text_udf('sms_text'))\\     .filter('prep_text &lt;&gt; \"\"')<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0443\u044e \u043d\u0430\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p>\u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<br \/> \u0432&nbsp;\u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435) \u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 (Pipeline), \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u0432&nbsp;\u0441\u0435\u0431\u044f \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f&nbsp;\u043d\u0435\u0435 \u044d\u0442\u0430\u043f\u044b. \u0414\u043b\u044f&nbsp;\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u044b \u0432&nbsp;\u043d\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0442\u0440\u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Feature_extraction\" rel=\"noopener noreferrer nofollow\">feature extractor<\/a>, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0438\u0445 \u0442\u0435\u043a\u0441\u0442 \u0432&nbsp;\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440: CountVectorizer, HashingTF+ IDF \u0438 Word2Vec.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442:<\/p>\n<ul>\n<li>\n<p><strong>Tokenizer<\/strong>, \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430&nbsp;\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u043e\u0432&nbsp;\u2014 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446, \u0432&nbsp;\u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>StopWordsRemover<\/strong>, \u0443\u0434\u0430\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u0442\u043e\u043f\u2011\u0441\u043b\u043e\u0432\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u0415\u0441\u043b\u0438 \u0432&nbsp;\u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0442\u043e\u043f\u2011\u0441\u043b\u043e\u0432\u0430, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432&nbsp;\u0441\u043f\u0438\u0441\u043a\u0435 \u0441\u0442\u043e\u043f\u2011\u0441\u043b\u043e\u0432 PySpark, \u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u043a\u0430\u043a&nbsp;\u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0438\u0436\u0435. <\/p>\n<\/li>\n<li>\n<p><strong>HashingTF<\/strong> \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u0435\u0448\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u043d\u0430&nbsp;\u0438\u0445 \u0447\u0430\u0441\u0442\u043e\u0442\u044b. \u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c CountVectorizer, \u0432&nbsp;\u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432&nbsp;\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441&nbsp;IDF (Inverse Document Frequency), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u044b. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 IDF \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0432\u0435\u0441 \u0448\u0438\u0440\u043e\u043a\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432. \u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e&nbsp;IDF \u043d\u0435&nbsp;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0430 \u043f\u043e&nbsp;\u0441\u0435\u0431\u0435, \u043e\u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0447\u0430\u0441\u0442\u043e\u0442 \u0441\u043b\u043e\u0432 (Term Frequency, \u0432&nbsp;\u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 HashingTF).<\/p>\n<\/li>\n<li>\n<p><strong>Word2Vec<\/strong>&nbsp;\u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430&nbsp;\u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0441\u043b\u043e\u0432 \u0432&nbsp;\u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u0421\u043b\u043e\u0432\u0430, \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0432&nbsp;\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435 \u0440\u044f\u0434\u043e\u043c \u0441&nbsp;\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043f\u043e&nbsp;\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u043c\u0443 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<\/li>\n<li>\n<p><strong>CountVectorizer<\/strong> \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430&nbsp;\u0440\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 (sparse vector), \u0433\u0434\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438&nbsp;\u2014 \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432&nbsp;\u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0430&nbsp;\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f&nbsp;\u2014 \u0447\u0438\u0441\u043b\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432&nbsp;\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435.   <\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Pipeline \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"python\">Tokenizer = Tokenizer(inputCol = 'prep_text', outputCol = 'tokens')  # \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430 \u0438\u0437 pyspark rus_stopwords = StopWordsRemover.loadDefaultStopWords('russian') # \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430 with open('\/home\/datalab\/nfs\/stopwords.txt', 'r') as f:     stopwords = [line.strip() for line in f] # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430 \u043a \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430\u043c \u0438\u0437 pyspark rus_stopwords.extend(stopwords) # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 rus_stopwords = list(set(rus_stopwords)) stopwordsRemover = StopWordsRemover(inputCol = 'tokens',                                      outputCol = 'clear_tokens',                                      stopWords = rus_stopwords)  hashingTF = HashingTF(inputCol = 'clear_tokens', outputCol = 'rawFeatures') idf = IDF(inputCol = 'rawFeatures', outputCol = 'TfIdfFeatures', minDocFreq = 5)  word2Vec = Word2Vec(inputCol = 'clear_tokens', outputCol = 'Word2VecFeatures')  countVec = CountVectorizer(inputCol = 'clear_tokens',                             outputCol = 'CountVectFeatures')  pipeline = Pipeline(stages = [regexTokenizer, stopwordsRemover,         hashingTF, idf, word2Vec, countVec]) # \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430\u0448 pipeline pipeline_fit = pipeline.fit(t) t = pipeline_fit.transform(t)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0447\u0438\u0449\u0435\u043d\u044b \u043e\u0442&nbsp;\u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u044b \u0432&nbsp;\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0432\u0438\u0434 \u0434\u043b\u044f&nbsp;\u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0435\u043a\u0443\u0449\u0438\u0439 \u0432\u0438\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0430&nbsp;\u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/213\/9f3\/e6b\/2139f3e6b0cf808924fb0a8e6f65dd52.png\" width=\"621\" height=\"114\"><\/figure>\n<h2>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BA%D0%BB%D0%B0%D1%81%D1%82%D0%B5%D1%80%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" id=\"\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f\"><\/a><\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0443\u0437\u043d\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">t.groupBy('clear_tokens').count().count()<\/code><\/pre>\n<p>\u0412\u0441\u0435\u0433\u043e \u0443&nbsp;\u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c 6294&nbsp;\u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439. \u042d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u043b\u0438\u043a\u043e \u0434\u043b\u044f&nbsp;\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c sms \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e&nbsp;\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412&nbsp;Spark \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 6&nbsp;\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438: KMeans, BisectingKMeans, Latent Dirichlet allocation (LDA), Power iteration clustering (PIC), Gaussian mixture \u0438 StreamingKMeans.<\/p>\n<p>StreamingKMeans \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445; PIC&nbsp;\u2014 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u0440\u0430\u0444\u043e\u0432; LDA \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432&nbsp;\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432&nbsp;\u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438; Gaussian mixture \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430&nbsp;\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b, \u0447\u0442\u043e&nbsp;\u043d\u0435&nbsp;\u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f&nbsp;\u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b KMeans \u0438 BisectingKMeans.<\/p>\n<details class=\"spoiler\">\n<summary> \u041e KMeans<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0432\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043d\u0442\u0440, \u0437\u0430\u0442\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443, \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e. \u0414\u0430\u043d\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043d\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u043d\u0438\u0436\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430.   <\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e BisectingKMeans<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0437\u0430\u0442\u0435\u043c \u043e\u043d \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f KMeans. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u0435\u043b\u044f\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c.   <\/p>\n<\/div>\n<\/details>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c BisectingKMeans \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f&nbsp;\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u043c KMeans, \u043a&nbsp;\u0442\u043e\u043c\u0443&nbsp;\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043f\u043e\u0434\u0435\u043b\u0438\u0442&nbsp;\u043b\u0438 \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430&nbsp;\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0447\u0435\u043c \u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043e.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043c\u044b \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Elbow_method_(clustering)\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043b\u043e\u043a\u0442\u044f<\/a>, \u0438 \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438, \u0447\u0442\u043e&nbsp;\u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e 36.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a&nbsp;\u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437&nbsp;\u043d\u0438\u0445, \u0434\u043b\u044f&nbsp;\u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432&nbsp;\u0441\u0435\u0431\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0435\u043a\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u0434\u0432\u0430 \u0446\u0438\u043a\u043b\u0430, \u0433\u0434\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a&nbsp;\u044d\u0442\u0438\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c. \u041a\u043e\u0434 \u0434\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"python\">cols = ['TfIdfFeatures', 'Word2VecFeatures', 'CountVectFeatures']  for col in cols:     kmeans = KMeans().setK(36)\\                .setFeaturesCol(col)\\                      .setPredictionCol(f'kmeans_clusters_{col}')     km_model = kmeans.fit(t)     t = km_model.transform(t)  for col in cols:     bkm = BisectingKMeans().setK(36)\\                            .setFeaturesCol(col)\\                            .setPredictionCol(f'BisectingKMeans_clusters_{col}')     bkm_model = bkm.fit(t)     t = bkm_model.transform(t)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432&nbsp;\u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f 6&nbsp;\u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0441&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438: kmeans_clusters_TfIdfFeatures, means_clusters_Word2VecFeatures, kmeans_clusters_CountVectFeatures, BisectingKMeans_clusters_TfIdfFeatures, BisectingKMeans_clusters_Word2VecFeatures \u0438 BisectingKMeans_clusters_CountVectFeatures.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432&nbsp;\u043a\u0430\u0436\u0434\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435, \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432\u044b\u0448\u0435;   <\/p>\n<\/li>\n<li>\n<p>\u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0432 \u0441\u0442\u043e\u043b\u0431\u0446\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u0435\u0441\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439\u0441\u044f \u0432 \u043d\u0435\u043c \u0442\u0435\u043a\u0441\u0442 \u0432 \u0432\u0438\u0434\u0435 \u0441\u043f\u0438\u0441\u043a\u0430;   <\/p>\n<\/li>\n<li>\n<p>\u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 FreqDist \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0438 \u0432\u0437\u044f\u043b\u0438 \u0438\u0437 \u043d\u0435\u0433\u043e 5 \u043f\u0435\u0440\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439;    <\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u043d\u043e\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430;   <\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432 Pandas DataFrame, \u0430 \u0435\u0433\u043e \u0432 PySpark DataFrame;   <\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u043e\u043c\u0435\u0440 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0432 \u043d\u0435\u043c, \u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043c \u0435\u0433\u043e \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 \u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0437\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0432\u0441\u0435 \u044d\u0442\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 Hadoop, \u0447\u0442\u043e\u0431\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<pre><code class=\"python\">col_clusters = ['kmeans_clusters_TfIdfFeatures',                    'kmeans_clusters_Word2VecFeatures',        'kmeans_clusters_CountVectFeatures',      'BisectingKMeans_clusters_TfIdfFeatures',       'BisectingKMeans_clusters_Word2VecFeatures',       'BisectingKMeans_clusters_CountVectFeatures'] for col in col_clusters:     for i in range(36):         ls = []         tmp = t.select('clear_tokens',col).filter(f\"{col} = {i}\").collect()          tmp = [tmp[j][0] for j in range(len(tmp))]          for el in tmp:             ls.extend(el)          fdist = list(FreqDist(ls))[:5]          d = {i:fdist}         d = pd.DataFrame(list(d.items()), columns = [col, 'top_words'])         d = spark.createDataFrame(d)          tmp_t = t.groupBy(col).count()\\                                 .orderBy('count', ascending = False)\\                                 .join(d, [col])          tmp_t.write.mode('append').saveAsTable(f'{col}_itog')<\/code><\/pre>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/h2>\n<p><a class=\"anchor\" name=\"%D1%80%D0%B5%D0%B7%D1%83%D0%BB%D1%8C%D1%82%D0%B0%D1%82%D1%8B\" id=\"\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b\"><\/a><\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043e\u0446\u0435\u043d\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 feature extractor, \u043c\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u043b\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432 Excel \u0438 \u0432\u044b\u0434\u0435\u043b\u0438\u043b\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0446\u0432\u0435\u0442\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d66\/c41\/915\/d66c41915ce5c9b3fa4068f9fefa5322.png\" alt=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f HashingTF-IDF + KMeans \u0438 HashingTF-IDF + BisectingKMeans\" title=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f HashingTF-IDF + KMeans \u0438 HashingTF-IDF + BisectingKMeans\" width=\"1193\" height=\"307\"><\/p>\n<div><figcaption>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f HashingTF-IDF + KMeans \u0438 HashingTF-IDF + BisectingKMeans<\/figcaption><\/div>\n<\/figure>\n<p>\u041d\u0430&nbsp;\u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u0432\u044b\u0448\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e&nbsp;\u0432&nbsp;\u043e\u0431\u043e\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0432&nbsp;\u043e\u0434\u0438\u043d, \u043a&nbsp;\u0442\u043e\u043c\u0443&nbsp;\u0436\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c BisectingKMeans \u0440\u0430\u0437\u0431\u0438\u043b \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 32&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0432\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 36.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/35c\/27b\/283\/35c27b2836fe6f4a85a2cdd07ba17470.png\" alt=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f CountVectorizer + KMeans \u0438 CountVectorizer + BisectingKMeans   \" title=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f CountVectorizer + KMeans \u0438 CountVectorizer + BisectingKMeans   \" width=\"1057\" height=\"449\"><\/p>\n<div><figcaption>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f CountVectorizer + KMeans \u0438 CountVectorizer + BisectingKMeans   <\/figcaption><\/div>\n<\/figure>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e&nbsp;CountVectorizer \u0432&nbsp;\u0441\u0432\u044f\u0437\u043a\u0435 \u0441&nbsp;KMeams \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c HashingTF+ IDF, \u043d\u043e&nbsp;\u0441&nbsp;BisectingKMeans \u043e\u043d \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0445\u0443\u0436\u0435. <\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/776\/e75\/85d\/776e7585d7a7a6efa40306734d1f41af.png\" alt=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f Word2vec + KMeans \u0438 Word2vec + BisectingKMeans   \" title=\"\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f Word2vec + KMeans \u0438 Word2vec + BisectingKMeans   \" width=\"939\" height=\"288\"><\/p>\n<div><figcaption>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0434\u043b\u044f Word2vec + KMeans \u0438 Word2vec + BisectingKMeans   <\/figcaption><\/div>\n<\/figure>\n<p>Word2Vec \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 KMeans \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u0437 \u0432\u0441\u0435\u0445, \u043d\u043e \u0441&nbsp; BisectingKMeans \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0445\u0443\u0434\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0430\u0437\u0431\u0438\u043b \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 26 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0432\u043c\u0435\u0441\u0442\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 36.   <\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p><a class=\"anchor\" name=\"%D0%B7%D0%B0%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\" id=\"\u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\"><\/a><\/p>\n<p>\u0425\u0443\u0436\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u0441\u0435\u0431\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 BisectingKMeans, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b&nbsp;\u043b\u0438\u0448\u043d\u0435\u0435 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0441&nbsp;\u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0438, \u043a\u0430\u043a&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u0435&nbsp;\u0432\u044b\u0434\u0435\u043b\u0438\u043b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b. \u0418\u0437&nbsp;\u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e&nbsp;BisectingKMeans \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430&nbsp;\u0434\u0430\u043d\u043d\u044b\u0445, \u0431\u043e\u043b\u0435\u0435 \u0441\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043e&nbsp;\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430\u0445. \u0422\u0430\u043a\u0436\u0435 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438&nbsp;\u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u0432\u044b\u0448\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b\u0448\u0435 36).<\/p>\n<p>\u041b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0435\u0431\u044f \u043f\u0440\u043e\u044f\u0432\u0438\u043b Word2Vec \u0432&nbsp;\u0441\u0432\u044f\u0437\u043a\u0435 \u0441&nbsp;KMeans, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e&nbsp;\u0432&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435&nbsp;\u0431\u044b\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u0447\u0438\u0441\u043b\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0430&nbsp;\u0438\u043c\u0435\u043d\u043d\u043e 34&nbsp;\u0438\u0437 36, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043c\u0435\u043d\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u0442\u044c. <\/p>\n<p>\u0412&nbsp;\u0438\u0442\u043e\u0433\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 pySpark ml, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u043b\u0438 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e sms\u2011\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0412&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b 34&nbsp;\u044f\u0432\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 pySpark ml \u0432\u043f\u043e\u043b\u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0434\u043b\u044f&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0438, \u0432&nbsp;\u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0434\u043b\u044f&nbsp;\u043c\u0430\u0448\u0438\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0439.<\/p>\n<\/p>\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\/738906\/\"> https:\/\/habr.com\/ru\/articles\/738906\/<\/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<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u041d\u0430 \u0441\u0432\u044f\u0437\u0438 \u0443\u0447\u0430\u0441\u0442\u043d\u0438\u043a\u0438&nbsp;<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>&nbsp;\u041a\u0443\u0445\u0442\u0435\u043d\u043a\u043e \u0410\u043d\u0434\u0440\u0435\u0439, \u041a\u0440\u0430\u0432\u0435\u0446 \u041c\u0430\u043a\u0441\u0438\u043c \u0438 \u0421\u0438\u044f\u043d\u043e\u0432 \u0410\u0440\u0442\u0435\u043c.<\/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=\"#%D0%BF%D0%BE%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0\" rel=\"noopener noreferrer nofollow\">\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 Spark \u0438 \u0438\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BF%D1%80%D0%B5%D0%B4%D0%B2%D0%B0%D1%80%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%BA%D0%BB%D0%B0%D1%81%D1%82%D0%B5%D1%80%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" rel=\"noopener noreferrer nofollow\">\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D1%80%D0%B5%D0%B7%D1%83%D0%BB%D1%8C%D1%82%D0%B0%D1%82%D1%8B\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#%D0%B7%D0%B0%D0%BA%D0%BB%D1%8E%D1%87%D0%B5%D0%BD%D0%B8%D0%B5\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0437\u0430\u0434\u0430\u0447\u0438<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D0%BE%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B0\" id=\"\u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\">\u043e\u0432\u043a\u0430&#187;><\/a><\/p>\n<p>\u041b\u044e\u0431\u043e\u0439 \u0442\u0435\u043a\u0441\u0442&nbsp;\u2014 \u044d\u0442\u043e \u043d\u0435&nbsp;\u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0441\u043b\u043e\u0432, \u043e\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u044b\u0441\u043b\u0438 \u0438 \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0430\u0432\u0442\u043e\u0440\u0430. \u041d\u043e&nbsp;\u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c. \u0412&nbsp;\u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e&nbsp;\u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0432&nbsp;\u044d\u0442\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438, \u043e\u0434\u043d\u043e\u0439 \u0438\u0437&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u044c ml \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 Apache Spark, \u0441\u0447\u0438\u0442\u0430\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u0432&nbsp;\u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u0430\u043d\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a \u0432\u0445\u043e\u0434\u0438\u0442 \u0432&nbsp;\u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 Hadoop&nbsp;\u2014 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u0434\u043b\u044f&nbsp;\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430&nbsp;\u0442\u043e, \u0447\u0442\u043e&nbsp;\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043d\u0435&nbsp;\u0442\u0430\u043a \u0448\u0438\u0440\u043e\u043a, \u043a\u0430\u043a&nbsp;\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, scikit\u2011learn, \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432&nbsp;\u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0435 \u0441\u0440\u043e\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0430&nbsp;\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0435. \u0414\u043b\u044f&nbsp;\u0440\u0430\u0431\u043e\u0442\u044b \u0441&nbsp;\u0434\u0430\u043d\u043d\u044b\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u043c \u043d\u0430&nbsp;\u044f\u0437\u044b\u043a\u0435 Python \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 PySpark.<\/p>\n<p>\u041c\u044b \u043d\u0435&nbsp;\u043d\u0430\u0448\u043b\u0438 \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0430&nbsp;\u0440\u0443\u0441\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f&nbsp;\u0431\u044b\u043b\u0430&nbsp;\u0431\u044b \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u044d\u0442\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435, \u0430&nbsp;\u0432&nbsp;\u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043d\u0430&nbsp;\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u0442\u043e\u0436\u0435&nbsp;\u0431\u044b\u043b\u043e \u043c\u0430\u043b\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0441\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0442\u0430\u0442\u044c\u0438 \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0430\u0448\u043b\u0438:<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><a href=\"https:\/\/levelup.gitconnected.com\/text-clustering-using-python-and-spark-69a3696a4320\" rel=\"noopener noreferrer nofollow\">Text Clustering using Python and Spark<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/towardsdatascience.com\/k-means-clustering-using-pyspark-on-big-data-6214beacdc8b\" rel=\"noopener noreferrer nofollow\">K Means Clustering using PySpark on Big Data<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/ieeexplore.ieee.org\/document\/9643401\" rel=\"noopener noreferrer nofollow\">A Scalable Short-Text Clustering Algorithm Using Apache Spark<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/blog-mjay.firebaseapp.com\/post\/text-clustering-in-databricks\/\" rel=\"noopener noreferrer nofollow\">Text Clustering at scale<\/a>   <\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p>\u0414\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 \u0441&nbsp;\u043f\u043e\u043c\u043e\u0449\u044c\u044e pyspark.ml \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0443\u044e \u0432&nbsp;\u0441\u0435\u0431\u0435 sms\u2011\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435. \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0430\u0436\u043d\u0443\u044e \u0434\u043b\u044f&nbsp;\u043d\u0430\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e&nbsp;\u043f\u043e\u043a\u0443\u043f\u043a\u0430\u0445, \u043e\u043f\u043b\u0430\u0442\u0430\u0445 \u0438 \u0441\u0431\u043e\u044f\u0445 \u043f\u0440\u0438&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u044d\u0442\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439. \u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437&nbsp;\u044d\u0442\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432&nbsp;\u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0432\u0441\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0430&nbsp;\u0433\u0440\u0443\u043f\u043f\u044b, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437&nbsp;\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432&nbsp;\u0441\u0435\u0431\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. <\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438 Spark \u0438 \u0438\u043c\u043f\u043e\u0440\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/h2>\n<p><a class=\"anchor\" name=\"%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5\" id=\"\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\">\u043d\u0438\u0435&#187;><\/a><\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c Spark \u0441\u0435\u0441\u0441\u0438\u044e \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from pyspark import SparkContext, SparkConf, HiveContext # \u0437\u0430\u043f\u0443\u0441\u043a \u0441\u0435\u0441\u0441\u0438\u0438 \u0441\u043f\u0430\u0440\u043a\u0430 conf = SparkConf().setAppName('spark_dlab_app')  conf.setAll(     [         #\u0423\u043a\u0430\u0436\u0438\u0442\u0435 \u0442\u0443\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b Spark     ]) spark = SparkSession.builder.config(conf=conf).enableHiveSupport().getOrCreate()<\/code><\/pre>\n<p>\u0412\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0441\u0435\u0441\u0441\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/spark.apache.org\/docs\/latest\/configuration.html\" rel=\"noopener noreferrer nofollow\">\u0437\u0434\u0435\u0441\u044c<\/a><\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b:<\/p>\n<pre><code class=\"python\"># \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 from pyspark.sql.functions import udf  # \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043e\u043a\u043e\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 from pyspark.sql.window import Window # \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 PySpark DataFrame from pyspark.sql import DataFrame # \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e udf \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 from pyspark.sql.types import StringType # \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 import re # \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Pandas DataFrame import pandas as pd # \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0442\u0435\u043a\u0441\u0442\u0430 from pyspark.ml.feature import HashingTF, IDF, Word2Vec,\\                                CountVectorizer, Tokenizer, StopWordsRemover # \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 from pyspark.ml.clustering import Kmeans, BisectingKmeans # \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0430\u0439\u043f\u043b\u0430\u0439\u043d\u0430 from pyspark.ml import Pipeline # \u0434\u043b\u044f \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0441\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 from nltk.probability import FreqDist<\/code><\/pre>\n<h2>\u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BF%D1%80%D0%B5%D0%B4%D0%B2%D0%B0%D1%80%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D0%BD%D0%B0%D1%8F\" id=\"\u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f\">\u0442\u0435\u043b\u044c\u043d\u0430\u044f&#187;<\/a><\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c DataFrame \u0438\u0437&nbsp;\u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430&nbsp;Hadoop, \u0432&nbsp;\u043d\u0430\u0448\u0435\u0439 \u0441\u0435\u0441\u0441\u0438\u0438:<\/p>\n<pre><code class=\"python\">t = spark.table('data')<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432&nbsp;\u0442\u0435\u043a\u0441\u0442\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435&nbsp;\u043d\u0435\u0441\u0451\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0446\u0438\u0444\u0440\u044b \u0438\u043b\u0438&nbsp;\u0437\u043d\u0430\u043a\u0438 \u043f\u0440\u0435\u043f\u0438\u043d\u0430\u043d\u0438\u044f, \u043c\u044b \u0435\u0451 \u0443\u0434\u0430\u043b\u0438\u043c. \u0414\u043b\u044f&nbsp;\u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 UDF\u2011\u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442 \u0442\u0435\u043a\u0441\u0442 \u0441&nbsp;\u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"python\">def text_prep(text):    # \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u043c \u0442\u0435\u043a\u0441\u0442 \u0432 \u043d\u0438\u0436\u043d\u0438\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440     text = str(text).lower()    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0435 \u0440\u0443\u0441\u0441\u043a\u0430\u044f \u0431\u0443\u043a\u0432\u0430, \u0438 \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u043b\u043e\u0432\u043e \u00ab\u0431\u0430\u043b\u0430\u043d\u0441\u00bb     text = re.sub('[^\u0430-\u044f\u0451]|\u0431\u0430\u043b\u0430\u043d\u0441',' ',text)    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0451, \u0447\u0442\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u00ab\u043e\u0442\u00bb     text = re.sub('\u043e\u0442.+','',text)    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u044b\u0435 \u0431\u0443\u043a\u0432\u044b     text = re.sub('\\s[\u0430-\u044f\u0451]\\s{0,1}','',text)    # \u0435\u0441\u043b\u0438 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0438\u0445 \u043d\u0430 \u043e\u0434\u0438\u043d     text = re.sub('\\s+',' ',text)    # \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u043b\u0438\u0448\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u0435\u043b\u044b \u0441\u043b\u0435\u0432\u0430 \u0438 \u0441\u043f\u0440\u0430\u0432\u0430     text = text.strip()     return text # \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 prep_text_udf = udf(text_prep, StringType())<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0443\u0431\u0435\u0440\u0435\u043c \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"python\">t = t.withColumn('prep_text', prep_text_udf('sms_text'))\\     .filter('prep_text &lt;&gt; \"\"')<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0441\u044f \u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0443\u044e \u043d\u0430\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p>\u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<br \/> \u0432&nbsp;\u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435) \u0442\u0435\u043a\u0441\u0442\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 (Pipeline), \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u0432&nbsp;\u0441\u0435\u0431\u044f \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f&nbsp;\u043d\u0435\u0435 \u044d\u0442\u0430\u043f\u044b. \u0414\u043b\u044f&nbsp;\u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043c\u044b \u0432&nbsp;\u043d\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0442\u0440\u0438 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Feature_extraction\" rel=\"noopener noreferrer nofollow\">feature extractor<\/a>, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0438\u0445 \u0442\u0435\u043a\u0441\u0442 \u0432&nbsp;\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0432\u0435\u043a\u0442\u043e\u0440: CountVectorizer, HashingTF+ IDF \u0438 Word2Vec.<\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0432\u0435\u0439\u0435\u0440 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442:<\/p>\n<ul>\n<li>\n<p><strong>Tokenizer<\/strong>, \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0449\u0438\u0439 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430&nbsp;\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0442\u043e\u043a\u0435\u043d\u043e\u0432&nbsp;\u2014 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043c\u044b\u0441\u043b\u043e\u0432\u044b\u0445 \u0435\u0434\u0438\u043d\u0438\u0446, \u0432&nbsp;\u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u043b\u043e\u0432\u0430.<\/p>\n<\/li>\n<li>\n<p><strong>StopWordsRemover<\/strong>, \u0443\u0434\u0430\u043b\u044f\u044e\u0449\u0438\u0439 \u0441\u0442\u043e\u043f\u2011\u0441\u043b\u043e\u0432\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u044f\u0437\u044b\u043a\u0430. \u0415\u0441\u043b\u0438 \u0432&nbsp;\u043f\u0440\u0435\u0434\u043c\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0442\u043e\u043f\u2011\u0441\u043b\u043e\u0432\u0430, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432&nbsp;\u0441\u043f\u0438\u0441\u043a\u0435 \u0441\u0442\u043e\u043f\u2011\u0441\u043b\u043e\u0432 PySpark, \u0442\u043e \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e, \u043a\u0430\u043a&nbsp;\u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043e \u043d\u0438\u0436\u0435. <\/p>\n<\/li>\n<li>\n<p><strong>HashingTF<\/strong> \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u0435\u0448\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043b\u043e\u0432\u0430 \u043d\u0430&nbsp;\u0438\u0445 \u0447\u0430\u0441\u0442\u043e\u0442\u044b. \u042f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c CountVectorizer, \u0432&nbsp;\u0434\u0430\u043d\u043d\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432&nbsp;\u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441&nbsp;IDF (Inverse Document Frequency), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u0447\u0430\u0441\u0442\u043e\u0442\u044b. \u041f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 IDF \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0432\u0435\u0441 \u0448\u0438\u0440\u043e\u043a\u043e\u0443\u043f\u043e\u0442\u0440\u0435\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u043e\u0432. \u0412\u0430\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e&nbsp;IDF \u043d\u0435&nbsp;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441\u0430\u043c\u0430 \u043f\u043e&nbsp;\u0441\u0435\u0431\u0435, \u043e\u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u0430 \u0447\u0430\u0441\u0442\u043e\u0442 \u0441\u043b\u043e\u0432 (Term Frequency, \u0432&nbsp;\u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043a&nbsp;\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 HashingTF).<\/p>\n<\/li>\n<li>\n<p><strong>Word2Vec<\/strong>&nbsp;\u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043d\u0430&nbsp;\u043d\u0435\u0439\u0440\u043e\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043c\u044b\u0441\u043b \u0441\u043b\u043e\u0432 \u0432&nbsp;\u0438\u0445 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u0421\u043b\u043e\u0432\u0430, \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0432&nbsp;\u0442\u0440\u0435\u043d\u0438\u0440\u043e\u0432\u043e\u0447\u043d\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043e\u0440\u043f\u0443\u0441\u0435 \u0440\u044f\u0434\u043e\u043c \u0441&nbsp;\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0431\u043b\u0438\u0437\u043a\u0438\u0435 \u043f\u043e&nbsp;\u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u043e\u043c\u0443 \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f. <\/p>\n<\/li>\n<li>\n<p><strong>CountVectorizer<\/strong> \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0442\u0435\u043a\u0441\u0442 \u043d\u0430&nbsp;\u0440\u0430\u0437\u0440\u0435\u0436\u0435\u043d\u043d\u044b\u0439 \u0432\u0435\u043a\u0442\u043e\u0440 (sparse vector), \u0433\u0434\u0435 \u043a\u043e\u043b\u043e\u043d\u043a\u0438&nbsp;\u2014 \u0432\u0441\u0435 \u0441\u043b\u043e\u0432\u0430 \u0432&nbsp;\u043a\u043e\u0440\u043f\u0443\u0441\u0435, \u0430&nbsp;\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f&nbsp;\u2014 \u0447\u0438\u0441\u043b\u043e \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0439 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432&nbsp;\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435.   <\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f Pipeline \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"python\">Tokenizer = Tokenizer(inputCol = 'prep_text', outputCol = 'tokens')  # \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430 \u0438\u0437 pyspark rus_stopwords = StopWordsRemover.loadDefaultStopWords('russian') # \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430 with open('\/home\/datalab\/nfs\/stopwords.txt', 'r') as f:     stopwords = [line.strip() for line in f] # \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430 \u043a \u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430\u043c \u0438\u0437 pyspark rus_stopwords.extend(stopwords) # \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 rus_stopwords = list(set(rus_stopwords)) stopwordsRemover = StopWordsRemover(inputCol = 'tokens',                                      outputCol = 'clear_tokens',                                      stopWords = rus_stopwords)  hashingTF = HashingTF(inputCol = 'clear_tokens', outputCol = 'rawFeatures') idf = IDF(inputCol = 'rawFeatures', outputCol = 'TfIdfFeatures', minDocFreq = 5)  word2Vec = Word2Vec(inputCol = 'clear_tokens', outputCol = 'Word2VecFeatures')  countVec = CountVectorizer(inputCol = 'clear_tokens',                             outputCol = 'CountVectFeatures')  pipeline = Pipeline(stages = [regexTokenizer, stopwordsRemover,         hashingTF, idf, word2Vec, countVec]) # \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u043d\u0430\u0448 pipeline pipeline_fit = pipeline.fit(t) t = pipeline_fit.transform(t)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0447\u0438\u0449\u0435\u043d\u044b \u043e\u0442&nbsp;\u043d\u0435\u043d\u0443\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438 \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043d\u044b \u0432&nbsp;\u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0432\u0438\u0434 \u0434\u043b\u044f&nbsp;\u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0438\u0445 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0435\u043a\u0443\u0449\u0438\u0439 \u0432\u0438\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0430&nbsp;\u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u043d\u0438\u0436\u0435:<\/p>\n<figure class=\"full-width\"><\/figure>\n<h2>\u041a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p><a class=\"anchor\" name=\"%D0%BA%D0%BB%D0%B0%D1%81%D1%82%D0%B5%D1%80%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F\" id=\"\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f\">\u0438\u0437\u0430\u0446\u0438\u044f&#187;<\/a><\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u043d\u0430\u0447\u0430\u043b\u043e\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0443\u0437\u043d\u0430\u0435\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043d\u0430\u0448\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"python\">t.groupBy('clear_tokens').count().count()<\/code><\/pre>\n<p>\u0412\u0441\u0435\u0433\u043e \u0443&nbsp;\u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c 6294&nbsp;\u0442\u0430\u043a\u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439. \u042d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u043b\u0438\u043a\u043e \u0434\u043b\u044f&nbsp;\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u043e\u0432\u0430\u0442\u044c sms \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e&nbsp;\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>\u0412&nbsp;Spark \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 6&nbsp;\u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438: KMeans, BisectingKMeans, Latent Dirichlet allocation (LDA), Power iteration clustering (PIC), Gaussian mixture \u0438 StreamingKMeans.<\/p>\n<p>StreamingKMeans \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445; PIC&nbsp;\u2014 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u0440\u0430\u0444\u043e\u0432; LDA \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432&nbsp;\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0432&nbsp;\u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043c\u043e\u0433\u0443\u0442 \u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438; Gaussian mixture \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430&nbsp;\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b, \u0447\u0442\u043e&nbsp;\u043d\u0435&nbsp;\u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f&nbsp;\u043d\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b KMeans \u0438 BisectingKMeans.<\/p>\n<details class=\"spoiler\">\n<summary> \u041e KMeans<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u0441\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0432\u044b\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0446\u0435\u043d\u0442\u0440, \u0437\u0430\u0442\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0443, \u0440\u0430\u0441\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0434\u043e \u0446\u0435\u043d\u0442\u0440\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0434\u043b\u044f \u043d\u0435\u0433\u043e \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e. \u0414\u0430\u043d\u043d\u044b\u0435 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u0442\u0440\u043e\u0432 \u043d\u0435 \u0441\u0442\u0430\u043d\u0443\u0442 \u043d\u0438\u0436\u0435 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u043e\u0433\u0430.   <\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041e BisectingKMeans<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u043a\u043b\u0430\u0441\u0442\u0435\u0440, \u0437\u0430\u0442\u0435\u043c \u043e\u043d \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f KMeans. \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u044b \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u0435\u043b\u044f\u0442\u0441\u044f, \u043f\u043e\u043a\u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c.   <\/p>\n<\/div>\n<\/details>\n<p>\u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c BisectingKMeans \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u043b\u044f&nbsp;\u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u043c KMeans, \u043a&nbsp;\u0442\u043e\u043c\u0443&nbsp;\u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043f\u043e\u0434\u0435\u043b\u0438\u0442&nbsp;\u043b\u0438 \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0430&nbsp;\u043c\u0435\u043d\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432, \u0447\u0435\u043c \u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0434\u0430\u043d\u043e.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u043c\u044b \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Elbow_method_(clustering)\" rel=\"noopener noreferrer nofollow\">\u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043b\u043e\u043a\u0442\u044f<\/a>, \u0438 \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u0438, \u0447\u0442\u043e&nbsp;\u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e 36.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0432\u0435\u043a\u0442\u043e\u0440\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u0442\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a&nbsp;\u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0438\u0437&nbsp;\u043d\u0438\u0445, \u0434\u043b\u044f&nbsp;\u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432&nbsp;\u0441\u0435\u0431\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043b\u043e\u043d\u043e\u043a \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432\u0435\u043a\u043e\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u0438 \u0434\u0432\u0430 \u0446\u0438\u043a\u043b\u0430, \u0433\u0434\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u043a&nbsp;\u044d\u0442\u0438\u043c \u043a\u043e\u043b\u043e\u043d\u043a\u0430\u043c. \u041a\u043e\u0434 \u0434\u043b\u044f&nbsp;\u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043d\u0438\u0436\u0435:<\/p>\n<pre><code class=\"python\">cols = ['TfIdfFeatures', 'Word2VecFeatures', 'CountVectFeatures']  for col in cols:     kmeans = KMeans().setK(36)\\                .setFeaturesCol(col)\\                      .setPredictionCol(f'kmeans_clusters_{col}')     km_model = kmeans.fit(t)     t = km_model.transform(t)  for col in cols:     bkm = BisectingKMeans().setK(36)\\                            .setFeaturesCol(col)\\           <\/code><\/pre>\n<\/p>\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-348178","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348178","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=348178"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348178\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}