title: compute precision, recall, F1 values for rpart package result
body: <p>The below data frame is a sample of my total data set:</p>
  
  <pre><code>A    B   C    D    E    target
  0.2 0.5 0.6 -0.5   -0.7   1
  0.9 0.7 0.4 -0.3   -0.8   0  
  0.1 0.3 0.5 -0.9   -0.2   0
  0.2 0.5 0.6 -0.5   -0.6   1
  </code></pre>
  
  <p>I want to apply classification tree on that so I used the below code:</p>
  
  <pre><code>data$target&lt;-factor(data$target)
  
  # Create Training Data
  train.ind &lt;- sample(nrow(data), 0.7*nrow(data))
  trainData&lt;-data[train.ind,]
  testData&lt;-data[-train.ind,]    
  
  library("rpart")
  tree &lt;- rpart(target ~.,data=trainData)
  
  ypred=predict(tree,testData)
  
      library(caret)
      #Print a confusion matrix
      result &lt;- confusionMatrix(ypred,testData$target)
  </code></pre>
  
  <blockquote>
    <p>Error: <code>data</code> and <code>reference</code> should be factors with the same levels.</p>
  </blockquote>
  
  <pre><code>   precision &lt;- result$byClass['Pos Pred Value']    
      recall &lt;- result$byClass['Sensitivity']
      f_measure &lt;- 2 * ((precision * recall) / (precision + recall))
      #OR
      f_measure &lt;-result$byClass['F1']
  </code></pre>
  
  <p>But it did not work. I need to the precision, recall and F1 values but I don't know how to compute using "rpart" package result.</p>