{"id":320559,"date":"2021-03-30T21:00:25","date_gmt":"2021-03-30T21:00:25","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=320559"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=320559","title":{"rendered":"Telegram bot + ML: \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0432\u043c\u0435\u0449\u0435\u043d\u0438\u044f"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fcd\/c84\/cb6\/fcdc84cb638871a0c88831ec9013a1f8.png\" width=\"987\" height=\"429\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0438\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u043a\u0435\u0439\u0441\u043e\u0432 \u043d\u0430 <a href=\"https:\/\/www.kaggle.com\/\" rel=\"noopener noreferrer nofollow\"><strong>Kaggle<\/strong><\/a>, \u0438\u0437\u0443\u0447\u0430\u044e \u0447\u0443\u0436\u0438\u0435 \u0438 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u044f\u044e\u0441\u044c. \u0412\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0438\u0445 \u0432 \u0432\u0435\u0431-\u043f\u0440\u043e\u0435\u043a\u0442, \u0434\u043b\u044f \u043c\u0435\u043d\u044f, <em>\u0448\u043a\u043e\u043b\u044c\u043d\u0438\u043a\u0430 Junior Frontend&#8217;\u0430<\/em>, \u0434\u0430\u044e\u0442 overhead \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u044b, \u044f \u0436\u0435 \u0445\u043e\u0447\u0443 \u043f\u0440\u043e\u0441\u0442\u043e &#171;\u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c&#187; \u043b\u044e\u0431\u0443\u044e \u043a\u0440\u0443\u0442\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0432 \u0441\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441. \u0420\u0443\u043a\u0438 \u0437\u0430\u0447\u0435\u0441\u0430\u043b\u0438\u0441\u044c \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0442\u0430\u043a \u0447\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<h4>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c. 1 \u0448\u0430\u0433<\/h4>\n<p>\u042f \u0445\u043e\u0447\u0443 \u0432\u0437\u044f\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 <a href=\"https:\/\/www.kaggle.com\/\" rel=\"noopener noreferrer nofollow\"><strong>Kaggle<\/strong><\/a>, \u0447\u0442\u043e\u0431\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434 \u043b\u044e\u0431\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f\u0441\u044c \u0432 \u043d\u0435\u043c. \u0411\u043e\u0442 \u0434\u043b\u044f \u0442\u0435\u043b\u0435\u0433\u0438 \u043f\u0438\u0448\u0435\u043c \u043d\u0430 <a href=\"https:\/\/docs.python.org\/3\/\" rel=\"noopener noreferrer nofollow\"><strong>Python 3.9<\/strong><\/a>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043b\u0438\u0431\u044b <a href=\"https:\/\/pypi.org\/project\/pyTelegramBotAPI\/0.3.0\/\" rel=\"noopener noreferrer nofollow\"><strong>pyTelegramBotAPI<\/strong><\/a>, \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 .py \u0438 .ipynb \u044e\u0437\u0430\u0435\u043c<strong> <\/strong><a href=\"https:\/\/pypi.org\/project\/ipynb\/\" rel=\"noopener noreferrer nofollow\"><strong>ipynb<\/strong><\/a>. <\/p>\n<p>\u0418 \u0442\u0430\u043a, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">pip install pyTelegramBotAPI pip install ipynb<\/code><\/pre>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430 <a href=\"https:\/\/www.kaggle.com\/\" rel=\"noopener noreferrer nofollow\"><strong>Kaggle<\/strong><\/a> \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0432\u0448\u0443\u044e\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c. \u042f \u043d\u0430\u0447\u043d\u0443 \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 <a href=\"https:\/\/www.kaggle.com\/c\/titanic\/\" rel=\"noopener noreferrer nofollow\"><strong>Titanic &#8212; Machine Learning from Disaster<\/strong><\/a>, \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u0443\u044e<strong> <\/strong><a href=\"https:\/\/www.kaggle.com\/zlatankr\/titanic-random-forest-82-78\" rel=\"noopener noreferrer nofollow\"><strong>\u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/strong><\/a> (Titanic Random Forest: 82.78%), \u043f\u0435\u0440\u0435\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u044e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u0431\u043e\u0442\u043e\u043c.<\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">pip install &lt;\u0438\u043c\u044f&gt;<\/code><\/pre>\n<h4>\u041f\u0438\u043b\u0438\u043c \u0431\u043e\u0442\u0430. 2 \u0448\u0430\u0433<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043d\u0430\u0448\u0438 \u043b\u0438\u0431\u044b:<\/p>\n<pre><code class=\"python\">import telebot from ipynb.fs.defs.ml import is_user_alive<\/code><\/pre>\n<p>\u0412 <code>ipynb.fs.defs.ml<\/code> \u0432\u043c\u0435\u0441\u0442\u043e ml \u0432\u043f\u0438\u0448\u0438\u0442\u0435 \u0438\u043c\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u0432\u043c\u0435\u0441\u0442\u043e <code>is_user_alive<\/code><strong> <\/strong>\u0438\u043c\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0432\u044b\u0436\u0438\u0432\u0435\u0442 \u043b\u0438 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440.<\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0431\u043e\u0442\u0430, \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043a\u0435\u043d (\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/t.me\/botfather\" rel=\"noopener noreferrer nofollow\"><strong>@BotFather<\/strong><\/a>):<\/p>\n<pre><code class=\"python\">bot = telebot.TeleBot('token')<\/code><\/pre>\n<p>\u041f\u0438\u0448\u0435\u043c \u0445\u044d\u043d\u0434\u043b\u0435\u0440 \u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>\/start<\/code>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u043c \u043a\u0430\u043a \u044e\u0437\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430 \u0434\u044b\u043d\u043d\u044b\u0445. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0438\u0437\u0443\u0447\u0438\u0442\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0438 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0441 \u0432\u0432\u043e\u0434\u043e\u043c \u0441\u0432\u043e\u0438\u0445 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<pre><code class=\"python\">@bot.messagehandler(commands=['start']) def welcome(message):       bot.sendmessage(message.chat.id, '\u041f\u0440\u0438\u0432\u0435\u0442! \u041d\u0430\u0437\u043e\u0432\u0438 \u041a\u043b\u0430\u0441\u0441 \u0431\u0438\u043b\u0435\u0442\u0430, \u0418\u043c\u044f (\u043e\u0434\u043d\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c), '                   '\u041f\u043e\u043b (male\/female), \u0412\u043e\u0437\u0440\u0430\u0441\u0442, \u041f\u0440\u0438\u0431\u044b\u043b \u043b\u0438 \u043e\u043d \u0441 \u0441\u0443\u043f\u0440\u0443\u0433\u043e\u043c (1-\u0434\u0430, 0-\u043d\u0435\u0442), '                   '\u0441 \u0420\u0435\u0431\u0435\u043d\u043a\u043e\u043c (1-\u0434\u0430, 0-\u043d\u0435\u0442), \u041d\u043e\u043c\u0435\u0440 \u0431\u0438\u043b\u0435\u0442\u0430, \u0435\u0433\u043e \u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0438 \u041f\u043e\u0440\u0442 '                   '\u043f\u0430\u0441\u0430\u0434\u043a\u0438, - \u0430 \u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0436\u0443, \u0432\u044b\u0436\u0438\u043b \u043b\u0438 \u044d\u0442\u043e\u0442 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440 \u043d\u0430 \u0422\u0438\u0442\u0430\u043d\u0438\u043a\u0435!')<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a\u043e\u0439 \u0431\u044b \u0442\u0435\u043a\u0441\u0442 \u044e\u0437\u0435\u0440 \u043d\u0435 \u0432\u0432\u0435\u043b, \u043c\u044b \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430. \u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u0445 \u0432 \u043b\u0438\u0441\u0442 \u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430:<\/p>\n<pre><code class=\"python\">@bot.messagehandler(contenttypes=['text']) def answer(message):       bot.sendmessage(message.chat.id, '\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u2026')       passengerdata = message.text.split()       passengerdata.insert(0, 0)       passengerdata.insert(9, ',')       passengerdata[2] = '\"', passengerdata[2], '\"'<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a, \u043d\u0430 9\u0435 \u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0437\u043d\u0430\u0447\u0430\u0449\u0443\u044e \u0437\u0430\u043f\u044f\u0442\u0443\u044e, \u0430 \u0438\u043c\u044f \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438.<\/p>\n<h4>\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c. 3 \u0448\u0430\u0433<\/h4>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u043c <code>cntrl+f<\/code> \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0438 <code>#%%<\/code> \u043a\u0440\u043e\u043c\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e. \u041f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u0432\u0441\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u0442\u0430\u0431\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 \u043d\u0438\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0432\u0438\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">&lt;\u0438\u043c\u043f\u043e\u0440\u0442\u044b&gt;  def is_user_alive(user_data):   &lt;\u0432\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434&gt;<\/code><\/pre>\n<p>\u041a\u0443\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430\u0447\u0430\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0434, \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"python\">with open(os.path.join('input', 'test.csv'), \"a\") as fp:       wr = csv.writer(fp, dialect='excel')       wr.writerow(user_data)<\/code><\/pre>\n<p><code>Predictions<\/code> \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 (\u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0432\u0430\u0448 \u0441\u043b\u0443\u0447\u0430\u0439). \u0422\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438\u0441\u044c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0435\u0433\u043e \u0441\u0442\u0440\u043e\u043a\u0443 (<code>return<\/code> \u043f\u0438\u0448\u0435\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0444\u0430\u0439\u043b\u0430): <\/p>\n<pre><code class=\"python\">return predictions[len(predictions)-1:]['Survived']<\/code><\/pre>\n<h4>\u0414\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u043e\u0442\u0430. 4 \u0448\u0430\u0433<\/h4>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>answer<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0430, \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c 0 \u0438\u043b\u0438 1\u2026 \u0432 \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435. \u041a\u043e\u0440\u043e\u0447\u0435, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0432\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f:<\/p>\n<pre><code class=\"python\">answer = is_user_alive(passenger_data)  if int(answer) == 1:       bot.sendmessage(message.chat.id, '\u0412\u0435\u0437\u0443\u043d\u0447\u0438\u043a! \u0412\u0438\u0434\u0438\u043c\u043e, \u044d\u0442\u043e\u0442 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440 \u0443\u0441\u043f\u0435\u043b \u043d\u0430 \u0441\u043f\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0448\u043b\u044e\u043f\u043a\u0443.')  elif int(answer) == 0:       bot.send_message(message.chat.id, '\u0423\u0432\u044b, \u043d\u043e \u0422\u0438\u0442\u0430\u043d\u0438\u043a \u0432\u0430\u0448 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u2026 \u043d\u0435 \u043f\u0435\u0440\u0435\u0436\u0438\u043b \u0431\u044b.')<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0447\u0435\u043a\u043d\u0443\u0442\u044c \u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0435 \u0438\u0437 <code>answer<\/code> \u0441 <code>message<\/code> \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c:<\/p>\n<pre><code class=\"python\">def doagain(message):       bot.sendmessage(message.chat.id, '\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0436\u0438\u0432\u0443\u0447\u0435\u0441\u0442\u044c \u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0435?')<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u043b\u0438\u043d\u0433:<\/p>\n<pre><code class=\"python\">while True:       try:             bot.polling(none_stop=True)       except ():             time.sleep(5)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f87\/dd6\/39f\/f87dd639f3996c63a932c87fb3af8fa4.png\" width=\"1127\" height=\"593\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<\/details>\n<h4>\u0412\u0441\u0435! \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u043f\u0440\u0430\u0432\u0434\u0430?<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c, \u043c\u043e\u0436\u0435\u0448\u044c \u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0432\u0435\u0440\u0441\u0438\u044e:<\/p>\n<p><iframe id=\"600fda59b4c396d242e096fb\" src=\"https:\/\/embedd.srv.habr.com\/iframe\/600fda59b4c396d242e096fb\" class=\"embed_video embed__content\" allowfullscreen=\"true\"><\/iframe><\/p>\n<p><a href=\"https:\/\/github.com\/freakssha\/ml-bot-titanic\" rel=\"noopener noreferrer nofollow\"><strong>\u041a\u043e\u0434: https:\/\/github.com\/freakssha\/ml-bot-titanic<\/strong><\/a><\/p>\n<p>\u042d\u0442\u043e \u0441\u043f\u0438\u0434\u0440\u0430\u043d \u043e\u0442 \u0447\u0435\u0448\u0443\u0449\u0438\u0445\u0441\u044f \u0440\u0443\u043a, \u043e\u043d \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0433\u0434\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c, \u043d\u043e \u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0435 \u0442\u0435\u0440\u044f\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 &#8212; \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435, \u043f\u0440\u043e\u0448\u0443!<\/p>\n<p><a href=\"https:\/\/github.com\/freakssha\" rel=\"noopener noreferrer nofollow\"><strong>GitHub<\/strong><\/a><strong>, <\/strong><a href=\"https:\/\/instagram.com\/freakssha\" rel=\"noopener noreferrer nofollow\"><strong>Inst<\/strong><\/a><strong>, <\/strong><a href=\"https:\/\/vk.com\/freakssha\" rel=\"noopener noreferrer nofollow\"><strong>VK<\/strong><\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/549858\/\"> https:\/\/habr.com\/ru\/post\/549858\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0438\u0448\u0443 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f \u043a\u0435\u0439\u0441\u043e\u0432 \u043d\u0430 <a href=\"https:\/\/www.kaggle.com\/\" rel=\"noopener noreferrer nofollow\"><strong>Kaggle<\/strong><\/a>, \u0438\u0437\u0443\u0447\u0430\u044e \u0447\u0443\u0436\u0438\u0435 \u0438 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u044f\u044e\u0441\u044c. \u0412\u0441\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0438\u0445 \u0432 \u0432\u0435\u0431-\u043f\u0440\u043e\u0435\u043a\u0442, \u0434\u043b\u044f \u043c\u0435\u043d\u044f, <em>\u0448\u043a\u043e\u043b\u044c\u043d\u0438\u043a\u0430 Junior Frontend&#8217;\u0430<\/em>, \u0434\u0430\u044e\u0442 overhead \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0438\u043d\u0444\u044b, \u044f \u0436\u0435 \u0445\u043e\u0447\u0443 \u043f\u0440\u043e\u0441\u0442\u043e &#171;\u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c&#187; \u043b\u044e\u0431\u0443\u044e \u043a\u0440\u0443\u0442\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0432 \u0441\u0432\u043e\u0439 \u0441\u0435\u0440\u0432\u0438\u0441. \u0420\u0443\u043a\u0438 \u0437\u0430\u0447\u0435\u0441\u0430\u043b\u0438\u0441\u044c \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0442\u0430\u043a \u0447\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0431\u044b\u043b\u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e.<\/p>\n<h4>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c. 1 \u0448\u0430\u0433<\/h4>\n<p>\u042f \u0445\u043e\u0447\u0443 \u0432\u0437\u044f\u0442\u044c \u0444\u043e\u0440\u043c\u0430\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 <a href=\"https:\/\/www.kaggle.com\/\" rel=\"noopener noreferrer nofollow\"><strong>Kaggle<\/strong><\/a>, \u0447\u0442\u043e\u0431\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0431\u044b\u043b\u043e \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0447\u0443\u0436\u043e\u0439 \u043a\u043e\u0434 \u043b\u044e\u0431\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f\u0441\u044c \u0432 \u043d\u0435\u043c. \u0411\u043e\u0442 \u0434\u043b\u044f \u0442\u0435\u043b\u0435\u0433\u0438 \u043f\u0438\u0448\u0435\u043c \u043d\u0430 <a href=\"https:\/\/docs.python.org\/3\/\" rel=\"noopener noreferrer nofollow\"><strong>Python 3.9<\/strong><\/a>, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043b\u0438\u0431\u044b <a href=\"https:\/\/pypi.org\/project\/pyTelegramBotAPI\/0.3.0\/\" rel=\"noopener noreferrer nofollow\"><strong>pyTelegramBotAPI<\/strong><\/a>, \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 .py \u0438 .ipynb \u044e\u0437\u0430\u0435\u043c<strong> <\/strong><a href=\"https:\/\/pypi.org\/project\/ipynb\/\" rel=\"noopener noreferrer nofollow\"><strong>ipynb<\/strong><\/a>. <\/p>\n<p>\u0418 \u0442\u0430\u043a, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">pip install pyTelegramBotAPI pip install ipynb<\/code><\/pre>\n<p>\u0417\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430 <a href=\"https:\/\/www.kaggle.com\/\" rel=\"noopener noreferrer nofollow\"><strong>Kaggle<\/strong><\/a> \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u0432\u0448\u0443\u044e\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c. \u042f \u043d\u0430\u0447\u043d\u0443 \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043a\u0435\u0439\u0441\u0430 <a href=\"https:\/\/www.kaggle.com\/c\/titanic\/\" rel=\"noopener noreferrer nofollow\"><strong>Titanic &#8212; Machine Learning from Disaster<\/strong><\/a>, \u0437\u0430\u0438\u043c\u0441\u0442\u0432\u0443\u044e<strong> <\/strong><a href=\"https:\/\/www.kaggle.com\/zlatankr\/titanic-random-forest-82-78\" rel=\"noopener noreferrer nofollow\"><strong>\u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/strong><\/a> (Titanic Random Forest: 82.78%), \u043f\u0435\u0440\u0435\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u044e \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u0431\u043e\u0442\u043e\u043c.<\/p>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">pip install &lt;\u0438\u043c\u044f&gt;<\/code><\/pre>\n<h4>\u041f\u0438\u043b\u0438\u043c \u0431\u043e\u0442\u0430. 2 \u0448\u0430\u0433<\/h4>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0432 \u043d\u0435\u0433\u043e \u043d\u0430\u0448\u0438 \u043b\u0438\u0431\u044b:<\/p>\n<pre><code class=\"python\">import telebot from ipynb.fs.defs.ml import is_user_alive<\/code><\/pre>\n<p>\u0412 <code>ipynb.fs.defs.ml<\/code> \u0432\u043c\u0435\u0441\u0442\u043e ml \u0432\u043f\u0438\u0448\u0438\u0442\u0435 \u0438\u043c\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0430 \u0432\u043c\u0435\u0441\u0442\u043e <code>is_user_alive<\/code><strong> <\/strong>\u0438\u043c\u044f \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u0442 \u044d\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0432\u044b\u0436\u0438\u0432\u0435\u0442 \u043b\u0438 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440.<\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0431\u043e\u0442\u0430, \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u043e\u043a\u0435\u043d (\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0435\u0433\u043e \u0447\u0435\u0440\u0435\u0437 <a href=\"https:\/\/t.me\/botfather\" rel=\"noopener noreferrer nofollow\"><strong>@BotFather<\/strong><\/a>):<\/p>\n<pre><code class=\"python\">bot = telebot.TeleBot('token')<\/code><\/pre>\n<p>\u041f\u0438\u0448\u0435\u043c \u0445\u044d\u043d\u0434\u043b\u0435\u0440 \u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>\/start<\/code>, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u043d\u0435\u043c \u043a\u0430\u043a \u044e\u0437\u0430\u0442\u044c \u0431\u043e\u0442\u0430 \u0438 \u0444\u043e\u0440\u043c\u0430\u0442 \u0432\u0432\u043e\u0434\u0430 \u0434\u044b\u043d\u043d\u044b\u0445. \u0427\u0442\u043e\u0431\u044b \u0435\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0438\u0437\u0443\u0447\u0438\u0442\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0438 \u043f\u043e\u044d\u043a\u0441\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0441 \u0432\u0432\u043e\u0434\u043e\u043c \u0441\u0432\u043e\u0438\u0445 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<pre><code class=\"python\">@bot.messagehandler(commands=['start']) def welcome(message):       bot.sendmessage(message.chat.id, '\u041f\u0440\u0438\u0432\u0435\u0442! \u041d\u0430\u0437\u043e\u0432\u0438 \u041a\u043b\u0430\u0441\u0441 \u0431\u0438\u043b\u0435\u0442\u0430, \u0418\u043c\u044f (\u043e\u0434\u043d\u0438\u043c \u0441\u043b\u043e\u0432\u043e\u043c), '                   '\u041f\u043e\u043b (male\/female), \u0412\u043e\u0437\u0440\u0430\u0441\u0442, \u041f\u0440\u0438\u0431\u044b\u043b \u043b\u0438 \u043e\u043d \u0441 \u0441\u0443\u043f\u0440\u0443\u0433\u043e\u043c (1-\u0434\u0430, 0-\u043d\u0435\u0442), '                   '\u0441 \u0420\u0435\u0431\u0435\u043d\u043a\u043e\u043c (1-\u0434\u0430, 0-\u043d\u0435\u0442), \u041d\u043e\u043c\u0435\u0440 \u0431\u0438\u043b\u0435\u0442\u0430, \u0435\u0433\u043e \u0421\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0438 \u041f\u043e\u0440\u0442 '                   '\u043f\u0430\u0441\u0430\u0434\u043a\u0438, - \u0430 \u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0436\u0443, \u0432\u044b\u0436\u0438\u043b \u043b\u0438 \u044d\u0442\u043e\u0442 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440 \u043d\u0430 \u0422\u0438\u0442\u0430\u043d\u0438\u043a\u0435!')<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u0430\u043a\u043e\u0439 \u0431\u044b \u0442\u0435\u043a\u0441\u0442 \u044e\u0437\u0435\u0440 \u043d\u0435 \u0432\u0432\u0435\u043b, \u043c\u044b \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0435\u0433\u043e \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430. \u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0438\u0445 \u0432 \u043b\u0438\u0441\u0442 \u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430:<\/p>\n<pre><code class=\"python\">@bot.messagehandler(contenttypes=['text']) def answer(message):       bot.sendmessage(message.chat.id, '\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c\u2026')       passengerdata = message.text.split()       passengerdata.insert(0, 0)       passengerdata.insert(9, ',')       passengerdata[2] = '\"', passengerdata[2], '\"'<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0431\u044b\u043b\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u0430\u0439\u0434\u0438\u0448\u043d\u0438\u043a, \u043d\u0430 9\u0435 \u043c\u0435\u0441\u0442\u043e \u043d\u0435\u0437\u043d\u0430\u0447\u0430\u0449\u0443\u044e \u0437\u0430\u043f\u044f\u0442\u0443\u044e, \u0430 \u0438\u043c\u044f \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438.<\/p>\n<h4>\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c. 3 \u0448\u0430\u0433<\/h4>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u0438\u0441\u043a\u043e\u043c <code>cntrl+f<\/code> \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u0438 \u043d\u0430 \u044f\u0447\u0435\u0439\u043a\u0438 <code>#%%<\/code> \u043a\u0440\u043e\u043c\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e. \u041f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c \u0432\u0441\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u044b \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438 \u0442\u0430\u0431\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u043e\u0434\u0430 \u043f\u043e\u0441\u043b\u0435 \u043d\u0438\u0445. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0432\u0438\u0434\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">&lt;\u0438\u043c\u043f\u043e\u0440\u0442\u044b&gt;  def is_user_alive(user_data):   &lt;\u0432\u0435\u0441\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434&gt;<\/code><\/pre>\n<p>\u041a\u0443\u0434\u0430-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 \u0441\u0430\u043c\u043e\u0435 \u043d\u0430\u0447\u0430\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u043e\u0434, \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u043d\u0430\u0448\u0438 \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"python\">with open(os.path.join('input', 'test.csv'), \"a\") as fp:       wr = csv.writer(fp, dialect='excel')       wr.writerow(user_data)<\/code><\/pre>\n<p><code>Predictions<\/code> \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0434\u0435\u043b\u0438 (\u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0432\u0430\u0448 \u0441\u043b\u0443\u0447\u0430\u0439). \u0422\u0430\u043a \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043b\u0438\u0441\u044c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0435\u0433\u043e \u0441\u0442\u0440\u043e\u043a\u0443 (<code>return<\/code> \u043f\u0438\u0448\u0435\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 \u0444\u0430\u0439\u043b\u0430): <\/p>\n<pre><code class=\"python\">return predictions[len(predictions)-1:]['Survived']<\/code><\/pre>\n<h4>\u0414\u043e\u043f\u0438\u043b\u0438\u0432\u0430\u0435\u043c \u0431\u043e\u0442\u0430. 4 \u0448\u0430\u0433<\/h4>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>answer<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0430\u043d\u0430\u043b\u0438\u0437\u0430, \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c 0 \u0438\u043b\u0438 1\u2026 \u0432 \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435. \u041a\u043e\u0440\u043e\u0447\u0435, \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0442\u0432\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u0435\u0441\u0442\u0438 \u0432 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u0442\u0438\u043f:<\/p>\n<pre><code class=\"python\">answer = is_user_alive(passenger_data)  if int(answer) == 1:       bot.sendmessage(message.chat.id, '\u0412\u0435\u0437\u0443\u043d\u0447\u0438\u043a! \u0412\u0438\u0434\u0438\u043c\u043e, \u044d\u0442\u043e\u0442 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440 \u0443\u0441\u043f\u0435\u043b \u043d\u0430 \u0441\u043f\u0430\u0441\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0448\u043b\u044e\u043f\u043a\u0443.')  elif int(answer) == 0:       bot.send_message(message.chat.id, '\u0423\u0432\u044b, \u043d\u043e \u0422\u0438\u0442\u0430\u043d\u0438\u043a \u0432\u0430\u0448 \u043f\u0430\u0441\u0441\u0430\u0436\u0438\u0440\u2026 \u043d\u0435 \u043f\u0435\u0440\u0435\u0436\u0438\u043b \u0431\u044b.')<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0447\u0435\u043a\u043d\u0443\u0442\u044c \u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0435\u0435 \u0438\u0437 <code>answer<\/code> \u0441 <code>message<\/code> \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c:<\/p>\n<pre><code class=\"python\">def doagain(message):       bot.sendmessage(message.chat.id, '\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0436\u0438\u0432\u0443\u0447\u0435\u0441\u0442\u044c \u043a\u043e\u0433\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0449\u0435?')<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u043e\u043b\u0438\u043d\u0433:<\/p>\n<pre><code class=\"python\">while True:       try:             bot.polling(none_stop=True)       except ():             time.sleep(5)<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/div>\n<\/details>\n<h4>\u0412\u0441\u0435! \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e, \u043f\u0440\u0430\u0432\u0434\u0430?<\/h4>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c, \u043c\u043e\u0436\u0435\u0448\u044c \u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0432\u0435\u0440\u0441\u0438\u044e:<\/p>\n<p><iframe id=\"600fda59b4c396d242e096fb\" src=\"https:\/\/embedd.srv.habr.com\/iframe\/600fda59b4c396d242e096fb\" class=\"embed_video embed__content\" allowfullscreen=\"true\"><\/iframe><\/p>\n<p><a href=\"https:\/\/github.com\/freakssha\/ml-bot-titanic\" rel=\"noopener noreferrer nofollow\"><strong>\u041a\u043e\u0434: https:\/\/github.com\/freakssha\/ml-bot-titanic<\/strong><\/a><\/p>\n<p>\u042d\u0442\u043e \u0441\u043f\u0438\u0434\u0440\u0430\u043d \u043e\u0442 \u0447\u0435\u0448\u0443\u0449\u0438\u0445\u0441\u044f \u0440\u0443\u043a, \u043e\u043d \u043d\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0433\u0434\u0435 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c, \u043d\u043e \u044f \u043f\u043e\u043a\u0430 \u043d\u0435 \u0437\u043d\u0430\u044e \u043a\u0430\u043a. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0435 \u0442\u0435\u0440\u044f\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0438 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 &#8212; \u043d\u0430\u043f\u0438\u0448\u0438\u0442\u0435, \u043f\u0440\u043e\u0448\u0443!<\/p>\n<p><a href=\"https:\/\/github.com\/freakssha\" rel=\"noopener noreferrer nofollow\"><strong>GitHub<\/strong><\/a><strong>, <\/strong><a href=\"https:\/\/instagram.com\/freakssha\" rel=\"noopener noreferrer nofollow\"><strong>Inst<\/strong><\/a><strong>, <\/strong><a href=\"https:\/\/vk.com\/freakssha\" rel=\"noopener noreferrer nofollow\"><strong>VK<\/strong><\/a><\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/549858\/\"> https:\/\/habr.com\/ru\/post\/549858\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-320559","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/320559","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=320559"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/320559\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}