I've been using caret to build a decision tree model using the "rpart2" method and 10-fold cross-validation repeated 5 times in R.
set.seed(888)
DT_up_rpart <-train(DiagDM1~., data = training, method = "rpart2", trControl = ctrl2,metric = "ROC", tuneGrid = maxdepthGrid)
From this call I get this results:
## CART
## 56662 samples
## 11 predictor
## 2 classes:'No','Si'
## No pre-processing
## Resampling: Cross-Validated (10 fold, repeated 5 times)
## Summary of sample sizes: 50995, 50995, 50996, 50996, 50996, 50996, ...
## Resampling results across tuning parameters:
##
## maxdepth ROC Sens Spec Accuracy Kappa
## 3 0.7378576 0.7408495 0.6449825 0.6929158 0.3858318
## 4 0.7382515 0.7367128 0.6502273 0.6934699 0.3869400
## 5 0.7382515 0.7367128 0.6502273 0.6934699 0.3869400
## 6 0.7382515 0.7367128 0.6502273 0.6934699 0.3869400
##
## ROC was used to select the optimal model using the largest value.
## The final value used for the model was maxdepth = 4
As you can see the final value used for the model was maxdepth = 4. So, now using the same training dataset, the same seed, the same performance measures, etc, I train a new model using maxdepth = 4 (constant value):
set.seed(888)
DT_up_rpart2 <-train(DiagDM1~., data = training, method = "rpart2", trControl = ctrl2, metric = "ROC", tuneGrid =data.frame(maxdepth = 4))
And I got these results:
## Resampling: Cross-Validated (10 fold, repeated 5 times)## Summary of sample sizes: 50995, 50995, 50996, 50996, 50996, 50996, ...
## Resampling results:
## ROC Sens Spec Accuracy Kappa
## 0.7379012 0.7391975 0.6464791 0.6928382 0.3856765
##
## Tuning parameter'maxdepth'was held constant at a value of 4
Note that in the first results showed above I got ROC = 0.7382512 for maxdepth = 4 while in the second model I got ROC = 0.7379012 for maxdepth = 4, and the same happens for all the performance measures. I was expecting to obtain the same results from the two models. That's why I set the seed value in both cases.
Why am I getting different results? I'm using the same dataset, the same seed, etc... Or am I defining the seed in the wrong way?
Any help would be appreciated.