{"id":267903,"date":"2015-11-10T16:29:04","date_gmt":"2015-11-10T13:29:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=267903"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=267903","title":{"rendered":"Kaggle: \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432"},"content":{"rendered":"<p>       \u041f\u0440\u0438\u0432\u0435\u0442, \u0445\u0430\u0431\u0440!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/012\/7ad\/f21\/0127adf21d9c410ca5777c78a92a7bf8.png\"\/><\/p>\n<p>  <b>#{Data Science \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432}<\/b><\/p>\n<p>  \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0413\u043b\u0435\u0431 \u041c\u043e\u0440\u043e\u0437\u043e\u0432, \u043c\u044b \u0441 \u0412\u0430\u043c\u0438 \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u043f\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u0442\u0430\u0442\u044c\u044f\u043c. \u041f\u043e \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0441\u044c\u0431\u0430\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u044b\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0432 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 <a href=\"http:\/\/dscourse.mlclass.ru\/\">MLClass.ru<\/a> (\u043a\u0441\u0442\u0430\u0442\u0438, \u043a\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0443\u0441\u043f\u0435\u043b \u2014 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e <a href=\"http:\/\/dscourse.mlclass.ru\/\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/a>, \u043f\u043e\u043a\u0430 \u043e\u043d\u0438 \u0435\u0449\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b).<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u0414\u0430\u043d\u043d\u044b\u0435<\/h3>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u043e\u0440\u0435\u0432\u043d\u043e\u0432\u0430\u043d\u0438\u044f Bag of Words \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 Kaggle \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u0438\u0437 25000 \u043e\u0431\u0437\u043e\u0440\u043e\u0432 \u0441 \u0441\u0430\u0439\u0442\u0430 IMBD \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0442\u043d\u0435\u0441\u0451 \u0441 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432: \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0439\/\u043f\u043e\u0437\u0438\u0442\u0438\u0432\u043d\u044b\u0439. \u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043e\u0431\u0437\u043e\u0440 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0438.<\/p>\n<pre><code>library(magrittr) library(tm) require(plyr) require(dplyr) library(ggplot2) library(randomForest) <\/code><\/pre>\n<p>  \u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<pre><code>data_train &lt;- read.delim(&quot;labeledTrainData.tsv&quot;,header = TRUE, sep = &quot;\\t&quot;,                                quote = &quot;&quot;, stringsAsFactors = F) <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u0440\u0451\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432: id, sentiment \u0438 review. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043d\u0430\u0448\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u044b. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0436\u0435 \u0438\u0437 \u0441\u0435\u0431\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0430\u043c \u043e\u0431\u0437\u043e\u0440. (\u0442.\u043a. \u043e\u0431\u0437\u043e\u0440 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0435 700 \u0437\u043d\u0430\u043a\u043e\u0432)<\/p>\n<pre><code>paste(substr(data_train[1,3],1,700),&quot;...&quot;) ## [1] &quot;\\&quot;With all this stuff going down at the moment with MJ i've started listening to his music, watching the odd documentary here and there, watched The Wiz and watched Moonwalker again. Maybe i just want to get a certain insight into this guy who i thought was really cool in the eighties just to maybe make up my mind whether he is guilty or innocent. Moonwalker is part biography, part feature film which i remember going to see at the cinema when it was originally released. Some of it has subtle messages about MJ's feeling towards the press and also the obvious message of drugs are bad m'kay.&lt;br \/&gt;&lt;br \/&gt;Visually impressive but of course this is all about Michael Jackson so unless you remotely lik ...&quot; <\/code><\/pre>\n<p>  \u0412\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u0432 \u0442\u0435\u043a\u0441\u0442\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u0443\u0441\u043e\u0440 \u0432 \u0432\u0438\u0434\u0435 HTML \u0442\u0435\u0433\u043e\u0432.<\/p>\n<h3>Bag of Words<\/h3>\n<p>  Bag of Words \u0438\u043b\u0438 \u043c\u0435\u0448\u043e\u043a \u0441\u043b\u043e\u0432 \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0441\u043e\u0431\u043e\u0439 \u043d\u0435\u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0441\u043b\u043e\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u0432 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u0442\u0435\u043a\u0441\u0442. \u0427\u0430\u0441\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u0442\u0435\u043a\u0441\u0442\u0443, \u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u2014 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0432 \u043d\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430. \u042f\u0447\u0435\u0439\u043a\u0438 \u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u043e\u043c \u0432\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442. \u0414\u0430\u043d\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u0434\u043e\u0431\u043d\u0430 \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439 \u044f\u0437\u044b\u043a \u0441\u043b\u043e\u0432 \u0432 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0439 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u044c\u0442\u0435\u0440\u0430 \u044f\u0437\u044b\u043a \u0446\u0438\u0444\u0440.<\/p>\n<h4>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445<\/h4>\n<p>  \u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0430\u043a\u0435\u0442\u0430 tm. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0431\u043b\u043e\u043a\u0435 \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f:<\/p>\n<ul>\n<li>\u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432\u0435\u043a\u0442\u043e\u0440 \u0438\u0437 \u0442\u0435\u043a\u0441\u0442\u043e\u0432<\/li>\n<li>\u0441\u043e\u0437\u0434\u0435\u0451\u0442\u0441\u044f \u043a\u043e\u0440\u043f\u0443\u0441 \u2014 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432<\/li>\n<li>\u0432\u0441\u0435 \u0431\u0443\u043a\u0432\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442\u0441\u044f \u043a \u0441\u0442\u0440\u043e\u0447\u043d\u044b\u043c<\/li>\n<li>\u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u043a\u0438 \u043f\u0443\u043d\u043a\u0442\u0443\u0430\u0446\u0438\u0438<\/li>\n<li>\u0443\u0434\u0430\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u00ab\u0441\u0442\u043e\u043f-\u0441\u043b\u043e\u0432\u0430\u00bb, \u0442.\u043a. \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u043b\u043e\u0432\u0430 \u0432 \u044f\u0437\u044b\u043a\u0435, \u043d\u0435 \u043d\u0435\u0441\u0443\u0449\u0438\u0435 \u0441\u0430\u043c\u0438 \u043f\u043e \u0441\u0435\u0431\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 (\u0432 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c \u044f\u0437\u044b\u043a\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 and) \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0440\u0430\u0437\u0443 \u0443\u0431\u0440\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0431\u0437\u043e\u0440\u0430\u0445, \u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0430 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u2014 movie.<\/li>\n<li>\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u0442\u0435\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0442.\u0435. \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 \u0441\u0432\u043e\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443<\/li>\n<\/ul>\n<pre><code>train_corpus &lt;- data_train$review %&gt;% VectorSource(.)%&gt;%         Corpus(.) %&gt;% tm_map(., tolower) %&gt;% tm_map(., PlainTextDocument) %&gt;%         tm_map(., removePunctuation) %&gt;%          tm_map(., removeWords, c(&quot;movie&quot;, stopwords(&quot;english&quot;))) %&gt;%         tm_map(., stemDocument) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443.<\/p>\n<pre><code>frequencies &lt;- DocumentTermMatrix(train_corpus) frequencies ## &lt;&lt;DocumentTermMatrix (documents: 25000, terms: 92244)&gt;&gt; ## Non-\/sparse entries: 2387851\/2303712149 ## Sparsity           : 100% ## Maximal term length: 64 ## Weighting          : term frequency (tf) <\/code><\/pre>\n<p>  \u041d\u0430\u0448\u0430 \u043c\u0430\u0442\u0440\u0438\u0446\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 90000 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432, \u0442.\u0435. \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0435\u0451 \u043e\u0441\u043d\u043e\u0432\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c 90000 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u0432! \u0415\u0451 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u0432 \u043d\u0435\u0439 \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0440\u0435\u0434\u043a\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u0432 \u043e\u0431\u0437\u043e\u0440\u0430\u0445 \u0441\u043b\u043e\u0432, \u0442.\u0435. \u043e\u043d\u0430 \u0440\u0430\u0437\u0440\u044f\u0436\u0435\u043d\u0430 (\u0442\u0435\u0440\u043c\u0438\u043d sparse). \u042f \u0440\u0435\u0448\u0438\u043b \u0435\u0451 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e (\u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0434\u0435\u043b\u044c \u0443\u043c\u0435\u0441\u0442\u0438\u043b\u0430\u0441\u044c \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441 \u0443\u0447\u0451\u0442\u043e\u043c 25000 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435) \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435 \u0441\u043b\u043e\u0432\u0430, \u0447\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0432 5% \u043e\u0431\u0437\u043e\u0440\u043e\u0432.<\/p>\n<pre><code>sparse &lt;- removeSparseTerms(frequencies, 0.95) sparse ## &lt;&lt;DocumentTermMatrix (documents: 25000, terms: 373)&gt;&gt; ## Non-\/sparse entries: 1046871\/8278129 ## Sparsity           : 89% ## Maximal term length: 10 ## Weighting          : term frequency (tf) <\/code><\/pre>\n<p>  \u0412 \u0438\u0442\u043e\u0433\u0435 \u0432 \u043c\u0430\u0442\u0440\u0438\u0446\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c 373 \u0442\u0435\u0440\u043c\u0438\u043d\u0430. \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0432 data frame \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0441 \u0446\u0435\u043b\u0435\u0432\u044b\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u043e\u043c.<\/p>\n<pre><code>reviewSparse = as.data.frame(as.matrix(sparse)) vocab &lt;- names(reviewSparse) reviewSparse$sentiment &lt;- data_train$sentiment %&gt;% as.factor(.) %&gt;%          revalue(., c(&quot;0&quot;=&quot;neg&quot;, &quot;1&quot; = &quot;pos&quot;)) row.names(reviewSparse) &lt;- NULL <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0443\u0447\u0438\u043c Random Forest \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e 100 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<pre><code>model_rf &lt;- randomForest(sentiment ~ ., data = reviewSparse, ntree = 100) <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0433\u043d\u043e\u0437 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>data_test &lt;- read.delim(&quot;testData.tsv&quot;, header = TRUE, sep = &quot;\\t&quot;,                                quote = &quot;&quot;, stringsAsFactors = F) test_corpus &lt;- data_test$review %&gt;% VectorSource(.)%&gt;%         Corpus(.) %&gt;% tm_map(., tolower) %&gt;% tm_map(., PlainTextDocument) %&gt;%         tm_map(., removePunctuation) %&gt;%          tm_map(., removeWords, c(&quot;movie&quot;, stopwords(&quot;english&quot;))) %&gt;%         tm_map(., stemDocument) test_frequencies &lt;-  DocumentTermMatrix(test_corpus,control=list(dictionary = vocab)) reviewSparse_test &lt;-  as.data.frame(as.matrix(test_frequencies)) row.names(reviewSparse_test) &lt;- NULL sentiment_test &lt;- predict(model_rf, newdata = reviewSparse_test) pred_test &lt;- as.data.frame(cbind(data_test$id, sentiment_test)) colnames(pred_test) &lt;- c(&quot;id&quot;, &quot;sentiment&quot;) pred_test$sentiment %&lt;&gt;% revalue(., c(&quot;1&quot;=&quot;0&quot;, &quot;2&quot; = &quot;1&quot;)) write.csv(pred_test, file=&quot;Submission.csv&quot;, quote=FALSE, row.names=FALSE) <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 Kaggle \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430 \u043e\u0446\u0435\u043d\u043a\u0443 \u043f\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 AUC \u2014 0.73184.<\/p>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0434\u043e\u0439\u0442\u0438 \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b. \u041f\u0440\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0438 \u043e\u0431\u0440\u0435\u0437\u0430\u043d\u0438\u0438 \u0435\u0451 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u043b\u043e\u0432\u0430, \u043d\u043e, \u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0431\u0437\u043e\u0440\u0430\u0445 \u0444\u0438\u043b\u044c\u043c\u043e\u0432, \u043d\u043e \u043d\u0435 \u043e\u0442\u0440\u0430\u0436\u0430\u044e\u0442 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043e\u0431\u0437\u043e\u0440\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u043a\u0430\u043a movie, film \u0438 \u0442.\u0434. \u041d\u043e, \u0442.\u043a. \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0430\u044f \u0432\u044b\u0431\u043e\u0440\u043a\u0430 \u0441 \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043d\u044b\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u0437\u043e\u0440\u043e\u0432, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u043b\u043e\u0432\u0430, \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0443 \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0438 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u0437\u043e\u0440\u043e\u0432.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u0443\u044e \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0434\u043b\u044f \u043d\u0435\u0433\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u043e\u0431\u0437\u043e\u0440\u043e\u0432.<\/p>\n<pre><code>freq_neg &lt;- data_train %&gt;% filter(sentiment == 0) %&gt;% select(review) %&gt;% VectorSource(.)%&gt;%         Corpus(.) %&gt;% tm_map(., tolower) %&gt;% tm_map(., PlainTextDocument) %&gt;%         tm_map(., removePunctuation) %&gt;%         tm_map(., removeNumbers) %&gt;%         tm_map(., removeWords, c(stopwords(&quot;english&quot;))) %&gt;%         tm_map(., stemDocument) %&gt;% DocumentTermMatrix(.) %&gt;%          removeSparseTerms(., 0.999) %&gt;% as.matrix(.) freq_df_neg &lt;- colSums(freq_neg) freq_df_neg &lt;- data.frame(word = names(freq_df_neg), freq = freq_df_neg) rownames(freq_df_neg) &lt;- NULL head(arrange(freq_df_neg, desc(freq))) ##   word  freq ## 1 movi 27800 ## 2 film 21900 ## 3  one 12959 ## 4 like 12001 ## 5 just 10539 ## 6 make  7846 <\/code><\/pre>\n<p>  \u0418 \u0434\u043b\u044f \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u0437\u043e\u0440\u043e\u0432.<\/p>\n<pre><code>freq_pos &lt;- data_train %&gt;% filter(sentiment == 1) %&gt;% select(review) %&gt;% VectorSource(.)%&gt;%         Corpus(.) %&gt;% tm_map(., tolower) %&gt;% tm_map(., PlainTextDocument) %&gt;%         tm_map(., removePunctuation) %&gt;%         tm_map(., removeNumbers) %&gt;%         tm_map(., removeWords, c(stopwords(&quot;english&quot;))) %&gt;%         tm_map(., stemDocument) %&gt;% DocumentTermMatrix(.) %&gt;%          removeSparseTerms(., 0.999) %&gt;% as.matrix(.) freq_df_pos &lt;- colSums(freq_pos) freq_df_pos &lt;- data.frame(word = names(freq_df_pos), freq = freq_df_pos) rownames(freq_df_pos) &lt;- NULL  head(arrange(freq_df_pos, desc(freq)))  ##   word  freq ## 1 film 24398 ## 2 movi 21796 ## 3  one 13706 ## 4 like 10138 ## 5 time  7889 ## 6 good  7508 <\/code><\/pre>\n<p>  \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 \u0447\u0430\u0441\u0442\u043e\u0442\u0430\u043c\u0438.<\/p>\n<pre><code>freq_all &lt;- merge(freq_df_neg, freq_df_pos, by = &quot;word&quot;, all = T) freq_all$freq.x[is.na(freq_all$freq.x)] &lt;- 0 freq_all$freq.y[is.na(freq_all$freq.y)] &lt;- 0 freq_all$diff &lt;- abs(freq_all$freq.x - freq_all$freq.y) head(arrange(freq_all, desc(diff)))  ##    word freq.x freq.y diff ## 1  movi  27800  21796 6004 ## 2   bad   7660   1931 5729 ## 3 great   2692   6459 3767 ## 4  just  10539   7109 3430 ## 5  love   2767   5988 3221 ## 6  even   7707   5056 2651 <\/code><\/pre>\n<p>  \u041e\u0442\u043b\u0438\u0447\u043d\u043e! \u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u0441\u0440\u0435\u0434\u0438 \u0441\u043b\u043e\u0432 \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0440\u0430\u0437\u043d\u0438\u0446\u0435\u0439 \u0442\u0430\u043a\u0438\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u044b \u043a\u0430\u043a <b>bad<\/b>, <b>great<\/b> \u0438 <b>love<\/b>. \u041d\u043e \u0442\u0430\u043a\u0436\u0435 \u0437\u0434\u0435\u0441\u044c \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u043b\u043e\u0432\u0430, \u043a\u0430\u043a <b>movie<\/b>. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e, \u0447\u0442\u043e \u0443 \u0447\u0430\u0441\u0442\u044b\u0445 \u0441\u043b\u043e\u0432 \u0434\u0430\u0436\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043d\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432\u044b\u0434\u0430\u0451\u0442 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u0443\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u044d\u0442\u043e \u0443\u043f\u0443\u0449\u0435\u043d\u0438\u0435, \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0440\u0430\u0437\u043d\u0438\u0446\u0443, \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0432 \u0435\u0451 \u043d\u0430 \u0441\u0443\u043c\u043c\u0443 \u0447\u0430\u0441\u0442\u043e\u0442. \u041f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0432\u0430\u043b\u0435 \u043c\u0435\u0436\u0434\u0443 <b>0<\/b> \u0438 <b>1<\/b>, \u0438 \u0447\u0435\u043c \u0432\u044b\u0448\u0435 \u0435\u0451 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u2014 \u0442\u0435\u043c \u0432\u0430\u0436\u043d\u0435\u0435 \u0434\u0430\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u043e\u0442\u0437\u044b\u0432\u0430\u043c\u0438. \u041d\u043e \u0447\u0442\u043e \u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043e \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0442\u0437\u044b\u0432\u043e\u0432 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0438\u0445 \u0447\u0430\u0441\u0442\u043e\u0442\u0430 \u043c\u0430\u043b\u0430? \u0414\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0438\u0445 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043a \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044e \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442.<\/p>\n<pre><code>freq_all$diff_norm &lt;- abs(freq_all$freq.x - freq_all$freq.y)\/         (freq_all$freq.x +freq_all$freq.y + 300) head(arrange(freq_all, desc(diff_norm)))  ##      word freq.x freq.y diff diff_norm ## 1   worst   2436    246 2190 0.7344064 ## 2    wast   1996    192 1804 0.7250804 ## 3 horribl   1189    194  995 0.5912062 ## 4  stupid   1525    293 1232 0.5816808 ## 5     bad   7660   1931 5729 0.5792134 ## 6    wors   1183    207  976 0.5775148 <\/code><\/pre>\n<p>  \u041e\u0442\u0431\u0435\u0440\u0451\u043c 500 \u0441\u043b\u043e\u0432 \u0441 \u043d\u0430\u0438\u0432\u044b\u0441\u0448\u0438\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u044b.<\/p>\n<pre><code>freq_word &lt;- arrange(freq_all, desc(diff_norm)) %&gt;% select(word) %&gt;% slice(1:500) <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u043d\u043e\u0439 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0443\u0447\u0438\u043c Random Forest \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<pre><code>vocab &lt;- as.character(freq_word$word) frequencies = DocumentTermMatrix(train_corpus,control=list(dictionary = vocab)) reviewSparse_train &lt;-  as.data.frame(as.matrix(frequencies)) row.names(reviewSparse_train) &lt;- NULL reviewSparse_train$sentiment &lt;- data_train$sentiment %&gt;% as.factor(.) %&gt;% revalue(., c(&quot;0&quot;=&quot;neg&quot;, &quot;1&quot; = &quot;pos&quot;))  model_rf &lt;- randomForest(sentiment ~ ., data = reviewSparse_train, ntree = 100) <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u043e\u0446\u0435\u043d\u043a\u0438 \u043d\u0430 \u0441\u0430\u0439\u0442\u0435 Kaggle \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430 \u043e\u0446\u0435\u043d\u043a\u0443 \u043f\u043e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 AUC \u2014 0.83120, \u0442.\u0435. \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0432 \u0441 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c\u0438 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043d\u0430 10%!<\/p>\n<h4>TF-IDF<\/h4>\n<p>  \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442-\u0442\u0435\u0440\u043c\u0438\u043d \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0430\u0441\u0442\u043e\u0442\u0443 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430 \u0432 \u043e\u0431\u0437\u043e\u0440\u0435. \u0412 \u043f\u0430\u043a\u0435\u0442\u0435 <b>tm<\/b> \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u043c\u0435\u0440\u0443, \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u0443\u044e <b>tf-idf<\/b>. <b>TF-IDF<\/b> (\u043e\u0442 \u0430\u043d\u0433\u043b. <b>TF \u2014 term frequency, IDF \u2014 inverse document frequency<\/b>) \u2014 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043c\u0435\u0442\u0440\u0438\u043a\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0430\u044f \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u043b\u043e\u0432\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430, \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u043b\u0438 \u043a\u043e\u0440\u043f\u0443\u0441\u0430. \u0412\u0435\u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u0435\u043d \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435, \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u043e\u043f\u043e\u0440\u0446\u0438\u043e\u043d\u0430\u043b\u0435\u043d \u0447\u0430\u0441\u0442\u043e\u0442\u0435 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432\u0430 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438.<\/p>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <b>tf-idf<\/b>, \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0438\u0437 <b>500<\/b> \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432 \u0441 \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u0435\u0442\u0440\u0438\u043a\u0438. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e\u0442 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u043b \u0432\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0432, \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0443\u044e \u0432\u044b\u0431\u043e\u0440\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435 \u0440\u0430\u0437\u043c\u0435\u0447\u0435\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u043e\u0431\u0437\u043e\u0440\u043e\u0432. \u041d\u0430 \u0431\u0430\u0437\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0442\u0440\u0438\u0446\u0443 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442-\u0442\u0435\u0440\u043c\u0438\u043d \u0438 \u043e\u0431\u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c.<\/p>\n<pre><code>data_train_un &lt;- read.delim(&quot;unlabeledTrainData.tsv&quot;,header = TRUE, sep = &quot;\\t&quot;,                             quote = &quot;&quot;, stringsAsFactors = F) train_review &lt;- c(data_train$review, data_train_un$review) train_corpus &lt;- train_review %&gt;% VectorSource(.)%&gt;%         Corpus(.) %&gt;% tm_map(., tolower) %&gt;% tm_map(., PlainTextDocument) %&gt;%         tm_map(., removePunctuation) %&gt;% tm_map(., removeNumbers) %&gt;%         tm_map(., removeWords, c(stopwords(&quot;english&quot;))) %&gt;%         tm_map(., stemDocument) tdm &lt;- TermDocumentMatrix(train_corpus,                           control = list(weighting = function(x) weightTfIdf(x, normalize = F))) library(slam) freq &lt;- rollup(tdm, 2,FUN = sum) freq &lt;- as.matrix(freq) freq_df &lt;- data.frame(word = row.names(freq), tfidf = freq) names(freq_df) &lt;- c(&quot;word&quot;, &quot;tf_idf&quot;) row.names(freq_df) &lt;- NULL freq_df %&lt;&gt;% arrange(desc(tf_idf)) vocab &lt;- as.character(freq_df$word)[1:500] train_corpus &lt;- data_train$review %&gt;% VectorSource(.)%&gt;%         Corpus(.) %&gt;% tm_map(., tolower) %&gt;% tm_map(., PlainTextDocument) %&gt;%         tm_map(., removePunctuation) %&gt;% tm_map(., removeNumbers) %&gt;%         tm_map(., removeWords, c(stopwords(&quot;english&quot;))) %&gt;%         tm_map(., stemDocument) frequencies = DocumentTermMatrix(train_corpus,control=list(dictionary = vocab,                                                            weighting = function(x) weightTfIdf(x, normalize = F) )) reviewSparse_train &lt;-  as.data.frame(as.matrix(frequencies)) rm(data_train_un, tdm, dtm, train_review) reviewSparse_train &lt;-  as.data.frame(as.matrix(frequencies)) row.names(reviewSparse_train) &lt;- NULL colnames(reviewSparse_train) = make.names(colnames(reviewSparse_train)) reviewSparse_train$sentiment &lt;- data_train$sentiment %&gt;% as.factor(.) %&gt;% revalue(., c(&quot;0&quot;=&quot;neg&quot;, &quot;1&quot; = &quot;pos&quot;)) rm(data_train, train_corpus, freq, freq_df) model_rf &lt;- randomForest(sentiment ~ ., data = reviewSparse_train, ntree = 100) <\/code><\/pre>\n<p>  \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0434\u0430\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0439 \u0432\u044b\u0431\u043e\u0440\u043a\u0435 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <b>AUC \u2014 0.81584<\/b>.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445. \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0434\u0435\u043b\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432 \u0438\u0437 \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442-\u0442\u0435\u0440\u043c\u0438\u043d, \u043d\u043e \u044d\u0442\u043e\u0442 \u043f\u0443\u0442\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u043a \u0447\u0430\u0441\u0442\u043e\u0442\u0430\u043c \u0441\u043b\u043e\u0432, \u0430 \u043a \u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c \u0438 \u0441\u0432\u044f\u0437\u044f\u043c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0434\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u043c\u043e\u0434\u0435\u043b\u0438 <b>word2vec<\/b>. \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0435 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430               <\/p>\n<div class=\"clear\"><\/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=\"http:\/\/habrahabr.ru\/post\/270591\/\"> http:\/\/habrahabr.ru\/post\/270591\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041f\u0440\u0438\u0432\u0435\u0442, \u0445\u0430\u0431\u0440!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/012\/7ad\/f21\/0127adf21d9c410ca5777c78a92a7bf8.png\"\/><\/p>\n<p>  <b>#{Data Science \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432}<\/b><\/p>\n<p>  \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0413\u043b\u0435\u0431 \u041c\u043e\u0440\u043e\u0437\u043e\u0432, \u043c\u044b \u0441 \u0412\u0430\u043c\u0438 \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b \u043f\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u043c \u0441\u0442\u0430\u0442\u044c\u044f\u043c. \u041f\u043e \u043c\u043d\u043e\u0433\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0441\u044c\u0431\u0430\u043c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043e\u043f\u044b\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u0438\u044f \u0432 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 <a href=\"http:\/\/dscourse.mlclass.ru\/\">MLClass.ru<\/a> (\u043a\u0441\u0442\u0430\u0442\u0438, \u043a\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0443\u0441\u043f\u0435\u043b \u2014 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e <a href=\"http:\/\/dscourse.mlclass.ru\/\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b<\/a>, \u043f\u043e\u043a\u0430 \u043e\u043d\u0438 \u0435\u0449\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b).  <\/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-267903","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267903","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=267903"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/267903\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}