title: Error in ConfusionMatrix: "data" and "reference" should be factors with the same levels
body: <p>I am trying to do a kfold cross validation with logistics regression but ran into some errors when trying to run the confusion matrix. I cannot figure out how to solve this. Any help is greatly appreciated.</p>
  <p>In addition:</p>
  <p>Warning message:</p>
  <blockquote>
  <p>In predict.lm(object, newdata, se.fit, scale = 1, type = if (type ==  :prediction from a rank-deficient fit may be misleading</p>
  </blockquote>
  <p>Here is my code:</p>
  <pre><code>for(i in 1:10){
    fold_val &lt;- tele.df[folds[[i]],] 
    fold_train &lt;- tele.df[-folds[[i]],] 
    tele.default.lr &lt;- glm(Churn ~ ., data = fold_train, family = &quot;binomial&quot;)
    tele.default.lr.pred.train &lt;- predict(tele.default.lr, fold_train, type = &quot;response&quot;)
    print(confusionMatrix(tele.default.lr.pred.train, as.factor(fold_train$Churn)))
    
    tele.default.lr.pred.valid &lt;- predict(tele.default.lr, fold_val, type = &quot;response&quot;)
    print(confusionMatrix(tele.default.lr.pred.valid, as.factor(fold_val$Churn)))
  </code></pre>