## Not run:
#
# ## A small example with standard pre-preprocessing: clean NAs and scale
# data(algae,package="DMwR")
#
# idx <- sample(1:nrow(algae),150)
# tr <- algae[idx,1:12]
# ts <- algae[-idx,1:12]
# summary(tr)
# summary(ts)
#
# preData <- standardPRE(a1 ~ ., tr, ts, steps=c("centralImp","scale"))
# summary(preData$train)
# summary(preData$test)
#
# ######
# ## Using in the context of an experiment
# library(e1071)
# res <- performanceEstimation(
# PredTask(a1 ~ .,algae[,1:12],"alga1"),
# Workflow(learner="svm",pre=c("centralImp","scale")),
# EstimationTask(metrics="mse")
# )
#
# summary(res)
#
# ######
# ## A user-defined pre-processing function
# myScale <- function(f,tr,ts,avg,std,...) {
# tgtVar <- deparse(f[[2]])
# allPreds <- setdiff(colnames(tr),tgtVar)
# numPreds <- allPreds[sapply(allPreds,
# function(p) is.numeric(tr[[p]]))]
# tr[,numPreds] <- scale(tr[,numPreds],center=avg,scale=std)
# ts[,numPreds] <- scale(ts[,numPreds],center=avg,scale=std)
# list(train=tr,test=ts)
# }
#
# ## now using it with some random averages and stds for the 8 numeric
# ## predictors (just for illustration)
# newData <- standardPRE(a1 ~ .,tr,ts,steps="myScale",
# avg=rnorm(8),std=rnorm(8))
#
# ## End(Not run)
Run the code above in your browser using DataLab