Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in varImp[, "%IncMSE"] on RFE rfFuncs regression subset fit #723

Closed
floriandeboissieu opened this issue Aug 23, 2017 · 1 comment
Closed

Comments

@floriandeboissieu
Copy link
Contributor

@floriandeboissieu floriandeboissieu commented Aug 23, 2017

varImp on the final regression fit of an RFE with rfFuncs gives an error. It comes from rfFuncs$fit.
It can be fixed modifying rfFuncs$fit, see example below.

library(caret)
library(randomForest)
set.seed(123)

# Simulate data
x <- matrix(rnorm(1e3), ncol = 10)  # Feature matrix
colnames(x) <- paste0('x', seq_len(10))
y_cont <- runif(1e2)                            # Continuous response
ctrl <- rfeControl(functions = rfFuncs, method = 'cv'
fit_cont <- rfe(x, y_cont, sizes = seq_len(3), rfeControl = ctrl)

varImp(fit_cont$fit)

# adding importance computation for selected model
rfFuncs$fit <- function (x, y, first, last, ...) 
{
  loadNamespace("randomForest")
  randomForest::randomForest(x, y, importance = (first|last), ...)
}

ctrl <- rfeControl(functions = rfFuncs, method = 'cv')
fit_cont <- rfe(x, y_cont, sizes = seq_len(3), rfeControl = ctrl)
varImp(fit_cont$fit)
topepo added a commit that referenced this issue Aug 23, 2017
@topepo
Copy link
Owner

@topepo topepo commented Aug 23, 2017

Looks good. Thanks

@topepo topepo closed this Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.