data(BloodBrain)
x <- scale(bbbDescr[,-nearZeroVar(bbbDescr)])
x <- x[, -findCorrelation(cor(x), .8)]
x <- as.data.frame(x)
set.seed(1)
lmProfile <- rfe(x, logBBB,
sizes = c(2:25, 30, 35, 40, 45, 50, 55, 60, 65),
rfeControl = rfeControl(functions = lmFuncs,
number = 200))
set.seed(1)
lmProfile2 <- rfe(x, logBBB,
sizes = c(2:25, 30, 35, 40, 45, 50, 55, 60, 65),
rfeControl = rfeControl(functions = lmFuncs,
rerank = TRUE,
number = 200))
xyplot(lmProfile$results$RMSE + lmProfile2$results$RMSE +
rfProfile$results$RMSE + rfProfile2$results$RMSE ~
lmProfile$results$Variables,
type = c("g", "p", "l"),
auto.key = TRUE)
rfProfile <- rfe(x, logBBB,
sizes = c(2, 5, 10, 20),
rfeControl = rfeControl(functions = rfFuncs))
bagProfile <- rfe(x, logBBB,
sizes = c(2, 5, 10, 20),
rfeControl = rfeControl(functions = treebagFuncs))
set.seed(1)
svmProfile <- rfe(x, logBBB,
sizes = c(5, 20, 65),
rfeControl = rfeControl(functions = caretFuncs,
number = 200),
## pass options to train()
method = "svmRadial",
fit = FALSE)
## classification with no resampling
data(mdrr)
mdrrDescr <- scale(mdrrDescr[,-nearZeroVar(mdrrDescr)])
mdrrDescr <- mdrrDescr[, -findCorrelation(cor(mdrrDescr), .8)]
set.seed(1)
inTrain <- createDataPartition(mdrrClass, p = .75, list = FALSE)[,1]
train <- mdrrDescr[ inTrain, ]
test <- mdrrDescr[-inTrain, ]
trainClass <- mdrrClass[ inTrain]
testClass <- mdrrClass[-inTrain]
preProc <- preProcess(train)
train <- predict(preProc, train)
test <- predict(preProc, test)
nbProfile <- rfeIter(train, trainClass,
test, testClass,
sizes = c(1:10, 15, 30),
rfeControl = rfeControl(functions = nbFuncs))
splitUp <- split(nbProfile$pred,
factor(nbProfile$pred$subset))
testResults <- lapply(splitUp,
function(u) postResample(u$pred, u$obs))
Variables <- as.numeric(names(testResults))
testResults <- do.call("rbind", testResults)
testResults <- cbind(testResults, Variables)
plot(testResults[,3], testResults[,1])
#######################################
## Parallel Processing Example via MPI
## A function to emulate lapply in parallel
mpiClacs <- function(X, FUN, ...)
{
theDots <- list(...)
parLapply(theDots$cl, X, FUN)
}
library(snow)
cl <- makeCluster(5, "MPI")
set.seed(1)
lmProfile <- rfe(x, logBBB,
sizes = c(2:25, 30, 35, 40, 45, 50, 55, 60, 65),
rfeControl = rfeControl(functions = lmFuncs,
number = 200,
workers = 5,
computeFunction = mpiClacs,
computeArgs = list(cl = cl)))
stopCluster(cl)
#######################################
## Parallel Processing Example via NWS
nwsClacs <- function(X, FUN, ...)
{
theDots <- list(...)
eachElem(theDots$sObj,
fun = FUN,
elementArgs = list(X))
}
library(nws)
sObj <- sleigh(workerCount = 5)
set.seed(1)
lmProfile <- rfe(x, logBBB,
sizes = c(2:25, 30, 35, 40, 45, 50, 55, 60, 65),
rfeControl = rfeControl(functions = lmFuncs,
number = 200,
workers = 5,
computeFunction = nwsClacs,
computeArgs = list(sObj = sObj)))
close(sObj)
Run the code above in your browser using DataLab