title: Rpart - accuracy of bigrams
body: <p>Good evening, everyone!</p>
  
  <p>I am facing a problem in R. I have a dataset containing Amazon reviews of the Playstation 4 and I would like to create a prediction model with the help of <em>rpart</em> and also would like to have the accuracy of this model.</p>
  
  <p>The reviews have been successfully loaded to R, a corpus has been created and some preprocessing tasks have been applied:</p>
  
  <pre><code>library(RWeka)
  library(tm)
  library(rpart)
  
  corpus &lt;- Corpus(VectorSource(tr.review.ps4$reviewText))
  corpus &lt;- tm_map(corpus, tolower)
  corpus &lt;- tm_map(corpus, removePunctuation)
  corpus &lt;- tm_map(corpus, PlainTextDocument)
  corpus &lt;- tm_map(corpus, removeWords, stopwords('english'))
  corpus &lt;- tm_map(corpus, stemDocument)
  </code></pre>
  
  <p>The bigrams and a term document matrix are created with the following code:</p>
  
  <pre><code>BigramTokenizer &lt;- function(x) {RWeka::NGramTokenizer(x, RWeka::Weka_control(min = 2, max = 2))}
  txtTdmBi &lt;- TermDocumentMatrix(corpus, control = list(tokenize = BigramTokenizer, bounds = list(global=c(10, Inf))))
  </code></pre>
  
  <p>Then sparse-terms are deleted and a matrix is created:</p>
  
  <pre><code>dtm &lt;- removeSparseTerms(txtTdmBi, 0.999)
  dtmsparse &lt;- as.data.frame(as.matrix(txtTdmBi))
  </code></pre>
  
  <p>The original dataset consists of 7561 objects. Therefore a training and test set is created as follows:</p>
  
  <pre><code>train &lt;- dtmsparse[1:6500,]
  test &lt;- dtmsparse[6501:7561,]
  </code></pre>
  
  <p>Then the training is done. $overall refers to the star rating from one to five.</p>
  
  <pre><code>train$overall &lt;- tr.review.ps4[1:6500,]$overall
  </code></pre>
  
  <p>When using unigrams the prediction model is created as follows:</p>
  
  <pre><code>model &lt;- rpart(overall ~., data = train, method= 'class')
  </code></pre>
  
  <p>However, this is not working in my case because - I guess - the connection to the original review dataset has to be established. But how? I don't have an idea.</p>
  
  <p>When I am entering this code I get following error-output:</p>
  
  <blockquote>
    <p>Error in terms.formula(formula, data = data) :</p>
  </blockquote>
  
  <p>Can anyone help me? Thanks a lot.</p>
  
  <p>Best regards
  Paul</p>