title: Different model accuracy when rerunning preProcess(), predict() and train() in R (caret)
body: <p>The data below is just an example, it is operations on this , or any, data which I am confused about:</p>
  
  <pre><code>library(caret)
  set.seed(3433)
  data(AlzheimerDisease)
  complete &lt;- data.frame(diagnosis, predictors)
  in_train &lt;- createDataPartition(complete$diagnosis, p = 0.75)[[1]]
  training &lt;- complete[in_train,]
  testing &lt;- complete[-in_train,]
  predIL &lt;- grep("^IL", names(training))
  smalltrain &lt;- training[, c(1, predIL)]
  
  fit_noPCA &lt;- train(diagnosis ~ ., method = "glm", data = smalltrain)
  pre_proc_obj &lt;- preProcess(smalltrain[,-1], method = "pca", thresh = 0.8)
  smalltrainsPCs &lt;- predict(pre_proc_obj, smalltrain[,-1])
  fit_PCA &lt;- train(x = smalltrainsPCs, y = smalltrain$diagnosis, method = "glm")
  fit_noPCA$results$Accuracy
  fit_PCA$results$Accuracy
  </code></pre>
  
  <p>When running this code, I get a 0.689539 accuracy for <code>fit_noPCA</code> and 0.682951 accuracy for <code>fit_PCA</code>. But when I rerun the last portion of the code:</p>
  
  <pre><code>fit_noPCA &lt;- train(diagnosis ~ ., method = "glm", data = smalltrain)
  pre_proc_obj &lt;- preProcess(smalltrain[,-1], method = "pca", thresh = 0.8)
  smalltrainsPCs &lt;- predict(pre_proc_obj, smalltrain[,-1])
  fit_PCA &lt;- train(x = smalltrainsPCs, y = smalltrain$diagnosis, method = "glm")
  fit_noPCA$results$Accuracy
  fit_PCA$results$Accuracy
  </code></pre>
  
  <p>Then each time I rerun these 6 lines I get different accuracy values. Why is this so? Is it because I am not resetting the seed? Even if, where is the inherent randomness of this process? </p>