caret
caret copied to clipboard
Error using RFE and Recipes package
I'm trying to implement PCA and run RFE to select the best components. I used the recipes package for pre-processing and added that model recipe to the rfe. However, I get the following error "Error in eval(e, x, parent.frame()) : object 'Num_Resamples' not found". See the code below:
df <- twoClassSim(100)
# Create recipe for pre-processing
model_recipe <- recipe(Class ~ ., data = df ) %>%
step_impute_mean(all_numeric()) %>%
step_normalize(all_numeric()) %>%
step_pca(all_predictors(), threshold = .95)
# Set ROC as the metric for the Logistic Regression function
lrFuncs$summary <- twoClassSummary
set.seed(42)
ctrl <- rfeControl(functions = lrFuncs, # Logistic Regression
method = "LOOCV", # Leave One Out Cross Validation
verbose = FALSE)
# Recursive Feature Elimination
rfe_lr <- rfe(model_recipe ,
data = df,
sizes = c(2:12),
rfeControl = ctrl,
metric = "ROC",
maximize = TRUE)
I think the problem is something related to using LOOCV as if I try using some other validation methods, it does run. I think that I need to specify Num_Resamples. After looking through the documentation and searching for this error, I tried different things, but nothing worked. I have two questions:
- Is there any argument missing in my implementation with the recipes package? My understanding is that the argument number does not need to be specified when using LOOCV.
- Alternatively, would it be possible to implement this using the trainControl (preProcOptions argument)? My understanding is that trainControl only works with the train function and not with rfe function - I've seen some example codes passing trainControl to the rfe function, but my tests indicate that rfe ignores the argument trControl.