## Not run: 
# 
# ## Estimating the mean squared error  of svm on the swiss data,
# ## using two repetitions of 10-fold CV
# library(e1071)
# data(swiss)
# 
# ## Now the evaluation
# eval.res <- cvEstimates(
#              Workflow(wf="standardWF", wfID="mySVMtrial",
#                       learner="svm", learner.pars=list(cost=10,gamma=0.1)
#                      ),
#              PredTask(Infant.Mortality ~ ., swiss),
#              EstimationTask(metrics="mse",method=CV(nReps=2,nFolds=10))
#                        )
# 
# ## Check a summary of the results
# summary(eval.res)
# 
# 
# ## An example with a user-defined workflow function implementing a
# ## simple approach using linear regression models but also containing
# ## some data-preprocessing and well as results post-processing.
# myLM <- function(form,train,test,k=10,.outModel=FALSE) {
#     require(DMwR)
#     ## fill-in NAs on both the train and test sets
#     ntr <- knnImputation(train,k)
#     nts <- knnImputation(test,k,distData=train)
#     ## obtain a linear regression model and simplify it
#     md <- lm(form,ntr)
#     md <- step(md)
#     ## get the model predictions
#     p <- predict(md,nts)
#     ## post-process the predictions (this is an example assuming the target
#     ## variable is always positive so we change negative predictions into 0)
#     p <- ifelse(p < 0,0,p)
#     ## now get the final return object
#     res <- list(trues=responseValues(form,nts), preds=p)
#     if (.outModel) res <- c(res,list(model=m))
#     res
# }
# 
# ## Now for the CV estimation 
# data(algae,package="DMwR")
# eval.res2 <- cvEstimates(
#              Workflow(wf="myLM",k=5),
#              PredTask(a1 ~ ., algae[,1:12],"alga1"),
#              EstimationTask("mse",method=CV()))
# 
# ## Check a summary of the results
# summary(eval.res2)
# 
# ##
# ## Parallel execution example
# ##
# ## Comparing the time of sequential and parallel execution
# ## using half of the cores of the local machine
# ##
# data(Satellite,package="mlbench")
# library(e1071)
# system.time({p <- cvEstimates(Workflow(learner="svm"),
#                               PredTask(classes ~ .,Satellite),
#                               EstimationTask("err",Boot(nReps=10)),
#                               cluster=TRUE)})[3]
# system.time({np <- cvEstimates(Workflow(learner="svm"),
#                                PredTask(classes ~ .,Satellite),
#                                EstimationTask("err",Boot(nReps=10)))})[3]
# 
# ## End(Not run)
Run the code above in your browser using DataLab